mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
This commit moves all of the libraries under a common directory called libs/. This most certainly break libcxx and uClibc++ for now.
Squashed commit of the following:
libs/libxx: Fix some confusing in naming. If the directory is called libxx, then the library must be libxx.a (unless perhaps LIBCXX is selected).
libs/: Fix paths in moved library directories.
libs: Brute force move of libc, libnx, and libxx to libs. Cannot yet build it in that configuration.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
/Make_bin.dep
|
||||
/Make_ubin.dep
|
||||
/Make_kbin.dep
|
||||
/.depend
|
||||
/*.lib
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
comment "Standard C Library Options"
|
||||
|
||||
source libs/libc/stdio/Kconfig
|
||||
source libs/libc/math/Kconfig
|
||||
source libs/libc/machine/Kconfig
|
||||
source libs/libc/stdlib/Kconfig
|
||||
source libs/libc/unistd/Kconfig
|
||||
source libs/libc/string/Kconfig
|
||||
source libs/libc/dllfcn/Kconfig
|
||||
source libs/libc/modlib/Kconfig
|
||||
source libs/libc/wchar/Kconfig
|
||||
source libs/libc/locale/Kconfig
|
||||
source libs/libc/lzf/Kconfig
|
||||
source libs/libc/time/Kconfig
|
||||
source libs/libc/tls/Kconfig
|
||||
source libs/libc/net/Kconfig
|
||||
source libs/libc/netdb/Kconfig
|
||||
source libs/libc/misc/Kconfig
|
||||
source libs/libc/wqueue/Kconfig
|
||||
source libs/libc/hex2bin/Kconfig
|
||||
source libs/libc/userfs/Kconfig
|
||||
@@ -0,0 +1,189 @@
|
||||
############################################################################
|
||||
# libs/libc/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
# CFLAGS
|
||||
|
||||
ifneq ($(CONFIG_BUILD_FLAT),y)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
KDEFINE = ${shell $(TOPDIR)\tools\define.bat "$(CC)" __KERNEL__}
|
||||
else
|
||||
KDEFINE = ${shell $(TOPDIR)/tools/define.sh "$(CC)" __KERNEL__}
|
||||
endif
|
||||
endif
|
||||
|
||||
# Sources and paths
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
|
||||
DEPPATH := --dep-path .
|
||||
VPATH := .
|
||||
|
||||
include aio/Make.defs
|
||||
include audio/Make.defs
|
||||
include dirent/Make.defs
|
||||
include dllfcn/Make.defs
|
||||
include fixedmath/Make.defs
|
||||
include hex2bin/Make.defs
|
||||
include inttypes/Make.defs
|
||||
include libgen/Make.defs
|
||||
include locale/Make.defs
|
||||
include lzf/Make.defs
|
||||
include machine/Make.defs
|
||||
include math/Make.defs
|
||||
include misc/Make.defs
|
||||
include modlib/Make.defs
|
||||
include net/Make.defs
|
||||
include netdb/Make.defs
|
||||
include pthread/Make.defs
|
||||
include queue/Make.defs
|
||||
include sched/Make.defs
|
||||
include semaphore/Make.defs
|
||||
include signal/Make.defs
|
||||
include spawn/Make.defs
|
||||
include stdio/Make.defs
|
||||
include stdlib/Make.defs
|
||||
include string/Make.defs
|
||||
include symtab/Make.defs
|
||||
include syslog/Make.defs
|
||||
include termios/Make.defs
|
||||
include time/Make.defs
|
||||
include tls/Make.defs
|
||||
include uio/Make.defs
|
||||
include unistd/Make.defs
|
||||
include userfs/Make.defs
|
||||
include wchar/Make.defs
|
||||
include wctype/Make.defs
|
||||
include wqueue/Make.defs
|
||||
|
||||
# REVISIT: Backslash causes problems in $(COBJS) target
|
||||
DELIM := $(strip /)
|
||||
BINDIR ?= bin
|
||||
|
||||
AOBJS = $(patsubst %.S, $(BINDIR)$(DELIM)%$(OBJEXT), $(ASRCS))
|
||||
COBJS = $(patsubst %.c, $(BINDIR)$(DELIM)%$(OBJEXT), $(CSRCS))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
UBIN = libuc$(LIBEXT)
|
||||
KBIN = libkc$(LIBEXT)
|
||||
BIN ?= libc$(LIBEXT)
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: clean distclean
|
||||
|
||||
$(AOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
$(call MOVEOBJ,$(patsubst $(BINDIR)$(DELIM)%$(OBJEXT),%,$@),$(BINDIR))
|
||||
|
||||
$(COBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
$(call MOVEOBJ,$(patsubst $(BINDIR)$(DELIM)%$(OBJEXT),%,$@),$(BINDIR))
|
||||
|
||||
# C library for the flat build
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(call ARCHIVE, $@, $(OBJS))
|
||||
ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
|
||||
$(Q) $(MAKE) -C zoneinfo all TOPDIR=$(TOPDIR) BIN=$(BIN)
|
||||
endif
|
||||
|
||||
# C library for the user phase of the two-pass kernel build
|
||||
|
||||
ifneq ($(BIN),$(UBIN))
|
||||
$(UBIN):
|
||||
$(Q) $(MAKE) $(UBIN) BIN=$(UBIN) BINDIR=ubin TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
|
||||
endif
|
||||
|
||||
# C library for the kernel phase of the two-pass kernel build
|
||||
|
||||
ifneq ($(BIN),$(KBIN))
|
||||
$(KBIN):
|
||||
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) BINDIR=kbin TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
|
||||
endif
|
||||
|
||||
# Context
|
||||
|
||||
context:
|
||||
ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
|
||||
$(Q) $(MAKE) -C zoneinfo context TOPDIR=$(TOPDIR) BIN=$(BIN)
|
||||
endif
|
||||
|
||||
# Dependencies
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
ifeq ($(CONFIG_BUILD_FLAT),y)
|
||||
$(Q) $(MKDEP) --obj-path bin --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make_bin.dep
|
||||
else
|
||||
$(Q) $(MKDEP) --obj-path ubin --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make_ubin.dep
|
||||
$(Q) $(MKDEP) --obj-path kbin --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(CFLAGS) $(KDEFINE) -- $(SRCS) >Make_kbin.dep
|
||||
endif
|
||||
ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
|
||||
$(Q) $(MAKE) -C zoneinfo depend TOPDIR=$(TOPDIR) BIN=$(BIN)
|
||||
endif
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
# Clean most derived files, retaining the configuration
|
||||
|
||||
clean:
|
||||
$(Q) $(MAKE) -C bin clean TOPDIR=$(TOPDIR)
|
||||
$(Q) $(MAKE) -C ubin clean TOPDIR=$(TOPDIR)
|
||||
$(Q) $(MAKE) -C kbin clean TOPDIR=$(TOPDIR)
|
||||
$(Q) $(MAKE) -C zoneinfo clean TOPDIR=$(TOPDIR) BIN=$(BIN)
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, $(UBIN))
|
||||
$(call DELFILE, $(KBIN))
|
||||
$(call CLEAN)
|
||||
|
||||
# Deep clean -- removes all traces of the configuration
|
||||
|
||||
distclean: clean
|
||||
$(Q) $(MAKE) -C bin distclean TOPDIR=$(TOPDIR)
|
||||
$(Q) $(MAKE) -C ubin distclean TOPDIR=$(TOPDIR)
|
||||
$(Q) $(MAKE) -C kbin distclean TOPDIR=$(TOPDIR)
|
||||
$(Q) $(MAKE) -C zoneinfo distclean TOPDIR=$(TOPDIR) BIN=$(BIN)
|
||||
$(call DELFILE, Make_bin.dep)
|
||||
$(call DELFILE, Make_ubin.dep)
|
||||
$(call DELFILE, Make_kbin.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make_bin.dep
|
||||
-include Make_ubin.dep
|
||||
-include Make_kbin.dep
|
||||
@@ -0,0 +1,101 @@
|
||||
lib
|
||||
===
|
||||
|
||||
This directory contains numerous, small functions typically associated with
|
||||
what you would expect to find in a standard C library. The sub-directories
|
||||
in this directory contain standard interface that can be executed by user-
|
||||
mode programs.
|
||||
|
||||
Normally, NuttX is built with no protection and all threads running in kerne-
|
||||
mode. In that model, there is no real architectural distinction between
|
||||
what is a kernel-mode program and what is a user-mode program; the system is
|
||||
more like on multi-threaded program that all runs in kernel-mode.
|
||||
|
||||
But if the CONFIG_BUILD_PROTECTED option is selected, NuttX will be built
|
||||
into distinct user-mode and kernel-mode sections. In that case, most of the
|
||||
code in the nuttx/ directory will run in kernel-mode with with exceptions
|
||||
of (1) the user-mode "proxies" found in syscall/proxies, and (2) the
|
||||
standard C library functions found in this directory. In this build model,
|
||||
it is critical to separate the user-mode OS interfaces in this way.
|
||||
|
||||
If CONFIG_BUILD_KERNEL is selected, then only a NuttX kernel will be built
|
||||
with no applications.
|
||||
|
||||
Sub-Directories
|
||||
===============
|
||||
|
||||
The files in the libs/libc/ directory are organized (mostly) according which file
|
||||
in the include/ directory provides the prototype for library functions. So
|
||||
we have:
|
||||
|
||||
audio - This part of the audio system: nuttx/audio/audio.h
|
||||
dllfcn - dllfcn.h
|
||||
hex2bin - hex2bin.h
|
||||
libgen - libgen.h
|
||||
locale - locale.h
|
||||
lzf - lzf.h
|
||||
fixedmath - fixedmath.h
|
||||
inttypes - inttypes.h
|
||||
machine - Various architecture-specific implementations.
|
||||
math - math.h
|
||||
modlib - Part of module and shared library logic: nuttx/lib/modlib.h
|
||||
net - Various network-related header files: netinet/ether.h, arpa/inet.h
|
||||
pthread - pthread.h
|
||||
queue - queue.h
|
||||
sched - sched.h
|
||||
semaphore - semaphore.h
|
||||
stdio - stdio.h
|
||||
stdlib - stdlib.h
|
||||
string - string.h (and legacy strings.h)
|
||||
time - time.h
|
||||
uio - sys/uio.h
|
||||
unistd - unistd.h
|
||||
wchar - wchar.h
|
||||
wctype - wctype.h
|
||||
|
||||
Most of these are "standard" header files; some are not: hex2bin.h and
|
||||
fixemath.h are non-standard.
|
||||
|
||||
There is also a misc/ subdirectory that contains various internal functions
|
||||
and interfaces from header files that are too few to warrant their own sub-
|
||||
directory:
|
||||
|
||||
misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h
|
||||
|
||||
Library Database
|
||||
================
|
||||
|
||||
Information about functions available in the NuttX C library information is
|
||||
maintained in a database. That "database" is implemented as a simple comma-
|
||||
separated-value file, libc.csv. Most spreadsheets programs will accept this
|
||||
format and can be used to maintain the library database.
|
||||
|
||||
This library database will (eventually) be used to generate symbol library
|
||||
symbol table information that can be exported to external applications.
|
||||
|
||||
The format of the CSV file for each line is:
|
||||
|
||||
Field 1: Function name
|
||||
Field 2: The header file that contains the function prototype
|
||||
Field 3: Condition for compilation
|
||||
Field 4: The type of function return value.
|
||||
Field 5 - N+5: The type of each of the N formal parameters of the function
|
||||
|
||||
Each type field has a format as follows:
|
||||
|
||||
type name:
|
||||
For all simpler types
|
||||
formal type | actual type:
|
||||
For array types where the form of the formal (eg. int parm[2])
|
||||
differs from the type of actual passed parameter (eg. int*). This
|
||||
is necessary because you cannot do simple casts to array types.
|
||||
formal type | union member actual type | union member fieldname:
|
||||
A similar situation exists for unions. For example, the formal
|
||||
parameter type union sigval -- You cannot cast a uintptr_t to
|
||||
a union sigval, but you can cast to the type of one of the union
|
||||
member types when passing the actual parameter. Similarly, we
|
||||
cannot cast a union sigval to a uinptr_t either. Rather, we need
|
||||
to cast a specific union member fieldname to uintptr_t.
|
||||
|
||||
NOTE: The tool mksymtab can be used to generate a symbol table from this CSV
|
||||
file. See nuttx/tools/README.txt for further details about the use of mksymtab.
|
||||
@@ -0,0 +1,46 @@
|
||||
############################################################################
|
||||
# libs/libc/aio/Make.defs
|
||||
#
|
||||
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_FS_AIO),y)
|
||||
|
||||
# Add the asynchronous I/O C files to the build
|
||||
|
||||
CSRCS += aio_error.c aio_return.c aio_suspend.c lio_listio.c
|
||||
|
||||
# Add the asynchronous I/O directory to the build
|
||||
|
||||
DEPPATH += --dep-path aio
|
||||
VPATH += :aio
|
||||
endif
|
||||
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/aio/aio.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __LIBC_AIO_AIO_H
|
||||
#define __LIBC_AIO_AIO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_FS_AIO
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_FS_AIO */
|
||||
#endif /* __LIBC_AIO_AIO_H */
|
||||
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/aio/aio_error.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <aio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef CONFIG_FS_AIO
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: aio_error
|
||||
*
|
||||
* Description:
|
||||
* The aio_error() function returns the error status associated with the
|
||||
* aiocb structure referenced by the aiocbp argument. The error status fo
|
||||
* an asynchronous I/O operation is the errno value that would be set by
|
||||
* the corresponding read(), write(), fdatasync(), or fsync() operation. If
|
||||
* the operation has not yet completed, then the error status will be equal
|
||||
* to EINPROGRESS.
|
||||
*
|
||||
* Input Parameters:
|
||||
* aiocbp - A pointer to an instance of struct aiocb
|
||||
*
|
||||
* Returned Value:
|
||||
* If the asynchronous I/O operation has completed successfully, then 0
|
||||
* will be returned. If the asynchronous operation has completed
|
||||
* unsuccessfully, then the error status, as described for read(),
|
||||
* write(), fdatasync(), and fsync(), will be returned. If the
|
||||
* asynchronous I/O operation has not yet completed, then EINPROGRESS will
|
||||
* be returned.
|
||||
*
|
||||
* The aio_error() function may fail if:
|
||||
*
|
||||
* EINVAL - The aiocbp argument does not refer to an asynchronous
|
||||
* operation whose return status has not yet been retrieved.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int aio_error(FAR const struct aiocb *aiocbp)
|
||||
{
|
||||
DEBUGASSERT(aiocbp);
|
||||
|
||||
if (aiocbp->aio_result < 0)
|
||||
{
|
||||
return -aiocbp->aio_result;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FS_AIO */
|
||||
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/aio/aio_return.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <aio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef CONFIG_FS_AIO
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: aio_return
|
||||
*
|
||||
* Description:
|
||||
* The aio_return() function returns the return status associated with
|
||||
* the aiocb structure referenced by the aiocbp argument. The return
|
||||
* status for an asynchronous I/O operation is the value that would be
|
||||
* returned by the corresponding read(), write(), or fsync() function
|
||||
* call. If the error status for the operation is equal to EINPROGRESS,
|
||||
* then the return status for the operation is undefined. The aio_return()
|
||||
* function may be called exactly once to retrieve the return status of
|
||||
* a given asynchronous operation; thereafter, if the same aiocb structure
|
||||
* is used in a call to aio_return() or aio_error(), an error may be
|
||||
* returned. When the aiocb structure referred to by aiocbp is used to
|
||||
* submit another asynchronous operation, then aio_return() may be
|
||||
* successfully used to retrieve the return status of that operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* aiocbp - A pointer to an instance of struct aiocb
|
||||
*
|
||||
* Returned Value:
|
||||
* If the asynchronous I/O operation has completed, then the return
|
||||
* status, as described for read(), write(), and fsync(), will be
|
||||
* returned. If the asynchronous I/O operation has not yet completed,
|
||||
* the results of aio_return() are undefined.
|
||||
*
|
||||
* The aio_return() function may fail if:
|
||||
*
|
||||
* EINVAL - The aiocbp argument does not refer to an asynchronous
|
||||
* operation whose return status has not yet been retrieved.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t aio_return(FAR struct aiocb *aiocbp)
|
||||
{
|
||||
DEBUGASSERT(aiocbp);
|
||||
if (aiocbp->aio_result < 0)
|
||||
{
|
||||
set_errno((int)-aiocbp->aio_result);
|
||||
return (ssize_t)ERROR;
|
||||
}
|
||||
|
||||
return aiocbp->aio_result;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FS_AIO */
|
||||
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/aio/aio_suspend.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <aio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef CONFIG_FS_AIO
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: aio_suspend
|
||||
*
|
||||
* Description:
|
||||
* The aio_suspend() function suspends the calling thread until at least
|
||||
* one of the asynchronous I/O operations referenced by the 'list' argument
|
||||
* has completed, until a signal interrupts the function, or, if 'timeout'
|
||||
* is not NULL, until the time interval specified by 'timeout' has passed.
|
||||
* If any of the aiocb structures in the list correspond to completed
|
||||
* asynchronous I/O operations (that is, the error status for the
|
||||
* operation is not equal to EINPROGRESS) at the time of the call, the
|
||||
* function returns without suspending the calling thread.
|
||||
*
|
||||
* Each aiocb structure pointed to must have been used in initiating an
|
||||
* asynchronous I/O request via aio_read(), aio_write(), or lio_listio().
|
||||
* This array may contain NULL pointers, which are ignored. If this
|
||||
* array contains pointers that refer to aiocb structures that have not
|
||||
* been used in submitting asynchronous I/O, the effect is undefined.
|
||||
*
|
||||
* Input Parameters:
|
||||
* list - An array of pointers to asynchronous I/O control blocks.
|
||||
* nent - The number of elements in the array.
|
||||
* aiocbp - A pointer to an array
|
||||
* timeout - If not NULL, this parameter is pointer to a timespec
|
||||
* structure that determines a timeout on the operation. If
|
||||
* the time referred to timeout passes before any of the I/O
|
||||
* operations referenced by list are completed, then
|
||||
* aio_suspend() returns with an error.
|
||||
*
|
||||
* Returned Value:
|
||||
* If the aio_suspend() function returns after one or more asynchronous
|
||||
* I/O operations have completed, the function returns zero. Otherwise,
|
||||
* the function returns a value of -1 and sets errno to indicate the
|
||||
* error. The application may determine which asynchronous I/O completed
|
||||
* by scanning the associated error and return status using aio_error()
|
||||
* and aio_return(), respectively.
|
||||
*
|
||||
* The aio_suspend() function will fail if:
|
||||
*
|
||||
* EAGAIN - No asynchronous I/O indicated in the list referenced by
|
||||
* list completed in the time interval indicated by timeout.
|
||||
* EINTR - A signal interrupted the aio_suspend() function.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int aio_suspend(FAR const struct aiocb *const list[], int nent,
|
||||
FAR const struct timespec *timeout)
|
||||
{
|
||||
sigset_t set;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(list);
|
||||
|
||||
/* Lock the scheduler so that no I/O events can complete on the worker
|
||||
* thread until we set our wait set up. Pre-emption will, of course, be
|
||||
* re-enabled while we are waiting for the signal.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
|
||||
/* Check each entry in the list. Break out of the loop if any entry
|
||||
* has completed.
|
||||
*/
|
||||
|
||||
for (i = 0; i < nent; i++)
|
||||
{
|
||||
/* Check if the I/O has completed */
|
||||
|
||||
if (list[i] && list[i]->aio_result != -EINPROGRESS)
|
||||
{
|
||||
/* Yes, return success */
|
||||
|
||||
sched_unlock();
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Then wait for SIGPOLL. On success sigtimedwait() will return the
|
||||
* signal number that cause the error (SIGPOLL). It will set errno
|
||||
* appropriately for this function on errors.
|
||||
*
|
||||
* NOTE: If completion of the I/O causes other signals to be generated
|
||||
* first, then this will wake up and return EINTR instead of success.
|
||||
*/
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGPOLL);
|
||||
|
||||
ret = sigtimedwait(&set, NULL, timeout);
|
||||
sched_unlock();
|
||||
return ret >= 0 ? OK : ERROR;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FS_AIO */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
############################################################################
|
||||
# libs/libc/audio/Make.defs
|
||||
#
|
||||
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_AUDIO),y)
|
||||
CSRCS += lib_buffer.c
|
||||
|
||||
# Add the audio/ directory to the build
|
||||
|
||||
DEPPATH += --dep-path audio
|
||||
VPATH += :audio
|
||||
endif
|
||||
@@ -0,0 +1,186 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/audio/lib_buffer.c
|
||||
*
|
||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/audio/audio.h>
|
||||
#include <nuttx/usb/audio.h>
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
#if defined(CONFIG_AUDIO)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_semtake
|
||||
*
|
||||
* Take an Audio Pipeline Buffer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void apb_semtake(FAR struct ap_buffer_s *apb)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
while (_SEM_WAIT(&apb->sem) < 0)
|
||||
{
|
||||
/* The only case that an error should occr here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR || _SEM_ERRNO(ret) == ECANCELED);
|
||||
UNUSED(ret);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_semgive
|
||||
****************************************************************************/
|
||||
|
||||
#define apb_semgive(b) _SEM_POST(&b->sem)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_alloc
|
||||
*
|
||||
* Allocate an Audio Pipeline Buffer for use in the Audio sub-system. This
|
||||
* will perform the actual allocate based on buffer data format, number of
|
||||
* channels, etc. and prepare the buffer for consumption.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int apb_alloc(FAR struct audio_buf_desc_s *bufdesc)
|
||||
{
|
||||
uint32_t bufsize;
|
||||
int ret;
|
||||
struct ap_buffer_s *apb;
|
||||
|
||||
DEBUGASSERT(bufdesc->u.ppBuffer != NULL);
|
||||
|
||||
/* Perform a user mode allocation */
|
||||
|
||||
bufsize = sizeof(struct ap_buffer_s) + bufdesc->numbytes;
|
||||
apb = lib_umalloc(bufsize);
|
||||
*bufdesc->u.ppBuffer = apb;
|
||||
|
||||
/* Test if the allocation was successful or not */
|
||||
|
||||
if (*bufdesc->u.ppBuffer == NULL)
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Populate the buffer contents */
|
||||
|
||||
memset(apb, 0, bufsize);
|
||||
apb->i.channels = 1;
|
||||
apb->crefs = 1;
|
||||
apb->nmaxbytes = bufdesc->numbytes;
|
||||
apb->nbytes = 0;
|
||||
apb->flags = 0;
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
apb->session = bufdesc->session;
|
||||
#endif
|
||||
|
||||
nxsem_init(&apb->sem, 0, 1);
|
||||
ret = sizeof(struct audio_buf_desc_s);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_free
|
||||
*
|
||||
* Free's a previously allocated or referenced Audio Pipeline Buffer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void apb_free(FAR struct ap_buffer_s *apb)
|
||||
{
|
||||
int refcount;
|
||||
|
||||
/* Perform a reference count decrement and possibly release the memory */
|
||||
|
||||
apb_semtake(apb);
|
||||
refcount = apb->crefs--;
|
||||
apb_semgive(apb);
|
||||
|
||||
if (refcount <= 1)
|
||||
{
|
||||
audinfo("Freeing %p\n", apb);
|
||||
lib_ufree(apb);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_reference
|
||||
*
|
||||
* Claim a reference to an Audio Pipeline Buffer. Each call to apb_reference
|
||||
* will increment the reference count and must have a matching apb_free
|
||||
* call. When the refcount decrements to zero, the buffer will be freed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void apb_reference(FAR struct ap_buffer_s *apb)
|
||||
{
|
||||
/* Do we need any thread protection here? Almost certaily... */
|
||||
|
||||
apb_semtake(apb);
|
||||
apb->crefs++;
|
||||
apb_semgive(apb);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_AUDIO */
|
||||
@@ -0,0 +1,8 @@
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
||||
@@ -0,0 +1,48 @@
|
||||
############################################################################
|
||||
# libs/libc/bin/Makefile
|
||||
#
|
||||
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
all:
|
||||
.PHONY: clean distclean
|
||||
|
||||
# Clean Targets:
|
||||
|
||||
clean:
|
||||
$(call CLEAN)
|
||||
|
||||
# Deep clean -- removes all traces of the configuration
|
||||
|
||||
distclean: clean
|
||||
@@ -0,0 +1,48 @@
|
||||
############################################################################
|
||||
# libs/libc/dirent/Make.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
|
||||
# Add the dirent C files to the build
|
||||
|
||||
CSRCS += lib_readdirr.c lib_telldir.c
|
||||
|
||||
# Add the dirent directory to the build
|
||||
|
||||
DEPPATH += --dep-path dirent
|
||||
VPATH += :dirent
|
||||
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dirent/lib_readdirr.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: readdir_r
|
||||
*
|
||||
* Description:
|
||||
* The readdir() function returns a pointer to a dirent
|
||||
* structure representing the next directory entry in the
|
||||
* directory stream pointed to by dir. It returns NULL on
|
||||
* reaching the end-of-file or if an error occurred.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
* call to opendir();
|
||||
* entry -- The storage pointed to by entry must be large
|
||||
* enough for a dirent with an array of char d_name
|
||||
* members containing at least {NAME_MAX}+1 elements.
|
||||
* result -- Upon successful return, the pointer returned
|
||||
* at *result shall have the same value as the
|
||||
* argument entry. Upon reaching the end of the directory
|
||||
* stream, this pointer shall have the value NULL.
|
||||
*
|
||||
* Returned Value:
|
||||
* If successful, the readdir_r() function return s zero;
|
||||
* otherwise, an error number is returned to indicate the
|
||||
* error.
|
||||
*
|
||||
* EBADF - Invalid directory stream descriptor dir
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int readdir_r(FAR DIR *dirp, FAR struct dirent *entry,
|
||||
FAR struct dirent **result)
|
||||
{
|
||||
struct dirent *tmp;
|
||||
|
||||
/* NOTE: The following use or errno is *not* thread-safe */
|
||||
|
||||
set_errno(0);
|
||||
tmp = readdir(dirp);
|
||||
if (!tmp)
|
||||
{
|
||||
int error = get_errno();
|
||||
if (!error)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
*result = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry)
|
||||
{
|
||||
memcpy(entry, tmp, sizeof(struct dirent));
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
*result = entry;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dirent/fs_telldir.c
|
||||
*
|
||||
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/fs/dirent.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: telldir
|
||||
*
|
||||
* Description:
|
||||
* The telldir() function returns the current location
|
||||
* associated with the directory stream dirp.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
* call to opendir();
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the telldir() function returns the current
|
||||
* location in the directory stream. On error, -1 is
|
||||
* returned, and errno is set appropriately.
|
||||
*
|
||||
* EBADF - Invalid directory stream descriptor dir
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
off_t telldir(FAR DIR *dirp)
|
||||
{
|
||||
struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
|
||||
|
||||
if (!idir || !idir->fd_root)
|
||||
{
|
||||
set_errno(EBADF);
|
||||
return (off_t)-1;
|
||||
}
|
||||
|
||||
/* Just return the current position */
|
||||
|
||||
return idir->fd_position;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
# menu "Shared Library Support"
|
||||
|
||||
config LIBC_DLLFCN
|
||||
bool "Shared library support"
|
||||
default n
|
||||
select LIBC_ARCH_ELF
|
||||
select LIBC_MODLIB if !BUILD_KERNEL
|
||||
select MODULE if BUILD_FLAT
|
||||
depends on EXPERIMENTAL || !BUILD_KERNEL
|
||||
---help---
|
||||
Enabled support for user-space shared libraries.
|
||||
|
||||
A work in progress, hence, marked EXPERIMENTAL
|
||||
|
||||
# endmenu # Shared Library Support
|
||||
@@ -0,0 +1,47 @@
|
||||
############################################################################
|
||||
# libs/libc/dllfcn/Make.defs
|
||||
#
|
||||
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_LIBC_DLLFCN),y)
|
||||
|
||||
# Add the dllfcn.h files to the build
|
||||
|
||||
CSRCS += lib_dlopen.c lib_dlclose.c lib_dlsym.c lib_dlerror.c lib_dlsymtab.c
|
||||
|
||||
# Add the dllfcn.h directory to the build
|
||||
|
||||
DEPPATH += --dep-path dllfcn
|
||||
VPATH += :dllfcn
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,251 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dllfcn/lib_dlclose.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <dllfcn.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/lib/modlib.h>
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlremove
|
||||
*
|
||||
* Description:
|
||||
* Remove a previously installed shared library from memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The shared library handle previously returned by dlopen().
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
|
||||
* errno value is set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
static inline int dlremove(FAR void *handle)
|
||||
{
|
||||
FAR struct module_s *modp = (FAR struct module_s *)handle;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(modp != NULL);
|
||||
|
||||
/* Get exclusive access to the module registry */
|
||||
|
||||
modlib_registry_lock();
|
||||
|
||||
/* Verify that the module is in the registry */
|
||||
|
||||
ret = modlib_registry_verify(modp);
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("ERROR: Failed to verify module: %d\n", ret);
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
#if CONFIG_MODLIB_MAXDEPEND > 0
|
||||
/* Refuse to remove any module that other modules may depend upon. */
|
||||
|
||||
if (modp->dependents > 0)
|
||||
{
|
||||
serr("ERROR: Module has dependents: %d\n", modp->dependents);
|
||||
ret = -EBUSY;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Is there an uninitializer? */
|
||||
|
||||
if (modp->modinfo.uninitializer != NULL)
|
||||
{
|
||||
/* Try to uninitialize the module */
|
||||
|
||||
ret = modp->modinfo.uninitializer(modp->modinfo.arg);
|
||||
|
||||
/* Did the module sucessfully uninitialize? */
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("ERROR: Failed to uninitialize the module: %d\n", ret);
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Nullify so that the uninitializer cannot be called again */
|
||||
|
||||
modp->modinfo.uninitializer = NULL;
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
||||
modp->initializer = NULL;
|
||||
modp->modinfo.arg = NULL;
|
||||
modp->modinfo.exports = NULL;
|
||||
modp->modinfo.nexports = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Release resources held by the module */
|
||||
|
||||
if (modp->alloc != NULL)
|
||||
{
|
||||
/* Free the module memory */
|
||||
|
||||
lib_free((FAR void *)modp->alloc);
|
||||
|
||||
/* Nullify so that the memory cannot be freed again */
|
||||
|
||||
modp->alloc = NULL;
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
||||
modp->textsize = 0;
|
||||
modp->datasize = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Remove the module from the registry */
|
||||
|
||||
ret = modlib_registry_del(modp);
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("ERROR: Failed to remove the module from the registry: %d\n", ret);
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
#if CONFIG_MODLIB_MAXDEPEND > 0
|
||||
/* Eliminate any dependencies that this module has on other modules */
|
||||
|
||||
(void)modlib_undepend(modp);
|
||||
#endif
|
||||
modlib_registry_unlock();
|
||||
|
||||
/* And free the registry entry */
|
||||
|
||||
lib_free(modp);
|
||||
return OK;
|
||||
|
||||
errout_with_lock:
|
||||
modlib_registry_unlock();
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlclose
|
||||
*
|
||||
* Description:
|
||||
* dlclose() is used to inform the system that the object referenced by a
|
||||
* handle returned from a previous dlopen() invocation is no longer needed
|
||||
* by the application.
|
||||
*
|
||||
* The use of dlclose() reflects a statement of intent on the part of the
|
||||
* process, but does not create any requirement upon the implementation,
|
||||
* such as removal of the code or symbols referenced by handle. Once an
|
||||
* object has been closed using dlclose() an application should assume
|
||||
* that its symbols are no longer available to dlsym(). All objects loaded
|
||||
* automatically as a result of invoking dlopen() on the referenced object
|
||||
* are also closed.
|
||||
*
|
||||
* Although a dlclose() operation is not required to remove structures
|
||||
* from an address space, neither is an implementation prohibited from
|
||||
* doing so. The only restriction on such a removal is that no object will
|
||||
* be removed to which references have been relocated, until or unless all
|
||||
* such references are removed. For instance, an object that had been
|
||||
* loaded with a dlopen() operation specifying the RTLD_GLOBAL flag might
|
||||
* provide a target for dynamic relocations performed in the processing of
|
||||
* other objects - in such environments, an application may assume that no
|
||||
* relocation, once made, will be undone or remade unless the object
|
||||
* requiring the relocation has itself been removed.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The opaque, non-NULL value returned by a previous successful
|
||||
* call to dlopen().
|
||||
*
|
||||
* Returned Value:
|
||||
* If the referenced object was successfully closed, dlclose() returns 0.
|
||||
* If the object could not be closed, or if handle does not refer to an
|
||||
* open object, dlclose() returns a non-zero value. More detailed
|
||||
* diagnostic information will be available through dlerror().
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int dlclose(FAR void *handle)
|
||||
{
|
||||
#if defined(CONFIG_BUILD_FLAT)
|
||||
/* In the FLAT build, a shared library is essentially the same as a kernel
|
||||
* module.
|
||||
*/
|
||||
|
||||
return rmmod(handle);
|
||||
|
||||
#elif defined(CONFIG_BUILD_PROTECTED)
|
||||
/* The PROTECTED build is equivalent to the FLAT build EXCEPT that there
|
||||
* must be two copies of the module logic: One residing in kernel
|
||||
* space and using the kernel symbol table and one residing in user space
|
||||
* using the user space symbol table.
|
||||
*
|
||||
* dlremove() is essentially a clone of rmmod().
|
||||
*/
|
||||
|
||||
return dlremove(handle);
|
||||
|
||||
#else /* if defined(CONFIG_BUILD_KERNEL) */
|
||||
/* The KERNEL build is considerably more complex: In order to be shared,
|
||||
* the .text portion of the module must be (1) build for PIC/PID operation
|
||||
* and (2) must like in a shared memory region accessible from all
|
||||
* processes. The .data/.bss portion of the module must be allocated in
|
||||
* the user space of each process, but must lie at the same virtual address
|
||||
* so that it can be referenced from the one copy of the text in the shared
|
||||
* memory region.
|
||||
*/
|
||||
|
||||
#warning Missing logic
|
||||
return -ENOSYS;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dllfcn/lib_dlerror.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <dllfcn.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlerror
|
||||
*
|
||||
* Description:
|
||||
* dlerror() returns a null-terminated character string (with no trailing
|
||||
* newline) that describes the last error that occurred during dynamic
|
||||
* linking processing. If no dynamic linking errors have occurred since
|
||||
* the last invocation of dlerror(), dlerror() returns NULL. Thus,
|
||||
* invoking dlerror() a second time, immediately following a prior
|
||||
* invocation, will result in NULL being returned.
|
||||
*
|
||||
* Input Parameters:
|
||||
* If successful, dlerror() returns a null-terminated character string.
|
||||
* Otherwise, NULL is returned.
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *dlerror(void)
|
||||
{
|
||||
#warning Missing logic
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dllfcn/lib_dlopen.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <dllfcn.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/lib/modlib.h>
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dldump_loadinfo
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
#if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
binfo("LOAD_INFO:\n");
|
||||
binfo(" textalloc: %08lx\n", (long)loadinfo->textalloc);
|
||||
binfo(" datastart: %08lx\n", (long)loadinfo->datastart);
|
||||
binfo(" textsize: %ld\n", (long)loadinfo->textsize);
|
||||
binfo(" datasize: %ld\n", (long)loadinfo->datasize);
|
||||
binfo(" filelen: %ld\n", (long)loadinfo->filelen);
|
||||
binfo(" filfd: %d\n", loadinfo->filfd);
|
||||
binfo(" symtabidx: %d\n", loadinfo->symtabidx);
|
||||
binfo(" strtabidx: %d\n", loadinfo->strtabidx);
|
||||
|
||||
binfo("ELF Header:\n");
|
||||
binfo(" e_ident: %02x %02x %02x %02x\n",
|
||||
loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1],
|
||||
loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]);
|
||||
binfo(" e_type: %04x\n", loadinfo->ehdr.e_type);
|
||||
binfo(" e_machine: %04x\n", loadinfo->ehdr.e_machine);
|
||||
binfo(" e_version: %08x\n", loadinfo->ehdr.e_version);
|
||||
binfo(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry);
|
||||
binfo(" e_phoff: %d\n", loadinfo->ehdr.e_phoff);
|
||||
binfo(" e_shoff: %d\n", loadinfo->ehdr.e_shoff);
|
||||
binfo(" e_flags: %08x\n" , loadinfo->ehdr.e_flags);
|
||||
binfo(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize);
|
||||
binfo(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize);
|
||||
binfo(" e_phnum: %d\n", loadinfo->ehdr.e_phnum);
|
||||
binfo(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize);
|
||||
binfo(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
|
||||
binfo(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);
|
||||
|
||||
if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
|
||||
{
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
binfo("Sections %d:\n", i);
|
||||
binfo(" sh_name: %08x\n", shdr->sh_name);
|
||||
binfo(" sh_type: %08x\n", shdr->sh_type);
|
||||
binfo(" sh_flags: %08x\n", shdr->sh_flags);
|
||||
binfo(" sh_addr: %08x\n", shdr->sh_addr);
|
||||
binfo(" sh_offset: %d\n", shdr->sh_offset);
|
||||
binfo(" sh_size: %d\n", shdr->sh_size);
|
||||
binfo(" sh_link: %d\n", shdr->sh_link);
|
||||
binfo(" sh_info: %d\n", shdr->sh_info);
|
||||
binfo(" sh_addralign: %d\n", shdr->sh_addralign);
|
||||
binfo(" sh_entsize: %d\n", shdr->sh_entsize);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define dldump_loadinfo(i)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dldump_initializer
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
#ifdef CONFIG_MODLIB_DUMPBUFFER
|
||||
static void dldump_initializer(mod_initializer_t initializer,
|
||||
FAR struct mod_loadinfo_s *loadinfo)
|
||||
{
|
||||
modlib_dumpbuffer("Initializer code", (FAR const uint8_t *)initializer,
|
||||
MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512));
|
||||
}
|
||||
#else
|
||||
# define dldump_initializer(b,l)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlinsert
|
||||
*
|
||||
* Description:
|
||||
* Verify that the file is an ELF module binary and, if so, load the
|
||||
* shared library into user memory and initialize it for use.
|
||||
*
|
||||
* NOTE: modlib_setsymtab() had to have been called by application logic
|
||||
* logic prior to calling this. Otherwise, dlinsert will be unable to
|
||||
* resolve symbols in the OS module.
|
||||
*
|
||||
* Input Parameters:
|
||||
* filename - Full path to the shared library file to be loaded
|
||||
*
|
||||
* Returned Value:
|
||||
* A non-NULL module handle that can be used on subsequent calls to other
|
||||
* shared library interfaces is returned on success. If insmod() was
|
||||
* unable to load the module insmod() will return a NULL handle and the
|
||||
* errno variable will be set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
static inline FAR void *dlinsert(FAR const char *filename)
|
||||
{
|
||||
struct mod_loadinfo_s loadinfo;
|
||||
FAR struct module_s *modp;
|
||||
mod_initializer_t initializer;
|
||||
int ret;
|
||||
|
||||
binfo("Loading file: %s\n", filename);
|
||||
|
||||
/* Get exclusive access to the module registry */
|
||||
|
||||
modlib_registry_lock();
|
||||
|
||||
/* Initialize the ELF library to load the program binary. */
|
||||
|
||||
ret = modlib_initialize(filename, &loadinfo);
|
||||
dldump_loadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
serr("ERROR: Failed to initialize to load module: %d\n", ret);
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Allocate a module registry entry to hold the module data */
|
||||
|
||||
modp = (FAR struct module_s *)lib_zalloc(sizeof(struct module_s));
|
||||
if (ret != 0)
|
||||
{
|
||||
binfo("Failed to initialize for load of ELF program: %d\n", ret);
|
||||
goto errout_with_loadinfo;
|
||||
}
|
||||
|
||||
/* Load the program binary */
|
||||
|
||||
ret = modlib_load(&loadinfo);
|
||||
dldump_loadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
binfo("Failed to load ELF program binary: %d\n", ret);
|
||||
goto errout_with_registry_entry;
|
||||
}
|
||||
|
||||
/* Bind the program to the kernel symbol table */
|
||||
|
||||
ret = modlib_bind(modp, &loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
binfo("Failed to bind symbols program binary: %d\n", ret);
|
||||
goto errout_with_load;
|
||||
}
|
||||
|
||||
/* Save the load information */
|
||||
|
||||
modp->alloc = (FAR void *)loadinfo.textalloc;
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
||||
modp->textsize = loadinfo.textsize;
|
||||
modp->datasize = loadinfo.datasize;
|
||||
#endif
|
||||
|
||||
/* Get the module initializer entry point */
|
||||
|
||||
initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry);
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
||||
modp->initializer = initializer;
|
||||
#endif
|
||||
dldump_initializer(initializer, &loadinfo);
|
||||
|
||||
/* Call the module initializer */
|
||||
|
||||
ret = initializer(&modp->modinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
binfo("Failed to initialize the module: %d\n", ret);
|
||||
goto errout_with_load;
|
||||
}
|
||||
|
||||
/* Add the new module entry to the registry */
|
||||
|
||||
modlib_registry_add(modp);
|
||||
|
||||
modlib_uninitialize(&loadinfo);
|
||||
modlib_registry_unlock();
|
||||
return (FAR void *)modp;
|
||||
|
||||
errout_with_load:
|
||||
modlib_unload(&loadinfo);
|
||||
(void)modlib_undepend(modp);
|
||||
errout_with_registry_entry:
|
||||
lib_free(modp);
|
||||
errout_with_loadinfo:
|
||||
modlib_uninitialize(&loadinfo);
|
||||
errout_with_lock:
|
||||
modlib_registry_unlock();
|
||||
set_errno(-ret);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlopen
|
||||
*
|
||||
* Description:
|
||||
* dlopen() makes an executable object file specified by file available to
|
||||
* the calling program. The class of files eligible for this operation and
|
||||
* the manner of their construction are specified by the implementation,
|
||||
* though typically such files are executable objects such as shared
|
||||
* libraries, relocatable files or programs. Note that some implementations
|
||||
* permit the construction of dependencies between such objects that are
|
||||
* embedded within files. In such cases, a dlopen() operation will load
|
||||
* such dependencies in addition to the object referenced by file.
|
||||
* Implementations may also impose specific constraints on the construction
|
||||
* of programs that can employ dlopen() and its related services.
|
||||
*
|
||||
* If a file is specified in multiple dlopen() invocations, mode is
|
||||
* interpreted at each invocation. Note, however, that once RTLD_NOW has
|
||||
* been specified all relocations will have been completed rendering
|
||||
* further RTLD_NOW operations redundant and any further RTLD_LAZY
|
||||
* operations irrelevant. Similarly note that once RTLD_GLOBAL has been
|
||||
* specified the object will maintain the RTLD_GLOBAL status regardless
|
||||
* of any previous or future specification of RTLD_LOCAL, so long as the
|
||||
* object remains in the address space (see dlclose()).
|
||||
*
|
||||
* Symbols introduced into a program through calls to dlopen() may be
|
||||
* used in relocation activities. Symbols so introduced may duplicate
|
||||
* symbols already defined by the program or previous dlopen()
|
||||
* operations. To resolve the ambiguities such a situation might
|
||||
* present, the resolution of a symbol reference to symbol definition is
|
||||
* based on a symbol resolution order. Two such resolution orders are
|
||||
* defined: load or dependency ordering. Load order establishes an
|
||||
* ordering among symbol definitions, such that the definition first
|
||||
* loaded (including definitions from the image file and any dependent
|
||||
* objects loaded with it) has priority over objects added later (via
|
||||
* dlopen()). Load ordering is used in relocation processing. Dependency
|
||||
* ordering uses a breadth-first order starting with a given object,
|
||||
* then all of its dependencies, then any dependents of those, iterating
|
||||
* until all dependencies are satisfied. With the exception of the global
|
||||
* symbol object obtained via a dlopen() operation on a file of 0,
|
||||
* dependency ordering is used by the dlsym() function. Load ordering is
|
||||
* used in dlsym() operations upon the global symbol object.
|
||||
*
|
||||
* When an object is first made accessible via dlopen() it and its
|
||||
* dependent objects are added in dependency order. Once all the objects
|
||||
* are added, relocations are performed using load order. Note that if an
|
||||
* object or its dependencies had been previously loaded, the load and
|
||||
* dependency orders may yield different resolutions.
|
||||
*
|
||||
* The symbols introduced by dlopen() operations, and available through
|
||||
* dlsym() are at a minimum those which are exported as symbols of global
|
||||
* scope by the object. Typically such symbols will be those that were
|
||||
* specified in (for example) C source code as having extern linkage. The
|
||||
* precise manner in which an implementation constructs the set of
|
||||
* exported symbols for a dlopen() object is specified by that
|
||||
* implementation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* file - Used to construct a pathname to the object file. If file
|
||||
* contains a slash character, the file argument is used as the
|
||||
* pathname for the file. Otherwise, file is used in an
|
||||
* implementation-dependent manner to yield a pathname.
|
||||
*
|
||||
* If the value of file is 0, dlopen() provides a handle on a
|
||||
* global symbol object. This object provides access to the symbols
|
||||
* from an ordered set of objects consisting of the original
|
||||
* program image file, together with any objects loaded at program
|
||||
* startup as specified by that process image file (for example,
|
||||
* shared libraries), and the set of objects loaded using a
|
||||
* dlopen() operation together with the RTLD_GLOBAL flag. As the
|
||||
* latter set of objects can change during execution, the set
|
||||
* identified by handle can also change dynamically.
|
||||
*
|
||||
* Only a single copy of an object file is brought into the address
|
||||
* space, even if dlopen() is invoked multiple times in reference
|
||||
* to the file, and even if different pathnames are used to
|
||||
* reference the file.
|
||||
* mode - Describes how dlopen() will operate upon file with respect to
|
||||
* the processing of relocations and the scope of visibility of the
|
||||
* symbols provided within file. When an object is brought into the
|
||||
* address space of a process, it may contain references to symbols
|
||||
* whose addresses are not known until the object is loaded. These
|
||||
* references must be relocated before the symbols can be accessed.
|
||||
* The mode parameter governs when these relocations take place.
|
||||
* See definitions above for values of the mode parameter:.
|
||||
*
|
||||
* Returned Value:
|
||||
* A successful dlopen() returns a handle which the caller may use on
|
||||
* subsequent calls to dlsym() and dlclose(). The value of this handle
|
||||
* should not be interpreted in any way by the caller.
|
||||
*
|
||||
* If file cannot be found, cannot be opened for reading, is not of an
|
||||
* appropriate object format for processing by dlopen(), or if an error
|
||||
* occurs during the process of loading file or relocating its symbolic
|
||||
* references, dlopen() will return NULL. More detailed diagnostic
|
||||
* information will be available through dlerror().
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *dlopen(FAR const char *file, int mode)
|
||||
{
|
||||
#if defined(CONFIG_BUILD_FLAT)
|
||||
FAR void *handle;
|
||||
FAR char *name;
|
||||
|
||||
DEBUGASSERT(file != NULL);
|
||||
|
||||
/* In the FLAT build, a shared library is essentially the same as a kernel
|
||||
* module.
|
||||
*
|
||||
* REVIST: Missing functionality:
|
||||
* - No automatic binding of symbols
|
||||
* - No dependencies
|
||||
* - mode is ignored.
|
||||
*/
|
||||
|
||||
/* Use the basename of the file as the module name.
|
||||
* REVISIT: This places an non-standard restriction. We cannot install
|
||||
* two modules of the same name event though they lie in different
|
||||
* directories.
|
||||
*/
|
||||
|
||||
name = strdup(file);
|
||||
if (name == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Then install the file using the basename of the file as the module name. */
|
||||
|
||||
handle = insmod(file, basename(name));
|
||||
free(name);
|
||||
return handle;
|
||||
|
||||
#elif defined(CONFIG_BUILD_PROTECTED)
|
||||
/* The PROTECTED build is equivalent to the FLAT build EXCEPT that there
|
||||
* must be two copies of the module logic: One residing in kernel
|
||||
* space and using the kernel symbol table and one residing in user space
|
||||
* using the user space symbol table.
|
||||
*
|
||||
* dlinsert() is essentially a clone of insmod().
|
||||
*/
|
||||
|
||||
return dlinsert(file);
|
||||
|
||||
#else /* if defined(CONFIG_BUILD_KERNEL) */
|
||||
/* The KERNEL build is considerably more complex: In order to be shared,
|
||||
* the .text portion of the module must be (1) build for PIC/PID operation
|
||||
* and (2) must like in a shared memory region accessible from all
|
||||
* processes. The .data/.bss portion of the module must be allocated in
|
||||
* the user space of each process, but must lie at the same virtual address
|
||||
* so that it can be referenced from the one copy of the text in the shared
|
||||
* memory region.
|
||||
*/
|
||||
|
||||
#warning Missing logic
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dllfcn/lib_dlsym.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <dllfcn.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/symtab.h>
|
||||
#include <nuttx/lib/modlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlgetsym
|
||||
*
|
||||
* Description:
|
||||
* dlgetsym() implements dlsym() for the PROTECTED build.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The opaque, non-NULL value returned by a previous successful
|
||||
* call to insmod().
|
||||
* name - A pointer to the symbol name string.
|
||||
*
|
||||
* Returned Value:
|
||||
* See dlsym().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
static inline FAR const void *dlgetsym(FAR void *handle,
|
||||
FAR const char *name)
|
||||
{
|
||||
FAR struct module_s *modp = (FAR struct module_s *)handle;
|
||||
FAR const struct symtab_s *symbol;
|
||||
int err;
|
||||
int ret;
|
||||
|
||||
/* Verify that the module is in the registry */
|
||||
|
||||
modlib_registry_lock();
|
||||
ret = modlib_registry_verify(modp);
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("ERROR: Failed to verify module: %d\n", ret);
|
||||
err = -ret;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Does the module have a symbol table? */
|
||||
|
||||
if (modp->modinfo.exports == NULL || modp->modinfo.nexports == 0)
|
||||
{
|
||||
serr("ERROR: Module has no symbol table\n");
|
||||
err = ENOENT;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Search the symbol table for the matching symbol */
|
||||
|
||||
symbol = symtab_findbyname(modp->modinfo.exports, name,
|
||||
modp->modinfo.nexports);
|
||||
if (symbol == NULL)
|
||||
{
|
||||
serr("ERROR: Failed to find symbol in symbol \"$s\" in table\n", name);
|
||||
err = ENOENT;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Return the address within the module assoicated with the symbol */
|
||||
|
||||
modlib_registry_unlock();
|
||||
DEBUGASSERT(symbol->sym_value != NULL);
|
||||
return symbol->sym_value;
|
||||
|
||||
errout_with_lock:
|
||||
modlib_registry_unlock();
|
||||
set_errno(err);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlsym
|
||||
*
|
||||
* Description:
|
||||
* dlsym() allows a process to obtain the address of a symbol defined
|
||||
* within an object made accessible through a dlopen() call. handle is the
|
||||
* value returned from a call to dlopen() (and which has not since been
|
||||
* released via a call to dlclose()), name is the symbol's name as a
|
||||
* character string.
|
||||
*
|
||||
* dlsym() will search for the named symbol in all objects loaded
|
||||
* automatically as a result of loading the object referenced by handle
|
||||
* (see dlopen()). Load ordering is used in dlsym() operations upon the
|
||||
* global symbol object. The symbol resolution algorithm used will be
|
||||
* dependency order as described in dlopen().
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The opaque, non-NULL value returned by a previous successful
|
||||
* call to dlopen().
|
||||
* name - A pointer to the symbol name string.
|
||||
*
|
||||
* Returned Value:
|
||||
* If handle does not refer to a valid object opened by dlopen(), or if
|
||||
* the named symbol cannot be found within any of the objects associated
|
||||
* with handle, dlsym() will return NULL. More detailed diagnostic
|
||||
* information will be available through dlerror().
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *dlsym(FAR void *handle, FAR const char *name)
|
||||
{
|
||||
#if defined(CONFIG_BUILD_FLAT)
|
||||
/* In the FLAT build, a shared library is essentially the same as a kernel
|
||||
* module.
|
||||
*/
|
||||
|
||||
return (FAR void *)modsym(handle, name);
|
||||
|
||||
#elif defined(CONFIG_BUILD_PROTECTED)
|
||||
/* The PROTECTED build is equivalent to the FLAT build EXCEPT that there
|
||||
* must be two copies of the module logic: One residing in kernel
|
||||
* space and using the kernel symbol table and one residing in user space
|
||||
* using the user space symbol table.
|
||||
*
|
||||
* dlgetsem() is essentially a clone of modsym().
|
||||
*/
|
||||
|
||||
return (FAR void *)dlgetsym(handle, name);
|
||||
|
||||
#else /* if defined(CONFIG_BUILD_KERNEL) */
|
||||
/* The KERNEL build is considerably more complex: In order to be shared,
|
||||
* the .text portion of the module must be (1) build for PIC/PID operation
|
||||
* and (2) must like in a shared memory region accessible from all
|
||||
* processes. The .data/.bss portion of the module must be allocated in
|
||||
* the user space of each process, but must lie at the same virtual address
|
||||
* so that it can be referenced from the one copy of the text in the shared
|
||||
* memory region.
|
||||
*/
|
||||
|
||||
#warning Missing logic
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/dllfcn/lib_symtab.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <dllfcn.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/lib/modlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlsymtab
|
||||
*
|
||||
* Description:
|
||||
* dlsymtab() is a non-standard shared library interface. It selects the
|
||||
* symbol table to use when binding a shared libary to the base firmware
|
||||
* which may be in FLASH memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The new symbol table.
|
||||
* nsymbols - The number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* Always returns OK.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int dlsymtab(FAR const struct symtab_s *symtab, int nsymbols)
|
||||
{
|
||||
#if defined(CONFIG_BUILD_FLAT) || defined(CONFIG_BUILD_PROTECTED)
|
||||
/* Set the symbol take information that will be used by this instance of
|
||||
* the module library.
|
||||
*/
|
||||
|
||||
modlib_setsymtab(symtab, nsymbols);
|
||||
return OK;
|
||||
|
||||
#else /* if defined(CONFIG_BUILD_KERNEL) */
|
||||
/* The KERNEL build is considerably more complex: In order to be shared,
|
||||
* the .text portion of the module must be (1) build for PIC/PID operation
|
||||
* and (2) must like in a shared memory region accessible from all
|
||||
* processes. The .data/.bss portion of the module must be allocated in
|
||||
* the user space of each process, but must lie at the same virtual address
|
||||
* so that it can be referenced from the one copy of the text in the shared
|
||||
* memory region.
|
||||
*/
|
||||
|
||||
#warning Missing logic
|
||||
return -ENOSYS;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
############################################################################
|
||||
# libs/libc/fixedmath/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Add the fixed precision math C files to the build
|
||||
|
||||
CSRCS += lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c
|
||||
CSRCS += lib_ubsqrt.c
|
||||
|
||||
# Add the fixed precision math directory to the build
|
||||
|
||||
DEPPATH += --dep-path fixedmath
|
||||
VPATH += :fixedmath
|
||||
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/fixedmath/lib_b16atan2.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define B16_C1 0x00000373 /* 0.013480470 */
|
||||
#define B16_C2 0x00000eb7 /* 0.057477314 */
|
||||
#define B16_C3 0x00001f0a /* 0.121239071 */
|
||||
#define B16_C4 0x00003215 /* 0.195635925 */
|
||||
#define B16_C5 0x0000553f /* 0.332994597 */
|
||||
#define B16_C6 0x00010000 /* 0.999995630 */
|
||||
#define B16_HALFPI 0x00019220 /* 1.570796327 */
|
||||
#define B16_PI 0x00032440 /* 3.141592654 */
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
|
||||
#ifndef ABS
|
||||
# define ABS(a) (a < 0 ? -a : a)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16atan2
|
||||
*
|
||||
* Description:
|
||||
* atan2 calculates the arctangent of y/x. (Based on a algorithm I saw
|
||||
* posted on the internet... now I have lost the link -- sorry).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16atan2(b16_t y, b16_t x)
|
||||
{
|
||||
b16_t t0;
|
||||
b16_t t1;
|
||||
b16_t t2;
|
||||
b16_t t3;
|
||||
|
||||
t2 = ABS(x);
|
||||
t1 = ABS(y);
|
||||
t0 = MAX(t2, t1);
|
||||
t1 = MIN(t2, t1);
|
||||
t2 = ub16inv(t0);
|
||||
t2 = b16mulb16(t1, t2);
|
||||
|
||||
t3 = b16mulb16(t2, t2);
|
||||
t0 = - B16_C1;
|
||||
t0 = b16mulb16(t0, t3) + B16_C2;
|
||||
t0 = b16mulb16(t0, t3) - B16_C3;
|
||||
t0 = b16mulb16(t0, t3) + B16_C4;
|
||||
t0 = b16mulb16(t0, t3) - B16_C5;
|
||||
t0 = b16mulb16(t0, t3) + B16_C6;
|
||||
t2 = b16mulb16(t0, t2);
|
||||
|
||||
t2 = (ABS(y) > ABS(x)) ? B16_HALFPI - t2 : t2;
|
||||
t2 = (x < 0) ? B16_PI - t2 : t2;
|
||||
t2 = (y < 0) ? -t2 : t2;
|
||||
|
||||
return t2;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/fixedmath/lib_b16cos.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16cos
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16cos(b16_t rad)
|
||||
{
|
||||
/* Compute cosine: sin(rad + PI/2) = cos(rad) */
|
||||
|
||||
rad += b16HALFPI;
|
||||
if (rad > b16PI)
|
||||
{
|
||||
rad -= b16TWOPI;
|
||||
}
|
||||
return b16sin(rad);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/fixedmath/lib_b16sin.c
|
||||
*
|
||||
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define b16_P225 0x0000399a
|
||||
#define b16_P405284735 0x000067c1
|
||||
#define b16_1P27323954 0x000145f3
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16sin
|
||||
* Ref: http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16sin(b16_t rad)
|
||||
{
|
||||
b16_t tmp1;
|
||||
b16_t tmp2;
|
||||
b16_t tmp3;
|
||||
|
||||
/* Force angle into the good range */
|
||||
|
||||
if (rad < -b16PI)
|
||||
{
|
||||
rad += b16TWOPI;
|
||||
}
|
||||
else if (rad > b16PI)
|
||||
{
|
||||
rad -= b16TWOPI;
|
||||
}
|
||||
|
||||
/* tmp1 = 1.27323954 * rad
|
||||
* tmp2 = .405284735 * rad * rad
|
||||
*/
|
||||
|
||||
|
||||
tmp1 = b16mulb16(b16_1P27323954, rad);
|
||||
tmp2 = b16mulb16(b16_P405284735, b16sqr(rad));
|
||||
|
||||
if (rad < 0)
|
||||
{
|
||||
/* tmp3 = 1.27323954 * rad + .405284735 * rad * rad */
|
||||
|
||||
tmp3 = tmp1 + tmp2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* tmp3 = 1.27323954 * rad - 0.405284735 * rad * rad */
|
||||
|
||||
tmp3 = tmp1 - tmp2;
|
||||
}
|
||||
|
||||
/* tmp1 = tmp3*tmp3 */
|
||||
|
||||
tmp1 = b16sqr(tmp3);
|
||||
if (tmp3 < 0)
|
||||
{
|
||||
/* tmp1 = tmp3 * -tmp3 */
|
||||
|
||||
tmp1 = -tmp1;
|
||||
}
|
||||
|
||||
/* Return sin = .225 * (tmp3 * (+/-tmp3) - tmp3) + tmp3 */
|
||||
|
||||
return b16mulb16(b16_P225, (tmp1 - tmp3)) + tmp3;
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/math/lib_fixedmath.c
|
||||
*
|
||||
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <fixedmath.h>
|
||||
|
||||
#ifndef CONFIG_HAVE_LONG_LONG
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fixsign
|
||||
****************************************************************************/
|
||||
|
||||
static void fixsign(b16_t *parg1, b16_t *parg2, bool *pnegate)
|
||||
{
|
||||
bool negate = false;
|
||||
b16_t arg;
|
||||
|
||||
arg = *parg1;
|
||||
if (arg < 0)
|
||||
{
|
||||
*parg1 = -arg;
|
||||
negate = true;
|
||||
}
|
||||
|
||||
arg = *parg2;
|
||||
if (arg < 0)
|
||||
{
|
||||
*parg2 = -arg;
|
||||
negate ^= true;
|
||||
}
|
||||
|
||||
*pnegate = negate;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adjustsign
|
||||
****************************************************************************/
|
||||
|
||||
static b16_t adjustsign(b16_t result, bool negate)
|
||||
{
|
||||
/* If the product is negative, then we overflowed */
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
return b16MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return b16MAX;
|
||||
}
|
||||
}
|
||||
|
||||
/* correct the sign of the result */
|
||||
|
||||
if (negate)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16mulb16
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16mulb16(b16_t m1, b16_t m2)
|
||||
{
|
||||
bool negate;
|
||||
b16_t product;
|
||||
|
||||
fixsign(&m1, &m2, &negate);
|
||||
product = (b16_t)ub16mulub16((ub16_t)m1, (ub16_t)m2);
|
||||
return adjustsign(product, negate);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ub16mulub16
|
||||
****************************************************************************/
|
||||
|
||||
ub16_t ub16mulub16(ub16_t m1, ub16_t m2)
|
||||
{
|
||||
/* Let:
|
||||
*
|
||||
* m1 = m1i*2**16 + m1f (b16)
|
||||
* m2 = m2i*2**16 + m2f (b16)
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32)
|
||||
* = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16)
|
||||
* = a*2**16 + b + c*2**-16
|
||||
*/
|
||||
|
||||
uint32_t m1i = ((uint32_t)m1 >> 16);
|
||||
uint32_t m2i = ((uint32_t)m1 >> 16);
|
||||
uint32_t m1f = ((uint32_t)m1 & 0x0000ffff);
|
||||
uint32_t m2f = ((uint32_t)m2 & 0x0000ffff);
|
||||
|
||||
return (m1i*m2i << 16) + m1i*m2f + m2i*m1f + (((m1f*m2f) + b16HALF) >> 16);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16sqr
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16sqr(b16_t a)
|
||||
{
|
||||
b16_t sq;
|
||||
|
||||
/* The result is always positive. Just take the absolute value */
|
||||
|
||||
if (a < 0)
|
||||
{
|
||||
a = -a;
|
||||
}
|
||||
|
||||
/* Overflow occurred if the result is negative */
|
||||
|
||||
sq = (b16_t)ub16sqr(a);
|
||||
if (sq < 0)
|
||||
{
|
||||
sq = b16MAX;
|
||||
}
|
||||
return sq;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16divb16
|
||||
****************************************************************************/
|
||||
|
||||
ub16_t ub16sqr(ub16_t a)
|
||||
{
|
||||
/* Let:
|
||||
*
|
||||
* m = mi*2**16 + mf (b16)
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32)
|
||||
* = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16)
|
||||
*/
|
||||
|
||||
uint32_t mi = ((uint32_t)a >> 16);
|
||||
uint32_t mf = ((uint32_t)a & 0x0000ffff);
|
||||
|
||||
return (mi*mi << 16) + (mi*mf << 1) + ((mf*mf + b16HALF) >> 16);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16divb16
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16divb16(b16_t num, b16_t denom)
|
||||
{
|
||||
bool negate;
|
||||
b16_t quotient;
|
||||
|
||||
fixsign(&num, &denom, &negate);
|
||||
quotient = (b16_t)ub16divub16((ub16_t)num, (ub16_t)denom);
|
||||
return adjustsign(quotient, negate);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ub16divub16
|
||||
****************************************************************************/
|
||||
|
||||
ub16_t ub16divub16(ub16_t num, ub16_t denom)
|
||||
{
|
||||
uint32_t term1;
|
||||
uint32_t numf;
|
||||
uint32_t product;
|
||||
|
||||
/* Let:
|
||||
*
|
||||
* num = numi*2**16 + numf (b16)
|
||||
* den = deni*2**16 + denf (b16)
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* num/den = numi*2**16 / den + numf / den (b0)
|
||||
* = numi*2**32 / den + numf*2**16 /den (b16)
|
||||
*/
|
||||
|
||||
/* Check for overflow in the first part of the quotient */
|
||||
|
||||
term1 = ((uint32_t)num & 0xffff0000) / denom;
|
||||
if (term1 >= 0x00010000)
|
||||
{
|
||||
return ub16MAX; /* Will overflow */
|
||||
}
|
||||
|
||||
/* Finish the division */
|
||||
|
||||
numf = num - term1 * denom;
|
||||
term1 <<= 16;
|
||||
product = term1 + (numf + (denom >> 1)) / denom;
|
||||
|
||||
/* Check for overflow */
|
||||
|
||||
if (product < term1)
|
||||
{
|
||||
return ub16MAX; /* Overflowed */
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/fixedmath/lib_ubsqrt.c
|
||||
*
|
||||
* Copyright (C) 2014,2017 Jussi Kivilinna <jussi.kivilinna@haltian.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ub32sqrtub16
|
||||
*
|
||||
* Description:
|
||||
* ub32sqrtub16 calculates square root for 'a'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ub16_t ub32sqrtub16(ub32_t a)
|
||||
{
|
||||
uint64_t n = a;
|
||||
uint64_t xk = n;
|
||||
|
||||
/* Direct conversion of ub32_t to uint64_t is same operation as multiplying
|
||||
* 'a' by 2^32, therefore n = a * 2^32.
|
||||
*/
|
||||
|
||||
if (xk == UINT64_MAX)
|
||||
{
|
||||
/* Avoid 'xk + n / xk' overflow on first iteration. */
|
||||
|
||||
xk = (uint64_t)1 << 63;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
uint64_t xk1 = (xk + n / xk) >> 1;
|
||||
|
||||
if (xk1 >= xk)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
xk = xk1;
|
||||
}
|
||||
while (1);
|
||||
|
||||
/* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^32)' => 'sqrt(a) * 2^16', thus
|
||||
* 'xk' holds square root of 'a' in ub16_t format.
|
||||
*/
|
||||
|
||||
return (ub16_t)xk;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ub16sqrtub8
|
||||
*
|
||||
* Description:
|
||||
* ub16sqrtub8 calculates square root for 'a'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ub8_t ub16sqrtub8(ub16_t a)
|
||||
{
|
||||
uint32_t n = a;
|
||||
uint32_t xk = n;
|
||||
|
||||
/* Direct conversion of ub16_t to uint32_t is same operation as multiplying
|
||||
* 'a' by 2^16, therefore n = a * 2^16.
|
||||
*/
|
||||
|
||||
if (xk == UINT32_MAX)
|
||||
{
|
||||
/* Avoid 'xk + n / xk' overflow on first iteration. */
|
||||
|
||||
xk = (uint32_t)1 << 31;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
uint32_t xk1 = (xk + n / xk) >> 1;
|
||||
|
||||
if (xk1 >= xk)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
xk = xk1;
|
||||
}
|
||||
while (1);
|
||||
|
||||
/* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^16)' => 'sqrt(a) * 2^8', thus
|
||||
* 'xk' holds square root of 'a' in ub8_t format.
|
||||
*/
|
||||
|
||||
return (ub8_t)xk;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config LIB_HEX2BIN
|
||||
bool "Intel HEX to binary conversion library"
|
||||
default n
|
||||
---help---
|
||||
Build in support for conversions from Intel Hex format to binary.
|
||||
This selection enables the interfaces of include/hex2bin.h.
|
||||
@@ -0,0 +1,47 @@
|
||||
############################################################################
|
||||
# libs/libc/hex2bin/Make.defs
|
||||
#
|
||||
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_LIB_HEX2BIN),y)
|
||||
|
||||
# Add the hex2bin sources to the build
|
||||
|
||||
CSRCS += lib_fhex2mem.c lib_hex2bin.c lib_hex2mem.c
|
||||
|
||||
# Add the hex2bin directory to the build
|
||||
|
||||
DEPPATH += --dep-path hex2bin
|
||||
VPATH += :hex2bin
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/hex2bin/fhex2mem.c
|
||||
*
|
||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <hex2bin.h>
|
||||
|
||||
#include <nuttx/streams.h>
|
||||
|
||||
#ifdef CONFIG_LIB_HEX2BIN
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fhex2mem
|
||||
*
|
||||
* Description:
|
||||
* Read the Intel HEX ASCII data provided on the standard stream
|
||||
* 'instream' and write the binary to memory.
|
||||
*
|
||||
* If, for example, instream is stdin, then the HEX ASCII data would be
|
||||
* taken from the console and written to memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* instream - The incoming standard stream from which Intel HEX data
|
||||
* will be received.
|
||||
* baseaddr - The base address of the memory region stream.
|
||||
* endpaddr - The end address (plus 1) of the memory region.
|
||||
* swap - Controls byte ordering. See enum hex2bin_swap_e for
|
||||
* description of the values.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int fhex2mem(FAR FILE *instream, uint32_t baseaddr, uint32_t endpaddr,
|
||||
enum hex2bin_swap_e swap)
|
||||
{
|
||||
struct lib_stdinstream_s stdinstream;
|
||||
struct lib_memsostream_s memoutstream;
|
||||
|
||||
/* Check memory addresses */
|
||||
|
||||
DEBUGASSERT(instream != NULL && endpaddr > baseaddr);
|
||||
|
||||
/* Wrap the file descriptor as raw stream; wrap the memory as a memory
|
||||
* stream.
|
||||
*/
|
||||
|
||||
lib_stdinstream(&stdinstream, instream);
|
||||
lib_memsostream(&memoutstream, (FAR char *)baseaddr,
|
||||
(int)(endpaddr - baseaddr));
|
||||
|
||||
/* And do the deed */
|
||||
|
||||
return hex2bin(&stdinstream.public, &memoutstream.public,
|
||||
(uint32_t)baseaddr, (uint32_t)endpaddr,
|
||||
(enum hex2bin_swap_e)swap);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_LIB_HEX2BIN */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/hex2bin/hex2mem.c
|
||||
*
|
||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <hex2bin.h>
|
||||
|
||||
#include <nuttx/streams.h>
|
||||
|
||||
#ifdef CONFIG_LIB_HEX2BIN
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hex2mem
|
||||
*
|
||||
* Description:
|
||||
* Read the Intel HEX ASCII data provided on the file descriptor 'fd' and
|
||||
* write the binary to memory.
|
||||
*
|
||||
* If, for example, fd is zero (stdin), then the HEX ASCII data would be
|
||||
* taken from the console and written to memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor from which Intel HEX data will be
|
||||
* received.
|
||||
* baseaddr - The base address of the memory region stream.
|
||||
* endpaddr - The end address (plus 1) of the memory region.
|
||||
* swap - Controls byte ordering. See enum hex2bin_swap_e for
|
||||
* description of the values.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int hex2mem(int fd, uint32_t baseaddr, uint32_t endpaddr,
|
||||
enum hex2bin_swap_e swap)
|
||||
{
|
||||
struct lib_rawinstream_s rawinstream;
|
||||
struct lib_memsostream_s memoutstream;
|
||||
|
||||
/* Check memory addresses */
|
||||
|
||||
DEBUGASSERT(fd >= 0 && endpaddr > baseaddr);
|
||||
|
||||
/* Wrap the file descriptor as raw stream; wrap the memory as a memory
|
||||
* stream.
|
||||
*/
|
||||
|
||||
lib_rawinstream(&rawinstream, fd);
|
||||
lib_memsostream(&memoutstream, (FAR char *)baseaddr,
|
||||
(int)(endpaddr - baseaddr));
|
||||
|
||||
/* And do the deed */
|
||||
|
||||
return hex2bin(&rawinstream.public, &memoutstream.public,
|
||||
(uint32_t)baseaddr, (uint32_t)endpaddr,
|
||||
(enum hex2bin_swap_e)swap);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_LIB_HEX2BIN */
|
||||
@@ -0,0 +1,43 @@
|
||||
############################################################################
|
||||
# libs/libc/inttypes/Make.defs
|
||||
#
|
||||
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Add the inttypes C files to the build
|
||||
|
||||
CSRCS += lib_imaxabs.c lib_strtoimax.c lib_strtoumax.c
|
||||
|
||||
# Add the inttypes directory to the build
|
||||
|
||||
DEPPATH += --dep-path inttypes
|
||||
VPATH += :inttypes
|
||||
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/inttypes/lib_imaxabs.c
|
||||
*
|
||||
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
intmax_t imaxabs(intmax_t j)
|
||||
{
|
||||
if (j < 0)
|
||||
{
|
||||
j = -j;
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/inttypes/lib_strtoimax.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
/* Current implementation depends on strtoull() and, hence, is only
|
||||
* available if long long types are supported.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: strtoimax
|
||||
*
|
||||
* Description:
|
||||
* The strtoimax() function converts the initial part of the string in
|
||||
* nptr to a intmax_t integer value according to the given base, which
|
||||
* must be between 2 and 36 inclusive, or be the special value 0.
|
||||
*
|
||||
* Returned Value:
|
||||
* - The converted value, if the base and number are valid
|
||||
* - 0 if an error occurs, and set errno to:
|
||||
* * EINVAL if base < 2 or base > 36
|
||||
* - INTMAX_MIN or INTMAX_MAX, of correct sign, if an overflow occurs,
|
||||
* and set errno to:
|
||||
* * ERANGE if the number cannot be represented using intmax_t
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
intmax_t strtoimax(FAR const char *nptr, FAR char **endptr, int base)
|
||||
{
|
||||
uintmax_t accum = 0;
|
||||
bool negate = false;
|
||||
|
||||
if (nptr)
|
||||
{
|
||||
/* Skip leading spaces */
|
||||
|
||||
lib_skipspace(&nptr);
|
||||
|
||||
/* Check for leading + or - */
|
||||
|
||||
if (*nptr == '-')
|
||||
{
|
||||
negate = true;
|
||||
nptr++;
|
||||
}
|
||||
else if (*nptr == '+')
|
||||
{
|
||||
nptr++;
|
||||
}
|
||||
|
||||
/* Get the unsigned value */
|
||||
|
||||
accum = strtoull(nptr, endptr, base);
|
||||
|
||||
/* Correct the sign of the result and check for overflow */
|
||||
|
||||
if (negate)
|
||||
{
|
||||
const uintmax_t limit = ((uintmax_t)-(INTMAX_MIN + 1)) + 1;
|
||||
|
||||
if (accum > limit)
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
return INTMAX_MIN;
|
||||
}
|
||||
|
||||
return (accum == limit) ? INTMAX_MIN : -(intmax_t)accum;
|
||||
}
|
||||
|
||||
if (accum > INTMAX_MAX)
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
return INTMAX_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
return (intmax_t)accum;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_HAVE_LONG_LONG */
|
||||
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
* /libs/libc/inttypes/lib_strtoumax.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: strtoumax
|
||||
*
|
||||
* Description:
|
||||
* The strtoumax() function converts the initial part of the string in
|
||||
* nptr to a long unsigned integer value according to the given base, which
|
||||
* must be between 2 and 36 inclusive, or be the special value 0.
|
||||
*
|
||||
* Returned Value:
|
||||
* - The converted value, if the base and number are valid
|
||||
* - 0 if an error occurs, and set errno to:
|
||||
* * EINVAL if base < 2 or base > 36
|
||||
* - UINTMAX_MAX if an overflow occurs, and set errno to:
|
||||
* * ERANGE if the number cannot be represented using uintmax_t
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uintmax_t strtoumax(FAR const char *nptr, FAR char **endptr, int base)
|
||||
{
|
||||
uintmax_t accum = 0;
|
||||
uintmax_t prev;
|
||||
int value;
|
||||
|
||||
if (nptr)
|
||||
{
|
||||
/* Skip leading spaces */
|
||||
|
||||
lib_skipspace(&nptr);
|
||||
|
||||
/* Check for unspecified base */
|
||||
|
||||
base = lib_checkbase(base, &nptr);
|
||||
|
||||
if (base < 0)
|
||||
{
|
||||
set_errno(EINVAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Accumulate each "digit" */
|
||||
|
||||
while (lib_isbasedigit(*nptr, base, &value))
|
||||
{
|
||||
prev = accum;
|
||||
accum = accum*base + value;
|
||||
nptr++;
|
||||
|
||||
/* Check for overflow */
|
||||
|
||||
if (accum < prev)
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
accum = UINTMAX_MAX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the final pointer to the unused value */
|
||||
|
||||
if (endptr)
|
||||
{
|
||||
*endptr = (char *)nptr;
|
||||
}
|
||||
}
|
||||
|
||||
return accum;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
||||
@@ -0,0 +1,48 @@
|
||||
############################################################################
|
||||
# libs/libc/kbin/Makefile
|
||||
#
|
||||
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
all:
|
||||
.PHONY: clean distclean
|
||||
|
||||
# Clean Targets:
|
||||
|
||||
clean:
|
||||
$(call CLEAN)
|
||||
|
||||
# Deep clean -- removes all traces of the configuration
|
||||
|
||||
distclean: clean
|
||||
@@ -0,0 +1,231 @@
|
||||
"_inet_ntoa","arpa/inet.h","defined(CONFIG_NET_IPv4) && !defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","in_addr_t"
|
||||
"abort","stdlib.h","","void"
|
||||
"abs","stdlib.h","","int","int"
|
||||
"aio_error","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *"
|
||||
"aio_return","aio.h","defined(CONFIG_FS_AIO)","ssize_t","FAR struct aiocb *"
|
||||
"aio_suspend","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR const struct timespec *"
|
||||
"asprintf","stdio.h","","int","FAR char **","FAR const char *","..."
|
||||
"vasprintf","stdio.h","","int","FAR char **","FAR const char *","va_list"
|
||||
"b16atan2","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t"
|
||||
"b16cos","fixedmath.h","","b16_t","b16_t"
|
||||
"b16divb16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t"
|
||||
"b16mulb16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t"
|
||||
"b16sin","fixedmath.h","","b16_t","b16_t"
|
||||
"b16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t"
|
||||
"basename","libgen.h","","FAR char","FAR char *"
|
||||
"cfgetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *"
|
||||
"cfsetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t"
|
||||
"chdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
|
||||
"clock","time.h","","clock_t"
|
||||
"crc32","crc32.h","","uint32_t","FAR const uint8_t *","size_t"
|
||||
"crc32part","crc32.h","","uint32_t","FAR const uint8_t *","size_t","uint32_t"
|
||||
"dirname","libgen.h","","FAR char","FAR char *"
|
||||
"dq_addafter","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_addbefore","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_addfirst","queue.h","","void","FAR dq_entry_t *","dq_queue_t *"
|
||||
"dq_addlast","queue.h","","void","FAR dq_entry_t *","dq_queue_t *"
|
||||
"dq_rem","queue.h","","void","FAR dq_entry_t *","dq_queue_t *"
|
||||
"dq_remfirst","queue.h","","FAR dq_entry_t","dq_queue_t *"
|
||||
"dq_remlast","queue.h","","FAR dq_entry_t","dq_queue_t *"
|
||||
"_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","int","FAR const char *","..."
|
||||
"ether_ntoa","netinet/ether.h","","FAR char","FAR const struct ether_addr *"
|
||||
"fclose","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *"
|
||||
"fdopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","int","FAR const char *"
|
||||
"fflush","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *"
|
||||
"ffs","strings.h","","int","int"
|
||||
"fgetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *"
|
||||
"fgetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *"
|
||||
"fgets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *","int","FAR FILE *"
|
||||
"fileno","stdio.h","","int","FAR FILE *"
|
||||
"fopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","FAR const char *","FAR const char *"
|
||||
"fprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR const char *","..."
|
||||
"fputc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int c","FAR FILE *"
|
||||
"fputs","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","FAR FILE *"
|
||||
"fread","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR void *","size_t","size_t","FAR FILE *"
|
||||
"fseek","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","long int","int"
|
||||
"fsetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *"
|
||||
"ftell","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","long","FAR FILE *"
|
||||
"fwrite","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR const void *","size_t","size_t","FAR FILE *"
|
||||
"getcwd","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","FAR char","FAR char *","size_t"
|
||||
"gethostname","unistd.h","defined(CONFIG_LIBC_NETDB)","int","FAR char*","size_t"
|
||||
"getopt","unistd.h","","int","int","FAR char *const[]","FAR const char *"
|
||||
"getoptargp","unistd.h","","FAR char *"
|
||||
"getoptindp","unistd.h","","int"
|
||||
"getoptoptp","unistd.h","","int"
|
||||
"gets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *"
|
||||
"gmtime","time.h","","struct tm","FAR const time_t *"
|
||||
"gmtime_r","time.h","","FAR struct tm","FAR const time_t *","FAR struct tm *"
|
||||
"htonl","arpa/inet.h","","uint32_t","uint32_t"
|
||||
"htons","arpa/inet.h","","uint16_t","uint16_t"
|
||||
"imaxabs","inttypes.h","","intmax_t","intmax_t"
|
||||
"inet_addr","arpa/inet.h","","in_addr_t","FAR const char "
|
||||
"inet_ntoa","arpa/inet.h","defined(CONFIG_NET_IPv4) && defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","struct in_addr"
|
||||
"inet_ntop","arpa/inet.h","","FAR const char","int","FAR const void *","FAR char *","socklen_t"
|
||||
"inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *"
|
||||
"iswalnum","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswalpha","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswblank","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswcntrl","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswctype","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t","wctype_t"
|
||||
"iswdigit","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswgraph","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswlower","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswprint","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswpunct","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswspace","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswupper","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"iswxdigit","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
|
||||
"labs","stdlib.h","","long int","long int"
|
||||
"lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int"
|
||||
"lio_listio","aio.h","defined(CONFIG_FS_AIO)","int","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR struct sigevent *"
|
||||
"llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int"
|
||||
"match","nuttx/lib/regex.h","","int","FAR const char *","FAR const char *"
|
||||
"mbrtowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","FAR const char *","size_t","mbstate_t *"
|
||||
"mbsnrtowcs","wchar.h","","size_t","FAR wchar_t *","FAR const char **","size_t","size_t","mbstate_t *"
|
||||
"mbtowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","wchar_t *","FAR const wchar_t *","size_t"
|
||||
"memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t"
|
||||
"memchr","string.h","","FAR void","FAR const void *","int c","size_t"
|
||||
"memcmp","string.h","","int","FAR const void *","FAR const void *","size_t"
|
||||
"memcpy","string.h","","FAR void","FAR void *","FAR const void *","size_t"
|
||||
"memmove","string.h","","FAR void","FAR void *","FAR const void *","size_t"
|
||||
"memset","string.h","","FAR void","FAR void *","int c","size_t"
|
||||
"mkfifo","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR const char*","mode_t"
|
||||
"mktime","time.h","","time_t","FAR const struct tm *"
|
||||
"ntohl","arpa/inet.h","","uint32_t","uint32_t"
|
||||
"ntohs","arpa/inet.h","","uint16_t","uint16_t"
|
||||
"perror","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","void","FAR const char *"
|
||||
"pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*"
|
||||
"printf","stdio.h","","int","FAR const char *","..."
|
||||
"pthread_attr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *"
|
||||
"pthread_attr_getinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR int *"
|
||||
"pthread_attr_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR struct sched_param *"
|
||||
"pthread_attr_getschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int *"
|
||||
"pthread_attr_getstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR long *"
|
||||
"pthread_attr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *"
|
||||
"pthread_attr_setinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int"
|
||||
"pthread_attr_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR const struct sched_param *"
|
||||
"pthread_attr_setschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int"
|
||||
"pthread_attr_setstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","long"
|
||||
"pthread_barrierattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *"
|
||||
"pthread_barrierattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_barrierattr_t *","FAR int *"
|
||||
"pthread_barrierattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *"
|
||||
"pthread_barrierattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *","int"
|
||||
"pthread_barrier_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrier_t*"
|
||||
"pthread_barrier_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrier_t*","FAR const pthread_barrierattr_t*","unsigned int"
|
||||
"pthread_barrier_wait","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrier_t*"
|
||||
"pthread_condattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *"
|
||||
"pthread_condattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *"
|
||||
"pthread_cond_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t*"
|
||||
"pthread_cond_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t*","FAR const pthread_condattr_t*"
|
||||
"pthread_mutexattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *"
|
||||
"pthread_mutexattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","FAR int *"
|
||||
"pthread_mutexattr_gettype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_PTHREAD_MUTEX_TYPES)","int","FAR const pthread_mutexattr_t *","int *"
|
||||
"pthread_mutexattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *"
|
||||
"pthread_mutexattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","int "
|
||||
"pthread_mutexattr_settype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_PTHREAD_MUTEX_TYPES)","int","pthread_mutexattr_t *","int"
|
||||
"pthread_once","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_once_t*","CODE void (*)(void)"
|
||||
"pthread_yield","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void"
|
||||
"puts","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *"
|
||||
"qsort","stdlib.h","","void","void *","size_t","size_t","int(*)(const void *","FAR const void *)"
|
||||
"rand","stdlib.h","","int"
|
||||
"readdir_r","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR *","FAR struct dirent *","FAR struct dirent **"
|
||||
"sched_get_priority_max","sched.h","","int","int"
|
||||
"sched_get_priority_min","sched.h","","int","int"
|
||||
"sem_getvalue","semaphore.h","","int","FAR sem_t *","FAR int *"
|
||||
"sem_init","semaphore.h","","int","FAR sem_t *","int","unsigned int"
|
||||
"sendfile","sys/sendfile.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","int","off_t","size_t"
|
||||
"setlocale","local.h","","FAR char *s","int","FAR const char *s"
|
||||
"setlogmask","syslog.h","","int","int"
|
||||
"sigaddset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int"
|
||||
"sigdelset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int"
|
||||
"sigemptyset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *"
|
||||
"sigfillset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *"
|
||||
"sigismember","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t *","int"
|
||||
"sleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","unsigned int","unsigned int"
|
||||
"snprintf","stdio.h","","int","FAR char *","size_t","FAR const char *","..."
|
||||
"sprintf","stdio.h","","int","FAR char *","FAR const char *","..."
|
||||
"sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_addfirst","queue.h","","void","FAR sq_entry_t *","sq_queue_t *"
|
||||
"sq_addlast","queue.h","","void","FAR sq_entry_t *","sq_queue_t *"
|
||||
"sq_rem","queue.h","","void","FAR sq_entry_t *","sq_queue_t *"
|
||||
"sq_remafter","queue.h","","FAR sq_entry_t","FAR sq_entry_t *","sq_queue_t *"
|
||||
"sq_remfirst","queue.h","","FAR sq_entry_t","sq_queue_t *"
|
||||
"sq_remlast","queue.h","","FAR sq_entry_t","sq_queue_t *"
|
||||
"srand","stdlib.h","","void","unsigned int"
|
||||
"sscanf","stdio.h","","int","FAR const char *","FAR const char *","..."
|
||||
"strcasecmp","strings.h","","int","FAR const char *","FAR const char *"
|
||||
"strcasestr","string.h","","FAR char","FAR const char *","FAR const char *"
|
||||
"strcat","string.h","","FAR char","FAR char *","FAR const char *"
|
||||
"strchr","string.h","","FAR char","FAR const char *","int"
|
||||
"strcmp","string.h","","int","FAR const char *","FAR const char *"
|
||||
"strcoll","string.h","CONFIG_LIBC_LOCALE","int","FAR const char *","FAR const char *"
|
||||
"strcpy","string.h","","FAR char *","FAR char *","FAR const char *"
|
||||
"strcspn","string.h","","size_t","FAR const char *","FAR const char *"
|
||||
"strdup","string.h","","FAR char","FAR const char *"
|
||||
"strerror","string.h","","FAR const char","int"
|
||||
"strerror_r","string.h","","int","int","FAR char *","size_t"
|
||||
"strftime","time.h","","size_t","FAR char *","size_t","FAR const char *","FAR const struct tm *"
|
||||
"strlen","string.h","","size_t","FAR const char *"
|
||||
"strncasecmp","strings.h","","int","FAR const char *","FAR const char *","size_t"
|
||||
"strncat","string.h","","FAR char","FAR char *","FAR const char *","size_t"
|
||||
"strncmp","string.h","","int","FAR const char *","FAR const char *","size_t"
|
||||
"strncpy","string.h","","FAR char","FAR char *","FAR const char *","size_t"
|
||||
"strndup","string.h","","FAR char","FAR const char *","size_t"
|
||||
"strnlen","string.h","","size_t","FAR const char *","size_t"
|
||||
"strpbrk","string.h","","FAR char","FAR const char *","FAR const char *"
|
||||
"strrchr","string.h","","FAR char","FAR const char *","int"
|
||||
"strspn","string.h","","size_t","FAR const char *","FAR const char *"
|
||||
"strstr","string.h","","FAR char","FAR const char *","FAR const char *"
|
||||
"strtod","stdlib.h","","double_t","FAR const char *str","FAR char **endptr"
|
||||
"strtok","string.h","","FAR char","FAR char *","FAR const char *"
|
||||
"strtok_r","string.h","","FAR char","FAR char *","FAR const char *","FAR char **"
|
||||
"strtol","string.h","","long","FAR const char *","FAR char **","int"
|
||||
"strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","FAR const char *nptr","FAR char **endptr","int base"
|
||||
"strtoul","stdlib.h","","unsigned long","FAR const char *","FAR char **","int"
|
||||
"strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","FAR const char *","FAR char **","int"
|
||||
"strxfrm","string.h","defined(CONFIG_LIBC_LOCALE)","size_t","FAR char *","FAR const char *","size_t"
|
||||
"swab","unistd.h","","void","int","FAR const void *","FAR void *","ssize_t"
|
||||
"swprintf","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR wchar_t *","size_t","FAR const wchar_t *","..."
|
||||
"syslog","syslog.h","","int","int","FAR const char *","..."
|
||||
"tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int"
|
||||
"tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *"
|
||||
"tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *"
|
||||
"telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR *"
|
||||
"time","time.h","","time_t","time_t *"
|
||||
"towlower","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","wint_t"
|
||||
"towupper","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","wint_t"
|
||||
"ub16divub16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t","ub16_t"
|
||||
"ub16mulub16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t","ub16_t"
|
||||
"ub16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t"
|
||||
"ungetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int","FAR FILE *"
|
||||
"usleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","int","int","FAR FILE *"
|
||||
"_info","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO)","int","FAR const char *","..."
|
||||
"vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR const char *","va_list"
|
||||
"vprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","va_list"
|
||||
"vsnprintf","stdio.h","","int","FAR char *","size_t","FAR const char *","va_list"
|
||||
"vsprintf","stdio.h","","int","FAR char *","FAR const char *","va_list"
|
||||
"vsscanf","stdio.h","","int","FAR char *","FAR const char *","va_list"
|
||||
"vsyslog","syslog.h","","int","int","FAR const char *","va_list"
|
||||
"wcrtomb","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","wchar_t","mbstate_t *"
|
||||
"wcscmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *"
|
||||
"wcscoll","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *"
|
||||
"wcsftime","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","size_t","FAR const wchar_t *","FAR const struct tm *"
|
||||
"wcslcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *","FAR const wchar_t *","size_t"
|
||||
"wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *"
|
||||
"wcsnrtombs","wchar.h","","size_t","FAR char *","FAR const wchar_t **","size_t","size_t","mbstate_t *"
|
||||
"wcstod","wchar.h","defined(CONFIG_LIBC_WCHAR)","","FAR const wchar_t *","FAR wchar_t **"
|
||||
"wcstof","wchar.h","defined(CONFIG_LIBC_WCHAR)","float","FAR const wchar_t *","FAR wchar_t **"
|
||||
"wcstol","wchar.h","defined(CONFIG_LIBC_WCHAR)","long int","FAR const wchar_t *","FAR wchar_t **","int"
|
||||
"wcstold","wchar.h","defined(CONFIG_LIBC_WCHAR)","long double","FAR const wchar_t *","FAR wchar_t **"
|
||||
"wcstoll","wchar.h","defined(CONFIG_LIBC_WCHAR)","long long int","FAR const wchar_t *","FAR wchar_t **","int"
|
||||
"wcstoul","wchar.h","defined(CONFIG_LIBC_WCHAR)","unsigned long int","FAR const wchar_t *","FAR wchar_t **","int"
|
||||
"wcsxfrm","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","FAR const wchar_t *","size_t"
|
||||
"wctob","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","wchar_t"
|
||||
"wctomb","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR char *","wchar_t"
|
||||
"wctype","wctype.h","defined(CONFIG_LIBC_WCHAR)","wctype_t","FAR const char *"
|
||||
"wmemchr","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchar_t *","wchar_t *","wchar_t","size_t"
|
||||
"wmemcmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","wchar_t *","wchar_t *","size_t"
|
||||
"wmemcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *","wchar_t *","wchar_t *","size_t"
|
||||
"wmemmove","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *","wchar_t *","wchar_t *","size_t"
|
||||
"wmemset","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *","wchar_t *","wchar_t","size_t"
|
||||
"_warn","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN)","int","FAR const char *","..."
|
||||
|
@@ -0,0 +1,238 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/libc.h
|
||||
*
|
||||
* Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __LIBC_LIBC_H
|
||||
#define __LIBC_LIBC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/streams.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* This configuration directory is used in environment variable processing
|
||||
* when we need to reference the user's home directory. There are no user
|
||||
* directories in NuttX so, by default, this always refers to the root
|
||||
* directory.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_LIB_HOMEDIR
|
||||
# define CONFIG_LIB_HOMEDIR "/"
|
||||
#endif
|
||||
|
||||
/* If C std I/O buffering is not supported, then we don't need its semaphore
|
||||
* protection.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
# define lib_sem_initialize(s)
|
||||
# define lib_take_semaphore(s)
|
||||
# define lib_give_semaphore(s)
|
||||
#endif
|
||||
|
||||
/* The NuttX C library an be build in two modes: (1) as a standard, C-library
|
||||
* that can be used by normal, user-space applications, or (2) as a special,
|
||||
* kernel-mode C-library only used within the OS. If NuttX is not being
|
||||
* built as separated kernel- and user-space modules, then only the first
|
||||
* mode is supported.
|
||||
*/
|
||||
|
||||
#if (defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \
|
||||
defined(CONFIG_BUILD_KERNEL)
|
||||
# include <nuttx/kmalloc.h>
|
||||
|
||||
/* Domain-specific allocations */
|
||||
|
||||
# define lib_malloc(s) kmm_malloc(s)
|
||||
# define lib_zalloc(s) kmm_zalloc(s)
|
||||
# define lib_realloc(p,s) kmm_realloc(p,s)
|
||||
# define lib_memalign(p,s) kmm_memalign(p,s)
|
||||
# define lib_free(p) kmm_free(p)
|
||||
|
||||
/* User-accessible allocations */
|
||||
|
||||
# define lib_umalloc(s) kumm_malloc(s)
|
||||
# define lib_uzalloc(s) kumm_zalloc(s)
|
||||
# define lib_urealloc(p,s) kumm_realloc(p,s)
|
||||
# define lib_ufree(p) kumm_free(p)
|
||||
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
|
||||
/* Domain-specific allocations */
|
||||
|
||||
# define lib_malloc(s) malloc(s)
|
||||
# define lib_zalloc(s) zalloc(s)
|
||||
# define lib_realloc(p,s) realloc(p,s)
|
||||
# define lib_free(p) free(p)
|
||||
|
||||
/* User-accessible allocations */
|
||||
|
||||
# define lib_umalloc(s) malloc(s)
|
||||
# define lib_uzalloc(s) zalloc(s)
|
||||
# define lib_urealloc(p,s) realloc(p,s)
|
||||
# define lib_ufree(p) free(p)
|
||||
|
||||
#endif
|
||||
|
||||
#define LIB_BUFLEN_UNKNOWN INT_MAX
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Defined in lib_streamsem.c */
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
void stream_semtake(FAR struct streamlist *list);
|
||||
void stream_semgive(FAR struct streamlist *list);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_dtoa.c */
|
||||
|
||||
#ifdef CONFIG_LIBC_FLOATINGPOINT
|
||||
char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign,
|
||||
char **rve);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_fopen.c */
|
||||
|
||||
int lib_mode2oflags(FAR const char *mode);
|
||||
|
||||
/* Defined in lib_libfwrite.c */
|
||||
|
||||
ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream);
|
||||
|
||||
/* Defined in lib_libfread.c */
|
||||
|
||||
ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
|
||||
|
||||
/* Defined in lib_libfgets.c */
|
||||
|
||||
FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream,
|
||||
bool keepnl, bool consume);
|
||||
|
||||
/* Defined in lib_libfflush.c */
|
||||
|
||||
ssize_t lib_fflush(FAR FILE *stream, bool bforce);
|
||||
|
||||
/* Defined in lib_rdflush.c */
|
||||
|
||||
int lib_rdflush(FAR FILE *stream);
|
||||
|
||||
/* Defined in lib_wrflush.c */
|
||||
|
||||
int lib_wrflush(FAR FILE *stream);
|
||||
|
||||
/* Defined in lib_sem.c */
|
||||
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
void lib_sem_initialize(FAR struct file_struct *stream);
|
||||
void lib_take_semaphore(FAR struct file_struct *stream);
|
||||
void lib_give_semaphore(FAR struct file_struct *stream);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_libgetbase.c */
|
||||
|
||||
int lib_getbase(const char *nptr, const char **endptr);
|
||||
|
||||
/* Defined in lib_skipspace.c */
|
||||
|
||||
void lib_skipspace(const char **pptr);
|
||||
|
||||
/* Defined in lib_isbasedigit.c */
|
||||
|
||||
bool lib_isbasedigit(int ch, int base, int *value);
|
||||
|
||||
/* Defined in lib_checkbase.c */
|
||||
|
||||
int lib_checkbase(int base, const char **pptr);
|
||||
|
||||
/* Defined in lib_expi.c */
|
||||
|
||||
#ifdef CONFIG_LIBM
|
||||
float lib_expif(size_t n);
|
||||
double lib_expi(size_t n);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_libsqrtapprox.c */
|
||||
|
||||
#ifdef CONFIG_LIBM
|
||||
float lib_sqrtapprox(float x);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_parsehostfile.c */
|
||||
|
||||
#ifdef CONFIG_NETDB_HOSTFILE
|
||||
struct hostent;
|
||||
ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
|
||||
FAR char *buf, size_t buflen);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __LIBC_LIBC_H */
|
||||
@@ -0,0 +1,43 @@
|
||||
############################################################################
|
||||
# libs/libc/libgen/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Add the libgen C files to the build
|
||||
|
||||
CSRCS += lib_basename.c lib_dirname.c
|
||||
|
||||
# Add the libgen directory to the build
|
||||
|
||||
DEPPATH += --dep-path libgen
|
||||
VPATH += :libgen
|
||||
@@ -0,0 +1,131 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/libgen/lib_basename.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static char g_retchar[2];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: basename
|
||||
*
|
||||
* Description:
|
||||
* basename() extracts the filename component from a null-terminated
|
||||
* pathname string. In the usual case, basename() returns the component
|
||||
* following the final '/'. Trailing '/' characters are not counted as
|
||||
* part of the pathname.
|
||||
*
|
||||
* If path does not contain a slash, basename() returns a copy of path.
|
||||
* If path is the string "/", then basename() returns the string "/". If
|
||||
* path is a NULL pointer or points to an empty string, then basename()
|
||||
* return the string ".".
|
||||
*
|
||||
* basename() may modify the contents of path, so copies should be passed.
|
||||
* basename() may return pointers to statically allocated memory which may
|
||||
* be overwritten by subsequent calls.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path The null-terminated string referring to the path to be decomposed
|
||||
*
|
||||
* Returned Value:
|
||||
* On success the filename component of the path is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *basename(FAR char *path)
|
||||
{
|
||||
char *p;
|
||||
int len;
|
||||
int ch;
|
||||
|
||||
/* Handle some corner cases */
|
||||
|
||||
if (!path || *path == '\0')
|
||||
{
|
||||
ch = '.';
|
||||
goto out_retchar;
|
||||
}
|
||||
|
||||
/* Check for trailing slash characters */
|
||||
|
||||
len = strlen(path);
|
||||
while (path[len-1] == '/')
|
||||
{
|
||||
/* Remove trailing '/' UNLESS this would make a zero length string */
|
||||
if (len > 1)
|
||||
{
|
||||
path[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = '/';
|
||||
goto out_retchar;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the address of the last '/' which is not at the end of the path and,
|
||||
* therefor, must be just before the beginning of the filename component.
|
||||
*/
|
||||
|
||||
p = strrchr(path, '/');
|
||||
if (p)
|
||||
{
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
/* There is no '/' in the path */
|
||||
|
||||
return path;
|
||||
|
||||
out_retchar:
|
||||
g_retchar[0] = ch;
|
||||
g_retchar[1] = '\0';
|
||||
return g_retchar;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/libgen/lib_dirname.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static char g_retchar[2];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dirname
|
||||
*
|
||||
* Description:
|
||||
* dirname() extracts the directory component from a null-terminated
|
||||
* pathname string. In the usual case, dirname() returns the string up
|
||||
* to, but not including, the final '/'. Trailing '/' characters are not
|
||||
* counted as part of the pathname.
|
||||
*
|
||||
* If path does not contain a slash, dirname() returns the string ".". If
|
||||
* path is the string "/", then dirname() returns the string "/". If path
|
||||
* is a NULL pointer or points to an empty string, then dirname() returns
|
||||
* the string ".".
|
||||
*
|
||||
* dirname() may modify the contents of path, so copies should be passed.
|
||||
* dirname() may return pointers to statically allocated memory which may
|
||||
* be overwritten by subsequent calls.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path The null-terminated string referring to the path to be decomposed
|
||||
*
|
||||
* Returned Value:
|
||||
* On success the directory component of the path is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *dirname(FAR char *path)
|
||||
{
|
||||
char *p;
|
||||
int len;
|
||||
int ch;
|
||||
|
||||
/* Handle some corner cases */
|
||||
|
||||
if (!path || *path == '\0')
|
||||
{
|
||||
ch = '.';
|
||||
goto out_retchar;
|
||||
}
|
||||
|
||||
/* Check for trailing slash characters */
|
||||
|
||||
len = strlen(path);
|
||||
while (path[len-1] == '/')
|
||||
{
|
||||
/* Remove trailing '/' UNLESS this would make a zero length string */
|
||||
if (len > 1)
|
||||
{
|
||||
path[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = '/';
|
||||
goto out_retchar;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the address of the last '/' which is not at the end of the path and,
|
||||
* therefor, must be the end of the directory component.
|
||||
*/
|
||||
|
||||
p = strrchr(path, '/');
|
||||
if (p)
|
||||
{
|
||||
/* Handle the case where the only '/' in the string is the at the beginning
|
||||
* of the path.
|
||||
*/
|
||||
|
||||
if (p == path)
|
||||
{
|
||||
ch = '/';
|
||||
goto out_retchar;
|
||||
}
|
||||
|
||||
/* No, the directory component is the substring before the '/'. */
|
||||
|
||||
*p = '\0';
|
||||
return path;
|
||||
}
|
||||
|
||||
/* There is no '/' in the path */
|
||||
|
||||
ch = '.';
|
||||
|
||||
out_retchar:
|
||||
g_retchar[0] = ch;
|
||||
g_retchar[1] = '\0';
|
||||
return g_retchar;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
#menu "Locale Support"
|
||||
|
||||
config LIBC_LOCALE
|
||||
bool "Enable I18N (LOCALE) support"
|
||||
default n
|
||||
---help---
|
||||
By default, i18n (locale) support is disabled.
|
||||
|
||||
#endmenu # Locale Support
|
||||
@@ -0,0 +1,47 @@
|
||||
############################################################################
|
||||
# libs/libc/locale/Make.defs
|
||||
#
|
||||
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_LIBC_LOCALE),y)
|
||||
|
||||
# Add the locale files to the build
|
||||
|
||||
CSRCS += lib_setlocale.c lib_localeconv.c
|
||||
|
||||
# Add the locale directory to the build
|
||||
|
||||
DEPPATH += --dep-path locale
|
||||
VPATH += :locale
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/locale/lib_localeconv.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <locale.h>
|
||||
|
||||
#ifdef CONFIG_LIBC_LOCALE
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: localeconv
|
||||
*
|
||||
* Description:
|
||||
* locales are not supported by NuttX
|
||||
*
|
||||
* Input Parameters:
|
||||
* category and locale - Select the appropriate piece of the program's
|
||||
* locale.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lconv *localeconv(void)
|
||||
{
|
||||
/* NULL indicates the locale was not changed */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/locale/lib_setlocale.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#ifdef CONFIG_LIBC_LOCALE
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: setlocale
|
||||
*
|
||||
* Description:
|
||||
* locales are not supported by NuttX
|
||||
*
|
||||
* Input Parameters:
|
||||
* category and locale - Select the appropriate piece of the program's
|
||||
* locale.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *setlocale(int category, FAR const char *locale)
|
||||
{
|
||||
return ((strcmp(locale, "POSIX") == 0 || strcmp(locale, "C") == 0 ||
|
||||
strcmp(locale, "") == 0) ? "C" : NULL);
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user