support musl libc on nuttx

This commit is contained in:
wgzAIIT 2022-08-04 15:34:36 +08:00
commit ad0132f739
992 changed files with 114309 additions and 0 deletions

View File

@ -2051,6 +2051,18 @@ source "binfmt/Kconfig"
endmenu endmenu
menu "Library Routines" menu "Library Routines"
choice
prompt "Selcet C library,built-in libc or musl libc."
default NUTTX_BUILT_IN_LIBC
config NUTTX_BUILT_IN_LIBC
bool "nuttx built-in libc"
config MUSL_LIBC
bool "musl libc"
endchoice
source "libs/libc/Kconfig" source "libs/libc/Kconfig"
source "libs/libxx/Kconfig" source "libs/libxx/Kconfig"
source "libs/libdsp/Kconfig" source "libs/libdsp/Kconfig"

View File

@ -0,0 +1,614 @@
/****************************************************************************
* include/nuttx/lib/math.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_LIB_MATH_H
#define __INCLUDE_NUTTX_LIB_MATH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/* If CONFIG_ARCH_MATH_H is defined, then the top-level Makefile will copy
* this header file to include/math.h where it will become the system math.h
* header file. In this case, the architecture specific code must provide
* an arch/<architecture>/include/math.h file which will be included below:
*/
#ifdef CONFIG_ARCH_MATH_H
# include <arch/math.h>
/* If CONFIG_LIBM is enabled, then the math library at lib/math will be
* built. This library was taken from the math library developed for the
* Rhombus OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus).
* The port or the Rhombus math library was contributed by Darcy Gong.
*/
#elif defined(CONFIG_LIBM)
/****************************************************************************
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* General Constants ********************************************************/
#define INFINITY (1.0/0.0)
#define NAN (0.0/0.0)
#define HUGE_VAL INFINITY
#define INFINITY_F (1.0F/0.0F)
#define NAN_F (0.0F/0.0F)
#define isnan(x) ((x) != (x))
#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY))
#define isfinite(x) (!(isinf(x) || isnan(x)))
#define isinf_f(x) (((x) == INFINITY_F) || ((x) == -INFINITY_F))
/* Exponential and Logarithmic constants ************************************/
#define M_E 2.7182818284590452353602874713526625
#define M_SQRT2 1.4142135623730950488016887242096981
#define M_SQRT1_2 0.7071067811865475244008443621048490
#define M_LOG2E 1.4426950408889634073599246810018921
#define M_LOG10E 0.4342944819032518276511289189166051
#define M_LN2 0.6931471805599453094172321214581765
#define M_LN10 2.3025850929940456840179914546843642
/* Trigonometric Constants **************************************************/
#define M_PI 3.1415926535897932384626433832795029
#define M_PI_2 1.5707963267948966192313216916397514
#define M_PI_4 0.7853981633974483096156608458198757
#define M_1_PI 0.3183098861837906715377675267450287
#define M_2_PI 0.6366197723675813430755350534900574
#define M_2_SQRTPI 1.1283791670955125738961589031215452
#define M_PI_F ((float)M_PI)
#define M_PI_2_F ((float)M_PI_2)
/****************************************************************************
* Type Declarations
****************************************************************************/
/* Floating point types */
typedef float float_t;
#ifndef CONFIG_HAVE_DOUBLE
typedef float double_t;
#else
typedef double double_t;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#if defined(__cplusplus)
extern "C"
{
#endif
/* General Functions ********************************************************/
float ceilf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double ceil (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double ceill (long double x);
#endif
float floorf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double floor (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double floorl(long double x);
#endif
float roundf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double round (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double roundl(long double x);
#endif
long int lroundf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long int lround(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long int lroundl(long double x);
#endif
#ifdef CONFIG_HAVE_LONG_LONG
long long int llroundf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long long int llround (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long long int llroundl(long double x);
#endif
#endif
float rintf(float x); /* Not implemented */
#ifdef CONFIG_HAVE_DOUBLE
double rint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double rintl(long double x); /* Not implemented */
#endif
long int lrintf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long int lrint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long int lrintl(long double x);
#endif
#ifdef CONFIG_HAVE_LONG_LONG
long long int llrintf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long long int llrint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long long int llrintl(long double x);
#endif
#endif
float fabsf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double fabs (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fabsl (long double x);
#endif
float modff (float x, float *iptr);
#ifdef CONFIG_HAVE_DOUBLE
double modf (double x, double *iptr);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double modfl (long double x, long double *iptr);
#endif
float fmodf (float x, float div);
#ifdef CONFIG_HAVE_DOUBLE
double fmod (double x, double div);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmodl (long double x, long double div);
#endif
/* Exponential and Logarithmic Functions ************************************/
float powf (float b, float e);
#ifdef CONFIG_HAVE_DOUBLE
double pow (double b, double e);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double powl (long double b, long double e);
#endif
float expf (float x);
float exp2f (float x);
float expm1f(float x);
#ifdef CONFIG_HAVE_DOUBLE
double exp (double x);
double exp2 (double x);
double expm1 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double expl (long double x);
long double exp2l (long double x);
long double expm1l(long double x);
#endif
float fdimf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double fdim(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fdiml(long double x, long double y);
#endif
float fmaf(float x, float y, float z);
#ifdef CONFIG_HAVE_DOUBLE
double fma(double x, double y, double z);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmal(long double x, long double y, long double z);
#endif
float fmaxf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double fmax(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmaxl(long double x, long double y);
#endif
float fminf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double fmin(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fminl(long double x, long double y);
#endif
float hypotf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double hypot(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double hypotl(long double x, long double y);
#endif
float lgammaf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double __cos(double x, double y);
double __sin(double x, double y, int iy);
double gamma(double x);
double lgamma(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double lgammal(long double x);
#endif
float tgammaf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double tgamma(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tgammal(long double x);
#endif
float logf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double log (double x);
#ifdef CONFIG_MUSL_LIBC
double log1p(double x);
#endif
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double logl (long double x);
#endif
float log10f(float x);
#ifdef CONFIG_HAVE_DOUBLE
double log10 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log10l(long double x);
#endif
float log1pf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double log1p (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log1pl(long double x);
#endif
float log2f (float x);
#ifdef CONFIG_HAVE_DOUBLE
double log2 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log2l (long double x);
#endif
float logbf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double logb (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double logbl (long double x);
#endif
int ilogbf (float x);
#ifdef CONFIG_HAVE_DOUBLE
int ilogb (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
int ilogbl (long double x);
#endif
float sqrtf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sqrt (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sqrtl (long double x);
#endif
float ldexpf(float x, int n);
#ifdef CONFIG_HAVE_DOUBLE
double ldexp (double x, int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double ldexpl(long double x, int n);
#endif
float frexpf(float x, int *exp);
#ifdef CONFIG_HAVE_DOUBLE
double frexp (double x, int *exp);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double frexpl(long double x, int *exp);
#endif
/* Trigonometric Functions **************************************************/
float sinf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sin (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sinl (long double x);
#endif
float cosf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double cos (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double cosl (long double x);
#endif
float tanf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double tan (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tanl (long double x);
#endif
float asinf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double asin (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double asinl (long double x);
#endif
float acosf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double acos (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double acosl (long double x);
#endif
float atanf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double atan (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atanl (long double x);
#endif
float atan2f(float y, float x);
#ifdef CONFIG_HAVE_DOUBLE
double atan2 (double y, double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atan2l(long double y, long double x);
#endif
float sinhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sinh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sinhl (long double x);
#endif
float coshf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double cosh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double coshl (long double x);
#endif
float cbrtf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double cbrt (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double cbrtl (long double x);
#endif
float tanhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double tanh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tanhl (long double x);
#endif
float asinhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double asinh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double asinhl (long double x);
#endif
float acoshf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double acosh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double acoshl (long double x);
#endif
float atanhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double atanh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atanhl (long double x);
#endif
float erff (float x);
float erfcf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double erf (double x);
double erfc(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double erfl (long double x);
long double erfcl(long double x);
#endif
float copysignf (float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double copysign (double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double copysignl (long double x, long double y);
#endif
float truncf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double trunc (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double truncl (long double x);
#endif
float nanf(const char *tagp);
#ifdef CONFIG_HAVE_DOUBLE
double nan(const char *tagp);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nanl(const char *tagp);
#endif
float nearbyintf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double nearbyint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nearbyintl(long double x);
#endif
float nextafterf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double nextafter(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nextafterl(long double x, long double y);
#endif
float nexttowardf(float x, long double y);
#ifdef CONFIG_HAVE_DOUBLE
double nexttoward(double x, long double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nexttowardl(long double x, long double y);
#endif
float remainderf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double remainder(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double remainderl(long double x, long double y);
#endif
float remquof(float x, float y, int *quo);
#ifdef CONFIG_HAVE_DOUBLE
double remquo(double x, double y, int *quo);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double remquol(long double x, long double y, int *quo);
#endif
float scalblnf(float x, long int n);
#ifdef CONFIG_HAVE_DOUBLE
double scalbln(double x, long int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double scalblnl(long double x, long int n);
#endif
float scalbnf(float x, int n);
#ifdef CONFIG_HAVE_DOUBLE
double scalbn(double x, int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double scalbnl(long double x, int n);
#endif
#define FP_INFINITE 0
#define FP_NAN 1
#define FP_NORMAL 2
#define FP_SUBNORMAL 3
#define FP_ZERO 4
#define fpclassify(x) \
__builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, \
FP_ZERO, x)
#define isunordered(x, y) __builtin_isunordered(x, y)
#define isgreater(x, y) __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y) __builtin_isless(x, y)
#define islessequal(x, y) __builtin_islessequal(x, y)
#define islessgreater(x, y) __builtin_islessgreater(x, y)
#define isnormal(x) __builtin_isnormal(x)
#define signbit(x) __builtin_signbit(x)
#if defined(__cplusplus)
}
#endif
#endif /* CONFIG_LIBM */
#endif /* __INCLUDE_NUTTX_LIB_MATH_H */

View File

@ -0,0 +1,2 @@
/exec_symtab.c
/modlib_symtab.c

View File

@ -0,0 +1,202 @@
############################################################################
# libs/libc-musl/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
include $(TOPDIR)/Make.defs
include aio/Make.defs
include assert/Make.defs
include audio/Make.defs
include builtin/Make.defs
include ctype/Make.defs
include dirent/Make.defs
include dlfcn/Make.defs
include endian/Make.defs
include errno/Make.defs
include eventfd/Make.defs
include fixedmath/Make.defs
include grp/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 pwd/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 stream/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 uuid/Make.defs
include wchar/Make.defs
include wctype/Make.defs
include wqueue/Make.defs
CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)libs$(DELIM)libc-musl}
# Rule for the symbol table generation
MKSYMTAB = $(TOPDIR)$(DELIM)tools$(DELIM)mksymtab$(HOSTEXEEXT)
$(MKSYMTAB):
$(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mksymtab
# C library and math library symbols should be available in the FLAT
# and PROTECTED builds. KERNEL builds are separately linked and so should
# not need symbol tables.
CSVFILES = $(TOPDIR)$(DELIM)libs$(DELIM)libc-musl$(DELIM)libc-musl.csv
CSVFILES += $(TOPDIR)$(DELIM)libs$(DELIM)libc-musl$(DELIM)math.csv
# In the PROTECTED and KERNEL builds, the applications could link with
# libproxy which will provide symbol-compatible access to OS functions
# via a call gate, but the applications which link with these functions
# directly could remove the repeat proxy code to save the space.
CSVFILES += $(TOPDIR)$(DELIM)syscall$(DELIM)syscall.csv
ifeq ($(CONFIG_EXECFUNCS_SYSTEM_SYMTAB),y)
exec_symtab.c : $(CSVFILES) $(MKSYMTAB)
$(Q) cat $(CSVFILES) | LC_ALL=C sort >$@.csv
$(Q) $(MKSYMTAB) $@.csv $@ $(CONFIG_EXECFUNCS_SYMTAB_ARRAY) $(CONFIG_EXECFUNCS_NSYMBOLS_VAR)
$(Q) rm -f $@.csv
CSRCS += exec_symtab.c
endif
ifeq ($(CONFIG_MODLIB_SYSTEM_SYMTAB),y)
modlib_sys_symtab.c : $(CSVFILES) $(MKSYMTAB)
$(Q) cat $(CSVFILES) | LC_ALL=C sort >$@.csv
$(Q) $(MKSYMTAB) $@.csv $@ $(CONFIG_MODLIB_SYMTAB_ARRAY) $(CONFIG_MODLIB_NSYMBOLS_VAR)
$(Q) rm -f $@.csv
CSRCS += modlib_sys_symtab.c
endif
BINDIR ?= bin
AOBJS = $(patsubst %.S, $(BINDIR)$(DELIM)%$(OBJEXT), $(ASRCS))
COBJS = $(patsubst %.c, $(BINDIR)$(DELIM)%$(OBJEXT), $(CSRCS))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
KBIN = libkc$(LIBEXT)
BIN ?= libc-musl$(LIBEXT)
all: $(BIN)
.PHONY: clean distclean
$(AOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.c
$(call COMPILE, $<, $@)
# C library for the flat build and
# the user phase of the two-pass kernel build
$(BIN): $(OBJS)
$(call ARCHIVE, $@, $(OBJS))
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo all BIN=$(BIN)
endif
# C library for the kernel phase of the two-pass kernel build
ifneq ($(BIN),$(KBIN))
$(KBIN):
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) BINDIR=kbin EXTRAFLAGS="$(EXTRAFLAGS)"
endif
# Context
context::
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo context BIN=$(BIN)
endif
# Dependencies
makedepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds)
$(call CATFILE, bin/Make.dep, $^)
$(call DELFILE, $^)
makekdepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds)
$(call CATFILE, kbin/Make.dep, $^)
$(call DELFILE, $^)
.depend: Makefile $(SRCS) $(TOPDIR)$(DELIM).config
$(Q) $(MAKE) makedepfile OBJPATH="bin"
ifneq ($(CONFIG_BUILD_FLAT),y)
$(Q) $(MAKE) makekdepfile CFLAGS="$(CFLAGS) $(KDEFINE)" OBJPATH="kbin"
endif
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo depend BIN=$(BIN)
endif
$(Q) touch $@
depend:: .depend
# Clean most derived files, retaining the configuration
clean::
$(Q) $(MAKE) -C bin clean
$(Q) $(MAKE) -C kbin clean
$(Q) $(MAKE) -C zoneinfo clean BIN=$(BIN)
$(call DELFILE, $(BIN))
$(call DELFILE, $(KBIN))
$(call CLEAN)
# Deep clean -- removes all traces of the configuration
distclean:: clean
$(Q) $(MAKE) -C bin distclean
$(Q) $(MAKE) -C kbin distclean
$(Q) $(MAKE) -C zoneinfo distclean BIN=$(BIN)
$(call DELFILE, exec_symtab.c)
$(call DELFILE, bin/Make.dep)
$(call DELFILE, kbin/Make.dep)
$(call DELFILE, .depend)
-include bin/Make.dep
-include kbin/Make.dep

View File

@ -0,0 +1,143 @@
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 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-musl/ 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
builtin - Support for builtin applications. Used by nuttx/binfmt and NSH.
dlfcn - dlfcn.h
endian - endian.h
errno - errno.h
hex2bin - hex2bin.h
libgen - libgen.h
locale - locale.h
lzf - lzf.h
fixedmath - fixedmath.h
grp - grp.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
pwd - pwd.h
queue - queue.h
sched - sched.h
semaphore - semaphore.h
stdio - stdio.h
stdlib - stdlib.h
string - string.h (and legacy strings.h and non-standard nuttx/b2c.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-musl.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.
symtab
======
Symbol Tables and Build Modes
-----------------------------
This directory provide support for a symbol table which provides all/most of
system and C library services/functions to the application and NSH.
Symbol tables have differing usefulness in different NuttX build modes:
1. In the FLAT build (CONFIG_BUILD_FLAT), symbol tables are used to bind
addresses in loaded ELF or NxFLAT modules to base code that usually
resides in FLASH memory. Both OS interfaces and user/application
libraries are made available to the loaded module via symbol tables.
2. Symbol tables may be of value in a protected build
(CONFIG_BUILD_PROTECTED) where the newly started user task must
share resources with other user code (but should use system calls to
interact with the OS).
3. But in the kernel build mode (CONFIG_BUILD_LOADABLE), only fully linked
executables loadable via execl(), execv(), or posix_spawan() can used.
There is no use for a symbol table with the kernel build since all
memory resources are separate; nothing is share-able with the newly
started process.
Code/Text Size Implications
---------------------------
The option can have substantial effect on system image size, mainly
code/text. That is because the instructions to generate symtab.inc
above will cause EVERY interface in the NuttX RTOS and the C library to be
included into build. Add to that the size of a huge symbol table.
In order to reduce the code/text size, you may want to manually prune the
auto-generated symtab.inc file to remove all interfaces that you do
not wish to include into the base FLASH image.

View File

@ -0,0 +1,31 @@
############################################################################
# libs/libc-musl/aio/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
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

View File

@ -0,0 +1,72 @@
/****************************************************************************
* libs/libc-musl/aio/aio.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio.h
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#ifndef __LIBS_LIBC_AIO_AIO_H
#define __LIBS_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 /* __LIBS_LIBC_AIO_AIO_H */

View File

@ -0,0 +1,109 @@
/****************************************************************************
* libs/libc-musl/aio/aio_error.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio_error.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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 */

View File

@ -0,0 +1,113 @@
/****************************************************************************
* libs/libc-musl/aio/aio_return.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio_return.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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 */

View File

@ -0,0 +1,142 @@
/****************************************************************************
* libs/libc-musl/aio/aio_suspend.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio_suspend.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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 */

View File

@ -0,0 +1,705 @@
/****************************************************************************
* libs/libc-musl/aio/lio_listio.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lio_listio.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <unistd.h>
#include <signal.h>
#include <aio.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/signal.h>
#include "libc-musl.h"
#include "aio/aio.h"
#ifdef CONFIG_FS_AIO
/****************************************************************************
* Private Types
****************************************************************************/
struct lio_sighand_s
{
FAR struct aiocb * const *list; /* List of I/O operations */
FAR struct sigevent sig; /* Describes how to signal the caller */
int nent; /* Number or elements in list[] */
pid_t pid; /* ID of client */
sigset_t oprocmask; /* sigprocmask to restore */
struct sigaction oact; /* Signal handler to restore */
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: lio_checkio
*
* Description:
* Check if all I/O operations in the list are complete.
*
* Input Parameters:
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
*
* Returned Value:
* Zero (OK) is returned if all I/O completed successfully.
* -EINPROGRESS is returned if one or more I/Os have not yet completed.
* The negated errno value if first error noted in the case where all I/O
* completed but one or more I/Os completed with an error.
*
* Assumptions:
* The scheduler is locked and no I/O can complete asynchronously with
* the logic in this function.
*
****************************************************************************/
static int lio_checkio(FAR struct aiocb * const *list, int nent)
{
FAR struct aiocb *aiocbp;
int ret;
int i;
ret = OK; /* Assume success */
/* Check each entry in the list. Break out of the loop if any entry
* has not completed.
*/
for (i = 0; i < nent; i++)
{
/* Skip over NULL entries */
aiocbp = list[i];
if (aiocbp)
{
/* Check if the I/O has completed */
if (aiocbp->aio_result == -EINPROGRESS)
{
/* No.. return -EINPROGRESS */
return -EINPROGRESS;
}
/* Check for an I/O error */
else if (aiocbp->aio_result < 0 && ret == OK)
{
/* Some other error other than -EINPROGRESS */
ret = aiocbp->aio_result;
}
}
}
/* All of the I/Os have completed */
return ret;
}
/****************************************************************************
* Name: lio_sighandler
*
* Description:
* Handle the SIGPOLL signal.
*
* Input Parameters:
* signo - The number of the signal that we caught (SIGPOLL)
* info - Information accompanying the signal
* context - Not used in NuttX
*
* Returned Value:
* None
*
****************************************************************************/
static void lio_sighandler(int signo, siginfo_t *info, void *ucontext)
{
FAR struct aiocb *aiocbp;
FAR struct lio_sighand_s *sighand;
int ret;
DEBUGASSERT(signo == SIGPOLL && info);
/* The info structure should contain a pointer to the AIO control block */
aiocbp = (FAR struct aiocb *)info->si_value.sival_ptr;
DEBUGASSERT(aiocbp && aiocbp->aio_result != -EINPROGRESS);
/* Recover our private data from the AIO control block */
sighand = (FAR struct lio_sighand_s *)aiocbp->aio_priv;
DEBUGASSERT(sighand && sighand->list);
aiocbp->aio_priv = NULL;
/* Prevent any asynchronous I/O completions while the signal handler runs */
sched_lock();
/* Check if all of the pending I/O has completed */
ret = lio_checkio(sighand->list, sighand->nent);
if (ret != -EINPROGRESS)
{
/* All pending I/O has completed */
/* Restore the signal handler */
sigaction(SIGPOLL, &sighand->oact, NULL);
/* Restore the sigprocmask */
sigprocmask(SIG_SETMASK, &sighand->oprocmask, NULL);
/* Signal the client */
DEBUGVERIFY(nxsig_notification(sighand->pid, &sighand->sig,
SI_ASYNCIO, &aiocbp->aio_sigwork));
/* And free the container */
lib_free(sighand);
}
sched_unlock();
}
/****************************************************************************
* Name: lio_sigsetup
*
* Description:
* Setup a signal handler to detect when until all I/O completes.
*
* Input Parameters:
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
*
* Returned Value:
* Zero (OK) is returned if all I/O completed successfully; Otherwise, a
* negated errno value is returned corresponding to the first error
* detected.
*
* Assumptions:
* The scheduler is locked and no I/O can complete asynchronously with
* the logic in this function.
*
****************************************************************************/
static int lio_sigsetup(FAR struct aiocb * const *list, int nent,
FAR struct sigevent *sig)
{
FAR struct aiocb *aiocbp;
FAR struct lio_sighand_s *sighand;
sigset_t set;
struct sigaction act;
int status;
int i;
/* Allocate a structure to pass data to the signal handler */
sighand = lib_zalloc(sizeof(struct lio_sighand_s));
if (!sighand)
{
ferr("ERROR: lib_zalloc failed\n");
return -ENOMEM;
}
/* Initialize the allocated structure */
sighand->list = list;
sighand->sig = *sig;
sighand->nent = nent;
sighand->pid = getpid();
/* Save this structure as the private data attached to each aiocb */
for (i = 0; i < nent; i++)
{
/* Skip over NULL entries in the list */
aiocbp = list[i];
if (aiocbp)
{
FAR void *priv = NULL;
/* Check if I/O is pending for this entry */
if (aiocbp->aio_result == -EINPROGRESS)
{
priv = (FAR void *)sighand;
}
aiocbp->aio_priv = priv;
}
}
/* Make sure that SIGPOLL is not blocked */
sigemptyset(&set);
sigaddset(&set, SIGPOLL);
status = sigprocmask(SIG_UNBLOCK, &set, &sighand->oprocmask);
if (status != OK)
{
int errcode = get_errno();
ferr("ERROR sigprocmask failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
/* Attach our signal handler */
finfo("Registering signal handler\n");
act.sa_sigaction = lio_sighandler;
act.sa_flags = SA_SIGINFO;
sigfillset(&act.sa_mask);
sigdelset(&act.sa_mask, SIGPOLL);
status = sigaction(SIGPOLL, &act, &sighand->oact);
if (status != OK)
{
int errcode = get_errno();
ferr("ERROR sigaction failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
return OK;
}
/****************************************************************************
* Name: lio_waitall
*
* Description:
* Wait for all I/O operations in the list to be complete.
*
* Input Parameters:
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
*
* Returned Value:
* Zero (OK) is returned if all I/O completed successfully; Otherwise, a
* negated errno value is returned corresponding to the first error
* detected.
*
* Assumptions:
* The scheduler is locked and no I/O can complete asynchronously with
* the logic in this function.
*
****************************************************************************/
static int lio_waitall(FAR struct aiocb * const *list, int nent)
{
sigset_t set;
int ret;
/* Loop until all I/O completes */
for (; ; )
{
/* Check if all I/O has completed */
ret = lio_checkio(list, nent);
if (ret != -EINPROGRESS)
{
/* All I/O has completed.. We are finished. */
return ret;
}
/* Then wait for SIGPOLL -- indefinitely.
*
* 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 = sigwaitinfo(&set, NULL);
if (ret < 0)
{
int errcode = get_errno();
/* The most likely reason that we would get here is because some
* unrelated signal has been received.
*/
ferr("ERROR: sigwaitinfo failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: lio_listio
*
* Description:
* The lio_listio() function initiates a list of I/O requests with a
* single function call.
*
* The 'mode' argument takes one of the values LIO_WAIT or LIO_NOWAIT
* declared in <aio.h> and determines whether the function returns when
* the I/O operations have been completed, or as soon as the operations
* have been queued. If the 'mode' argument is LIO_WAIT, the function will
* wait until all I/O is complete and the 'sig' argument will be ignored.
*
* If the 'mode' argument is LIO_NOWAIT, the function will return
* immediately, and asynchronous notification will occur, according to the
* 'sig' argument, when all the I/O operations complete. If 'sig' is NULL,
* then no asynchronous notification will occur. If 'sig' is not NULL,
* asynchronous notification occurs when all the requests in 'list' have
* completed.
*
* The I/O requests enumerated by 'list' are submitted in an unspecified
* order.
*
* The 'list' argument is an array of pointers to aiocb structures. The
* array contains 'nent 'elements. The array may contain NULL elements,
* which will be ignored.
*
* If the buffer pointed to by 'list' or the aiocb structures pointed to
* by the elements of the array 'list' become illegal addresses before all
* asynchronous I/O completed and, if necessary, the notification is
* sent, then the behavior is undefined. If the buffers pointed to by the
* aio_buf member of the aiocb structure pointed to by the elements of
* the array 'list' become illegal addresses prior to the asynchronous
* I/O associated with that aiocb structure being completed, the behavior
* is undefined.
*
* The aio_lio_opcode field of each aiocb structure specifies the
* operation to be performed. The supported operations are LIO_READ,
* LIO_WRITE, and LIO_NOP; these symbols are defined in <aio.h>. The
* LIO_NOP operation causes the list entry to be ignored. If the
* aio_lio_opcode element is equal to LIO_READ, then an I/O operation is
* submitted as if by a call to aio_read() with the aiocbp equal to the
* address of the aiocb structure. If the aio_lio_opcode element is equal
* to LIO_WRITE, then an I/O operation is submitted as if by a call to
* aio_write() with the aiocbp equal to the address of the aiocb
* structure.
*
* The aio_fildes member specifies the file descriptor on which the
* operation is to be performed.
*
* The aio_buf member specifies the address of the buffer to or from which
* the data is transferred.
*
* The aio_nbytes member specifies the number of bytes of data to be
* transferred.
*
* The members of the aiocb structure further describe the I/O operation
* to be performed, in a manner identical to that of the corresponding
* aiocb structure when used by the aio_read() and aio_write() functions.
*
* The 'nent' argument specifies how many elements are members of the list;
* that is, the length of the array.
*
* Input Parameters:
* mode - Either LIO_WAIT or LIO_NOWAIT
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
* sig - Used to notify the caller when the I/O is performed
* asynchronously.
*
* Returned Value:
* If the mode argument has the value LIO_NOWAIT, the lio_listio()
* function will return the value zero if the I/O operations are
* successfully queued; otherwise, the function will return the value
* -1 and set errno to indicate the error.
*
* If the mode argument has the value LIO_WAIT, the lio_listio() function
* will return the value zero when all the indicated I/O has completed
* successfully. Otherwise, lio_listio() will return a value of -1 and
* set errno to indicate the error.
*
* In either case, the return value only indicates the success or failure
* of the lio_listio() call itself, not the status of the individual I/O
* requests. In some cases one or more of the I/O requests contained in
* the list may fail. Failure of an individual request does not prevent
* completion of any other individual request. To determine the outcome
* of each I/O request, the application must examine the error status
* associated with each aiocb control block. The error statuses so
* returned are identical to those returned as the result of an aio_read()
* or aio_write() function.
*
* The lio_listio() function will fail if:
*
* EAGAIN - The resources necessary to queue all the I/O requests were
* not available. The application may check the error status for each
* aiocb to determine the individual request(s) that failed.
* EAGAIN - The number of entries indicated by 'nent' would cause the
* system-wide limit {AIO_MAX} to be exceeded.
* EINVAL - The mode argument is not a proper value, or the value of
* 'nent' was greater than {AIO_LISTIO_MAX}.
* EINTR - A signal was delivered while waiting for all I/O requests to
* complete during an LIO_WAIT operation. Note that, since each I/O
* operation invoked by lio_listio() may possibly provoke a signal when
* it completes, this error return may be caused by the completion of
* one (or more) of the very I/O operations being awaited. Outstanding
* I/O requests are not cancelled, and the application will examine
* each list element to determine whether the request was initiated,
* cancelled, or completed.
* EIO - One or more of the individual I/O operations failed. The
* application may check the error status for each aiocb structure to
* determine the individual request(s) that failed.
*
* In addition to the errors returned by the lio_listio() function, if the
* lio_listio() function succeeds or fails with errors of EAGAIN, EINTR, or
* EIO, then some of the I/O specified by the list may have been initiated.
* If the lio_listio() function fails with an error code other than EAGAIN,
* EINTR, or EIO, no operations from the list will have been initiated. The
* I/O operation indicated by each list element can encounter errors
* specific to the individual read or write function being performed. In
* this event, the error status for each aiocb control block contains the
* associated error code. The error codes that can be set are the same as
* would be set by a read() or write() function, with the following
* additional error codes possible:
*
* EAGAIN - The requested I/O operation was not queued due to resource
* limitations.
* ECANCELED - The requested I/O was cancelled before the I/O completed
* due to an explicit aio_cancel() request.
* EFBIG - The aiocbp->aio_lio_opcode is LIO_WRITE, the file is a
* regular file, aiocbp->aio_nbytes is greater than 0, and the
* aiocbp->aio_offset is greater than or equal to the offset maximum
* in the open file description associated with aiocbp->aio_fildes.
* EINPROGRESS - The requested I/O is in progress.
* EOVERFLOW - The aiocbp->aio_lio_opcode is LIO_READ, the file is a
* regular file, aiocbp->aio_nbytes is greater than 0, and the
* aiocbp->aio_offset is before the end-of-file and is greater than
* or equal to the offset maximum in the open file description
* associated with aiocbp->aio_fildes.
*
****************************************************************************/
int lio_listio(int mode, FAR struct aiocb * const list[], int nent,
FAR struct sigevent *sig)
{
FAR struct aiocb *aiocbp = NULL;
int nqueued;
int errcode;
int retcode;
int status;
int ret;
int i;
DEBUGASSERT(mode == LIO_WAIT || mode == LIO_NOWAIT);
DEBUGASSERT(list);
nqueued = 0; /* No I/O operations yet queued */
ret = OK; /* Assume success */
/* 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();
/* Submit each asynchronous I/O operation in the list, skipping over NULL
* entries.
*/
for (i = 0; i < nent; i++)
{
/* Skip over NULL entries */
aiocbp = list[i];
if (aiocbp)
{
/* Submit the operation according to its opcode */
status = OK;
switch (aiocbp->aio_lio_opcode)
{
case LIO_NOP:
{
/* Mark the do-nothing operation complete */
aiocbp->aio_result = OK;
}
break;
case LIO_READ:
case LIO_WRITE:
{
if (aiocbp->aio_lio_opcode == LIO_READ)
{
/* Submit the asynchronous read operation */
status = aio_read(aiocbp);
}
else
{
/* Submit the asynchronous write operation */
status = aio_write(aiocbp);
}
if (status < 0)
{
/* Failed to queue the I/O. Set up the error return. */
errcode = get_errno();
ferr("ERROR: aio_read/write failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
aiocbp->aio_result = -errcode;
ret = ERROR;
}
else
{
/* Increment the count of successfully queue operations */
nqueued++;
}
}
break;
default:
{
/* Make the invalid operation complete with an error */
ferr("ERROR: Unrecognized opcode: %d\n",
aiocbp->aio_lio_opcode);
aiocbp->aio_result = -EINVAL;
ret = ERROR;
}
break;
}
}
}
/* If there was any failure in queuing the I/O, EIO will be returned */
retcode = EIO;
/* Now what? Three possibilities:
*
* Case 1: mode == LIO_WAIT
*
* Ignore the sig argument; Do no return until all I/O completes.
*/
if (mode == LIO_WAIT)
{
/* Don't wait if all if no I/O was queue */
if (nqueued > 0)
{
/* Wait until all I/O completes. The scheduler will be unlocked
* while we are waiting.
*/
status = lio_waitall(list, nent);
if (status < 0 && ret == OK)
{
/* Something bad happened while waiting and this is the first
* error to be reported.
*/
retcode = -status;
ret = ERROR;
}
}
}
/* Case 2: mode == LIO_NOWAIT and sig != NULL
*
* If any I/O was queued, then setup to signal the caller when all of
* the transfers complete.
*
* If no I/O was queue, then we I suppose that we need to signal the
* caller ourself?
*/
else if (sig != NULL)
{
if (nqueued > 0)
{
/* Setup a signal handler to detect when until all I/O completes. */
status = lio_sigsetup(list, nent, sig);
if (status < 0 && ret == OK)
{
/* Something bad happened while setting up the signal and this
* is the first error to be reported.
*/
retcode = -status;
ret = ERROR;
}
}
else
{
status = nxsig_notification(getpid(), sig,
SI_ASYNCIO, &aiocbp->aio_sigwork);
if (status < 0 && ret == OK)
{
/* Something bad happened while performing the notification
* and this is the first error to be reported.
*/
retcode = -status;
ret = ERROR;
}
}
}
/* Case 3: mode == LIO_NOWAIT and sig == NULL
*
* Just return now.
*/
sched_unlock();
if (ret < 0)
{
set_errno(retcode);
return ERROR;
}
return OK;
}
#endif /* CONFIG_FS_AIO */

View File

@ -0,0 +1,30 @@
############################################################################
# libs/libc-musl/assert/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
CSRCS += lib_assert.c
ifeq ($(CONFIG_STACK_CANARIES),y)
CSRCS += lib_stackchk.c
endif
# Add the assert directory to the build
DEPPATH += --dep-path assert
VPATH += :assert

View File

@ -0,0 +1,47 @@
/****************************************************************************
* libs/libc-musl/assert/lib_assert.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_assert.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/arch.h>
#include <assert.h>
#include <stdlib.h>
/****************************************************************************
* Public Functions
****************************************************************************/
void _assert(FAR const char *filename, int linenum)
{
up_assert(filename, linenum);
exit(EXIT_FAILURE);
}

View File

@ -0,0 +1,69 @@
/****************************************************************************
* libs/libc-musl/assert/lib_stackchk.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_stackchk.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <assert.h>
#ifdef CONFIG_STACK_CANARIES
/****************************************************************************
* Public Data
****************************************************************************/
FAR const void *const __stack_chk_guard = &__stack_chk_guard;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: __stack_chk_fail
*
* Description:
* The interface __stack_chk_fail() shall abort the function that called
* it with a message that a stack overflow has been detected. The program
* that called the function shall then exit.
*
* Input Parameters:
* None
*
* Returned Value:
* None.
*
****************************************************************************/
void __stack_chk_fail(void)
{
PANIC();
}
#endif /* CONFIG_STACK_CANARIES */

View File

@ -0,0 +1,30 @@
############################################################################
# libs/libc-musl/audio/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_AUDIO),y)
CSRCS += lib_buffer.c
include audio/libsrc/Make.defs
# Add the audio/ directory to the build
DEPPATH += --dep-path audio
VPATH += :audio
endif

View File

@ -0,0 +1,180 @@
/****************************************************************************
* libs/libc-musl/audio/lib_buffer.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_buffer.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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 <errno.h>
#include <debug.h>
#include <nuttx/audio/audio.h>
#include <nuttx/usb/audio.h>
#include "libc-musl.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.pbuffer != NULL);
/* Perform a user mode allocation */
bufsize = sizeof(struct ap_buffer_s) + bufdesc->numbytes;
apb = lib_umalloc(bufsize);
*bufdesc->u.pbuffer = apb;
/* Test if the allocation was successful or not */
if (*bufdesc->u.pbuffer == 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;
apb->samp = (FAR uint8_t *)(apb + 1);
#ifdef CONFIG_AUDIO_MULTI_SESSION
apb->session = bufdesc->session;
#endif
_SEM_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);
_SEM_DESTROY(&apb->sem);
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 */

View File

@ -0,0 +1,64 @@
############################################################################
# libs/libc-musl/audio/libsrc/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_AUDIO_SRC),y)
PACKAGE=libsamplerate
VERSION=0.1.9
libsamplerate:
$(Q) curl -L https://codeload.github.com/libsndfile/libsamplerate/zip/master -o libsamplerate.zip
$(Q) unzip -o libsamplerate.zip
$(Q) mv libsamplerate-master libsamplerate
$(Q) cp -rf libsamplerate/include/samplerate.h $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)audio$(DELIM)
context:: libsamplerate
CSRCS += samplerate.c
CSRCS += src_sinc.c
CSRCS += src_linear.c
CSRCS += src_zoh.c
CFLAGS += -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\"
CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)audio}
ifeq ($(CONFIG_SINC_FAST_CONVERTER),y)
CFLAGS += -DENABLE_SINC_FAST_CONVERTER
endif
ifeq ($(CONFIG_SINC_MEDIUM_CONVERTER),y)
CFLAGS += -DENABLE_SINC_MEDIUM_CONVERTER
endif
ifeq ($(CONFIG_SINC_BEST_CONVERTER),y)
CFLAGS += -DENABLE_SINC_BEST_CONVERTER
endif
VPATH += libsamplerate/src
SUBDIRS += libsamplerate/src
DEPPATH += --dep-path libsamplerate/src
distclean::
$(call DELDIR, $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)audio$(DELIM)samplerate.h)
$(call DELDIR, libsamplerate)
$(call DELFILE, libsamplerate.zip)
endif

View File

@ -0,0 +1,33 @@
############################################################################
# libs/libc-musl/bin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
include $(TOPDIR)/Make.defs
all:
.PHONY: clean distclean
# Clean Targets:
clean:
$(call CLEAN)
# Deep clean -- removes all traces of the configuration
distclean: clean

View File

@ -0,0 +1,36 @@
############################################################################
# libs/libc-musl/builtin/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_BUILTIN),y)
# Builtin library files
CSRCS += lib_builtin_getname.c lib_builtin_isavail.c lib_builtin_forindex.c
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CSRCS += lib_builtin_setlist.c
endif
# Hook the builtin subdirectory into the build
DEPPATH += --dep-path builtin
VPATH += builtin
endif

View File

@ -0,0 +1,69 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_forindex.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_forindex.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_for_index
*
* Description:
* Returns the builtin_s structure for the selected built-in.
* If support for built-in functions is enabled in the NuttX
* configuration, then this function must be provided by the application
* code.
*
* Input Parameters:
* index, from 0 and on...
*
* Returned Value:
* Returns valid pointer pointing to the builtin_s structure if index is
* valid.
* Otherwise, NULL is returned.
*
****************************************************************************/
FAR const struct builtin_s *builtin_for_index(int index)
{
if (index < g_builtin_count)
{
return &g_builtins[index];
}
return NULL;
}

View File

@ -0,0 +1,70 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_getname.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_getname.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_getname
*
* Description:
* Returns pointer the a name of the application at 'index' in the table
* of built-in applications.
*
* Input Parameters:
* index - From 0 and on ...
*
* Returned Value:
* Returns valid pointer pointing to the app name if index is valid.
* Otherwise NULL is returned.
*
****************************************************************************/
FAR const char *builtin_getname(int index)
{
FAR const struct builtin_s *builtin;
builtin = builtin_for_index(index);
if (builtin != NULL)
{
return builtin->name;
}
return NULL;
}

View File

@ -0,0 +1,79 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_isavail.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_isavail.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <nuttx/lib/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_isavail
*
* Description:
* Checks for availability of an application named 'appname' registered
* during compile time and, if available, returns the index into the table
* of built-in applications.
*
* Input Parameters:
* filename - Name of the linked-in binary to be started.
*
* Returned Value:
* This is an internal function, used by by the NuttX binfmt logic and
* by the application built-in logic. It returns a non-negative index to
* the application entry in the table of built-in applications on success
* or a negated errno value in the event of a failure.
*
****************************************************************************/
int builtin_isavail(FAR const char *appname)
{
FAR const char *name;
int i;
for (i = 0; (name = builtin_getname(i)) != NULL; i++)
{
if (strcmp(name, appname) == 0)
{
return i;
}
}
return -ENOENT;
}

View File

@ -0,0 +1,82 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_setlist.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_setlist.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
#if defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)
/****************************************************************************
* Public Functions
****************************************************************************/
FAR const struct builtin_s *g_builtins;
int g_builtin_count;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_setlist
*
* Description:
* Saves the user-space list of built-in applications for use by BINFS in
* protected mode. Normally this is small set of globals provided by
* user-space logic. It provides name-value pairs for associating
* built-in application names with user-space entry point addresses.
* These globals are only needed for use by BINFS which executes built-in
* applications from kernel-space in PROTECTED mode. In the FLAT build,
* the user space globals are readily available. (BINFS is not
* supportable in KERNEL mode since user-space address have no general
* meaning that configuration).
*
* Input Parameters:
* builtins - The list of built-in functions. Each entry is a name-value
* pair that maps a built-in function name to its user-space
* entry point address.
* count - The number of name-value pairs in the built-in list.
*
* Returned Value:
* None
*
****************************************************************************/
void builtin_setlist(FAR const struct builtin_s *builtins, int count)
{
g_builtins = builtins;
g_builtin_count = count;
}
#endif /* CONFIG_BUILD_PROTECTED && __KERNEL__ */

View File

@ -0,0 +1,29 @@
############################################################################
# libs/libc/libc-musl/ctype/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the ctype C files to the build
CSRCS += isalnum.c isalpha.c isascii.c isblank.c
CSRCS += iscntrl.c isdigit.c isgraph.c islower.c
CSRCS += isprint.c ispunct.c isspace.c isupper.c
CSRCS += isxdigit.c tolower.c toupper.c
DEPPATH += --dep-path ctype
VPATH += :ctype

View File

@ -0,0 +1,15 @@
/**
* @file isalnum.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}

View File

@ -0,0 +1,16 @@
/**
* @file isalpha.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isalpha
int isalpha(int c)
{
return ((unsigned)c|32)-'a' < 26;
}

View File

@ -0,0 +1,16 @@
/**
* @file isascii.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isascii
int isascii(int c)
{
return !(c&~0x7f);
}

View File

@ -0,0 +1,15 @@
/**
* @file isblank.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int isblank(int c)
{
return (c == ' ' || c == '\t');
}

View File

@ -0,0 +1,15 @@
/**
* @file iscntrl.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int iscntrl(int c)
{
return (unsigned)c < 0x20 || c == 0x7f;
}

View File

@ -0,0 +1,16 @@
/**
* @file isdigit.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isdigit
int isdigit(int c)
{
return (unsigned)c-'0' < 10;
}

View File

@ -0,0 +1,16 @@
/**
* @file isgraph.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isgraph
int isgraph(int c)
{
return (unsigned)c-0x21 < 0x5e;
}

View File

@ -0,0 +1,16 @@
/**
* @file islower.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef islower
int islower(int c)
{
return (unsigned)c-'a' < 26;
}

View File

@ -0,0 +1,16 @@
/**
* @file isprint.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isprint
int isprint(int c)
{
return (unsigned)c-0x20 < 0x5f;
}

View File

@ -0,0 +1,15 @@
/**
* @file ispunct.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int ispunct(int c)
{
return isgraph(c) && !isalnum(c);
}

View File

@ -0,0 +1,16 @@
/**
* @file isspace.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isspace
int isspace(int c)
{
return c == ' ' || (unsigned)c-'\t' < 5;
}

View File

@ -0,0 +1,16 @@
/**
* @file isupper.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isupper
int isupper(int c)
{
return (unsigned)c-'A' < 26;
}

View File

@ -0,0 +1,15 @@
/**
* @file isxdigit.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int isxdigit(int c)
{
return isdigit(c) || ((unsigned)c|32)-'a' < 6;
}

View File

@ -0,0 +1,16 @@
/**
* @file tolower.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int tolower(int c)
{
if (isupper(c)) return c | 32;
return c;
}

View File

@ -0,0 +1,16 @@
/**
* @file toupper.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int toupper(int c)
{
if (islower(c)) return c & 0x5f;
return c;
}

View File

@ -0,0 +1,29 @@
############################################################################
# libs/libc-musl/dirent/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the dirent C files to the build
CSRCS += lib_readdirr.c lib_telldir.c lib_alphasort.c lib_scandir.c
CSRCS += lib_ftw.c lib_nftw.c
# Add the dirent directory to the build
DEPPATH += --dep-path dirent
VPATH += :dirent

View File

@ -0,0 +1,69 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_alphasort.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_alphasort.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <dirent.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: alphasort
*
* Description:
* The alphasort() function can be used as the comparison function
* compar() for scandir(). It sorts directory entries using strcoll on the
* strings (*a)->d_name and (*b)->d_name.
*
* Input Parameters:
* a - The first direntry to compare
* b - The second direntry to compare
*
* Returned Value:
* An integer less than, equal to, or greater than zero if the first
* argument is considered to be respectively less than, equal to, or
* greater than the second.
*
****************************************************************************/
int alphasort(FAR const struct dirent **a, FAR const struct dirent **b)
{
#ifdef CONFIG_LIBC_LOCALE
return strcoll((*a)->d_name, (*b)->d_name);
#else
return strcmp((*a)->d_name, (*b)->d_name);
#endif
}

View File

@ -0,0 +1,54 @@
/****************************************************************************
* libs/musl/dirent/lib_ftw.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_ftw.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <ftw.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int ftw(FAR const char *path, ftw_cb_t fn, int fdlimit)
{
/* The following cast assumes that calling a function with one
* argument more than it needs behaves as expected. This is
* actually undefined, but works on all real-world machines.
*/
union
{
ftw_cb_t ftw;
nftw_cb_t nftw;
} u;
u.ftw = fn;
return nftw(path, u.nftw, fdlimit, FTW_PHYS);
}

View File

@ -0,0 +1,250 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_nftw.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_nftw.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <ftw.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include "libc-musl.h"
/****************************************************************************
* Private Functions
****************************************************************************/
static int
call_nftw(FAR char *path, nftw_cb_t fn, int flags, int base,
int level, FAR const struct stat *buf, int info)
{
struct FTW ftw =
{
base, level
};
int r;
#ifndef CONFIG_DISABLE_ENVIRON
if (flags & FTW_CHDIR)
{
if (base > 1)
{
path[base - 1] = '\0';
r = chdir(path);
path[base - 1] = '/';
}
else
{
r = chdir("/");
}
if (r < 0)
{
return r;
}
}
#endif
r = fn(path, buf, info, &ftw);
#ifndef CONFIG_DISABLE_ENVIRON
if (flags & FTW_CHDIR)
{
lib_restoredir();
}
#endif
return r;
}
static int
do_nftw(FAR char *path, nftw_cb_t fn, int fdlimit, int flags, int level)
{
FAR DIR *dir = NULL;
struct stat buf;
size_t base;
size_t j;
int info;
int r;
j = strlen(path);
while (j > 1 && path[j - 1] == '/')
{
path[--j] = '\0';
}
base = j - 1;
while (base > 0 && path[base - 1] != '/')
{
--base;
}
r = flags & FTW_PHYS ? lstat(path, &buf) : stat(path, &buf);
if (r < 0)
{
if (!(flags & FTW_PHYS) &&
get_errno() == ENOENT && !lstat(path, &buf))
{
info = FTW_SLN;
}
else if (get_errno() == EACCES)
{
info = FTW_NS;
}
else
{
return -1;
}
}
else if (S_ISDIR(buf.st_mode))
{
if (flags & FTW_DEPTH)
{
info = FTW_DP;
}
else
{
info = FTW_D;
}
}
else if (S_ISLNK(buf.st_mode))
{
if (flags & FTW_PHYS)
{
info = FTW_SL;
}
else
{
info = FTW_SLN;
}
}
else
{
info = FTW_F;
}
if (info == FTW_D || info == FTW_DP)
{
dir = opendir(path);
if (dir)
{
if (fdlimit <= 0)
{
closedir(dir);
dir = NULL;
}
}
else if (get_errno() == EACCES)
{
info = FTW_DNR;
}
else
{
return -1;
}
}
if (!(flags & FTW_DEPTH))
{
r = call_nftw(path, fn, flags, base, level, &buf, info);
if (r)
{
return r;
}
}
if (dir)
{
FAR struct dirent *de;
size_t l = j;
if (path[j - 1] != '/')
{
path[j++] = '/';
}
while ((de = readdir(dir)))
{
if (de->d_name[0] == '.' && (!de->d_name[1] ||
(de->d_name[1] == '.' && !de->d_name[2])))
{
continue;
}
if (strlen(de->d_name) > PATH_MAX - j)
{
set_errno(ENAMETOOLONG);
closedir(dir);
return -1;
}
strcpy(path + j, de->d_name);
r = do_nftw(path, fn, fdlimit - 1, flags, level + 1);
if (r)
{
closedir(dir);
return r;
}
}
path[l] = '\0';
closedir(dir);
}
if (flags & FTW_DEPTH)
{
r = call_nftw(path, fn, flags, base, level, &buf, info);
if (r)
{
return r;
}
}
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
int nftw(FAR const char *path, nftw_cb_t fn, int fdlimit, int flags)
{
char pathbuf[PATH_MAX + 1];
strncpy(pathbuf, path, PATH_MAX);
pathbuf[PATH_MAX] = '\0';
return do_nftw(pathbuf, fn, fdlimit, flags, 0);
}

View File

@ -0,0 +1,117 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_readdirr.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_readdirr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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;
}

View File

@ -0,0 +1,237 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_scandir.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_scandir.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#include "libc-musl.h"
/* The scandir() function is not appropriate for use within the kernel in its
* current form because it uses user space memory allocators and modifies
* the errno value.
*/
#ifndef __KERNEL__
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: scandir
*
* Description:
* The scandir() function scans the directory dirp, calling filter() on
* each directory entry. Entries for which filter() returns nonzero are
* stored in strings allocated via malloc(), sorted using qsort() with
* comparison function compar(), and collected in array namelist which is
* allocated via malloc(). If filter is NULL, all entries are selected.
*
* Input Parameters:
* path - Pathname of the directory to scan
* namelist - An array of pointers to directory entries, which is allocated
* by scandir via malloc. Each directory entry is allocated via
* malloc as well. The caller is responsible to free said
* objects.
* filter - Directory entries for which filter returns zero are not
* included in the namelist. If filter is NULL, all entries are
* included.
* compar - Comparison function used with qsort() to sort the namelist.
*
* Returned Value:
* If successful, the scandir() function returns the number of entries in
* the namelist. Otherwise, it returns -1 and errno is set to indicate the
* error.
*
****************************************************************************/
int scandir(FAR const char *path, FAR struct dirent ***namelist,
CODE int (*filter)(FAR const struct dirent *),
CODE int (*compar)(FAR const struct dirent **,
FAR const struct dirent **))
{
FAR struct dirent *d;
FAR struct dirent *dnew;
FAR struct dirent **list = NULL;
size_t listsize = 0;
size_t cnt = 0;
int errsv;
int result;
FAR DIR *dirp;
/* This scandir implementation relies on errno being set by other service
* functions that it is calling to figure if it was successful. We save
* the original errno value to be able to restore it in case of success.
*/
errsv = get_errno();
dirp = opendir(path);
if (!dirp)
{
return -1;
}
/* opendir might have set errno. Reset to zero. */
set_errno(0);
for (d = readdir(dirp); d != NULL; d = readdir(dirp))
{
size_t dsize;
/* If the caller provided a filter function which tells scandir to skip
* the current directory entry, do so.
*/
if (filter && !filter(d))
{
continue;
}
/* The caller provided filter function might have set errno. Reset to
* zero.
*/
set_errno(0);
/* Grow the directory entry list, if required. */
if (cnt == listsize)
{
struct dirent **newlist;
if (!listsize)
{
listsize = 4;
}
else
{
listsize *= 2;
}
newlist = lib_realloc(list, listsize * sizeof(*list));
if (!newlist)
{
/* realloc failed and set errno. This will tell follow up code
* that we failed.
*/
break;
}
list = newlist;
}
/* Allocate a new directory entry, but restrict its heap size to what
* is really required given the directories' path name.
*/
dsize = (size_t)(&d->d_name[strlen(d->d_name) + 1] - (char *)d);
dnew = lib_malloc(dsize);
if (!dnew)
{
/* malloc failed and set errno. This will tell follow up code that
* we failed.
*/
break;
}
/* Copy directory entry to newly allocated one and update the list
* accordingly.
*/
memcpy(dnew, d, dsize);
list[cnt] = dnew;
cnt++;
/* Some service function might have set errno as a side effect. Reset
* to zero.
*/
set_errno(0);
}
if (get_errno() == 0)
{
/* If the caller provided a comparison function, use it to sort the
* list of directory entries.
*/
if (compar)
{
typedef int (*compar_fn_t)(FAR const void *, FAR const void *);
qsort(list, cnt, sizeof(*list), (compar_fn_t)compar);
}
/* Set the output parameters. */
*namelist = list;
result = (int)cnt;
}
else
{
size_t i;
/* Something failed along the way. Clean up. */
for (i = 0; i < cnt; i++)
{
lib_free(list[i]);
}
lib_free(list);
result = -1;
}
closedir(dirp);
if (result >= 0)
{
/* Restore original errno value in case of success. */
set_errno(errsv);
}
return result;
}
#endif /* __KERNEL__ */

View File

@ -0,0 +1,84 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_telldir.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_telldir.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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;
}

View File

@ -0,0 +1,32 @@
############################################################################
# libs/libc-musl/dlfcn/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_LIBC_DLFCN),y)
# Add the dlfcn.h files to the build
CSRCS += lib_dlopen.c lib_dlclose.c lib_dlsym.c lib_dlerror.c lib_dlsymtab.c
# Add the dlfcn.h directory to the build
DEPPATH += --dep-path dlfcn
VPATH += :dlfcn
endif

View File

@ -0,0 +1,261 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlclose.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlclose.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dlfcn.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
#include "libc-musl.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 successfully 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->textalloc != NULL)
{
/* Free the module memory */
lib_free((FAR void *)modp->textalloc);
/* Nullify so that the memory cannot be freed again */
modp->textalloc = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = 0;
#endif
}
if (modp->dataalloc != NULL)
{
/* Free the module memory */
lib_free((FAR void *)modp->dataalloc);
/* Nullify so that the memory cannot be freed again */
modp->dataalloc = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
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 */
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
}

View File

@ -0,0 +1,68 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlerror.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlerror.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <dlfcn.h>
#include <string.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)
{
return (FAR char *)strerror(get_errno());
}

View File

@ -0,0 +1,474 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlopen.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlopen.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <dlfcn.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/envpath.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
#include "libc-musl.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 Elf_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
/* 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().
*/
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->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart;
#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);
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;
}
#elif defined(CONFIG_BUILD_FLAT)
/* In the FLAT build, a shared library is essentially the same as a kernel
* module.
*
* REVISIT: Missing functionality:
* - No automatic binding of symbols
* - No dependencies
* - mode is ignored.
*/
static inline FAR void *dlinsert(FAR const char *filename)
{
FAR void *handle;
FAR char *name;
DEBUGASSERT(filename != NULL);
name = strdup(filename);
if (name == NULL)
{
return NULL;
}
/* Then install the file using the basename of the file as the module
* name.
*/
handle = insmod(filename, basename(name));
lib_free(name);
return 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.
*/
static inline FAR void *dlinsert(FAR const char *filename)
{
#warning Missing logic
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)
{
FAR void *handle = NULL;
#ifdef CONFIG_LIBC_ENVPATH
if (file[0] != '/')
{
FAR const char *relpath;
FAR char *fullpath;
ENVPATH_HANDLE env;
/* Set aside the relative path */
relpath = file;
/* Initialize to traverse the LD_LIBRARY_PATH variable */
env = envpath_init("LD_LIBRARY_PATH");
if (env)
{
/* Get the next absolute file path */
while ((fullpath = envpath_next(env, relpath)) != NULL)
{
/* Try to load the file at this path */
handle = dlinsert(fullpath);
/* Free the allocated fullpath */
lib_free(fullpath);
/* Break out of the loop with handle != NULL on success */
if (handle != NULL)
{
break;
}
}
/* Release the traversal handle */
envpath_release(env);
}
}
else
#endif
{
/* We already have the one and only absolute path to the file to
* be loaded.
*/
handle = dlinsert(file);
}
return handle;
}

View File

@ -0,0 +1,186 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlsym.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlsym.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dlfcn.h>
#include <assert.h>
#include <debug.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 associated 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
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlsymtab.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlsymtab.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dlfcn.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 library 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)
{
#ifdef 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;
#else
/* Set the symbol take information that will be used by this instance of
* the module library.
*/
modlib_setsymtab(symtab, nsymbols);
return OK;
#endif
}

View File

@ -0,0 +1,28 @@
############################################################################
# libs/libc-musl/endian/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the endian.h C files to the build
CSRCS += swap16.c swap32.c swap64.c
# Add the endian directory to the build
DEPPATH += --dep-path endian
VPATH += :endian

View File

@ -0,0 +1,22 @@
/**
* @file swap16.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <stdint.h>
#include <endian.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef __SWAP_UINT16_ISMACRO
uint16_t __swap_uint16(uint16_t n)
{
return n<<8 | n>>8;
}
#endif

View File

@ -0,0 +1,22 @@
/**
* @file swap32.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <stdint.h>
#include <endian.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef __SWAP_UINT32_ISMACRO
uint32_t __swap_uint32(uint32_t n)
{
return (n>>24) | (n>>8&0xff00) | (n<<8&0xff0000) | (n<<24);
}
#endif

View File

@ -0,0 +1,24 @@
/**
* @file swap64.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <nuttx/compiler.h>
#include <stdint.h>
#include <endian.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifdef CONFIG_HAVE_LONG_LONG
uint64_t __swap_uint64(uint64_t n)
{
return (__swap_uint32(n)+ (0ULL<<32)) | __swap_uint32(n>>32);
}
#endif

View File

@ -0,0 +1,26 @@
############################################################################
# libs/libc-musl/errno/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
CSRCS += lib_errno.c
# Include errno build support
DEPPATH += --dep-path errno
VPATH += :errno

View File

@ -0,0 +1,74 @@
/****************************************************************************
* libs/libc-musl/errno/lib_errno.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_errno.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/tls.h>
/****************************************************************************
* Private Data
****************************************************************************/
static int g_errno;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: __errno
*
* Description:
* Return a pointer to the thread specific errno.
*
* Input Parameters:
* None
*
* Returned Value:
* A pointer to the per-thread errno variable.
*
* Assumptions:
*
****************************************************************************/
FAR int *__errno(void)
{
/* Get the TLS tls_info_s structure instance for this thread */
FAR struct tls_info_s *tlsinfo = up_tls_info();
/* And return the return refernce to the error number */
return tlsinfo ? &tlsinfo->tl_errno : &g_errno;
}

View File

@ -0,0 +1,27 @@
############################################################################
# libs/libc-musl/eventfd/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_EVENT_FD),y)
CSRCS += lib_eventfd.c
DEPPATH += --dep-path eventfd
VPATH += :eventfd
endif

View File

@ -0,0 +1,51 @@
/****************************************************************************
* libs/libc-musl/eventfd/lib_eventfd.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_eventfd.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/eventfd.h>
#include <sys/ioctl.h>
#include <unistd.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int eventfd_read(int fd, FAR eventfd_t *value)
{
return read(fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
}
int eventfd_write(int fd, eventfd_t value)
{
return write(fd, &value,
sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
}

View File

@ -0,0 +1,29 @@
############################################################################
# libs/libc-musl/fixedmath/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# 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

View File

@ -0,0 +1,102 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_b16atan2.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_b16atan2.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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;
}

View File

@ -0,0 +1,59 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_b16cos.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_b16cos.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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);
}

View File

@ -0,0 +1,104 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_b16sin.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_b16sin.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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:
* 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;
}

View File

@ -0,0 +1,268 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_fixedmath.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_fixedmath.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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

View File

@ -0,0 +1,131 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_ubsqrt.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_ubsqrt.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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;
}

View File

@ -0,0 +1,35 @@
############################################################################
# libs/libc-musl/grp/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the grp C files to the build
CSRCS += lib_getgrgid.c lib_getgrgidr.c lib_getgrnam.c lib_getgrnamr.c
CSRCS += lib_initgroups.c
ifeq ($(CONFIG_LIBC_GROUP_FILE),y)
CSRCS += lib_find_grpfile.c lib_grp_globals.c
else
CSRCS += lib_getgrbuf.c lib_getgrbufr.c
endif
# Add the grp directory to the build
DEPPATH += --dep-path grp
VPATH += :grp

View File

@ -0,0 +1,346 @@
/****************************************************************************
* libs/libc-musl/grp/lib_find_grpfile.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_find_grpfile.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
#include <assert.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Private Types
****************************************************************************/
typedef CODE int (grp_foreach_match_t)(FAR const struct group *entry,
uintptr_t arg);
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: grp_match_name
*
* Description:
* Called for each record in the group file. Returns "1" if the record
* matches the group name (passed as arg)
*
* Input Parameters:
* entry - The parsed group file record
* arg - A pointer to the group name to match
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry name does not match.
* = 1 : The entry name matches
*
****************************************************************************/
static int grp_match_name(FAR const struct group *entry, uintptr_t arg)
{
FAR const char *gname = (FAR const char *)arg;
return strcmp(entry->gr_name, gname) == 0 ? 1 : 0;
}
/****************************************************************************
* Name: grp_match_gid
*
* Description:
* Called for each record in the group file. Returns "1" if the record
* matches the group ID (passed as arg)
*
* Input Parameters:
* entry - The parsed group file record
* arg - The group ID to match
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry name does not match.
* = 1 : The entry name matches
*
****************************************************************************/
static int grp_match_gid(FAR const struct group *entry, uintptr_t arg)
{
int match_gid = (int)arg;
return match_gid == entry->gr_gid ? 1 : 0;
}
/****************************************************************************
* Name: grp_foreach
*
* Description:
* Visit each record in group file.
*
* Input Parameters:
* match - The match function to call on each record
* arg - Argument passed to the match function
* entry - Location to return the parsed group file entry
* buffer - I/O buffer used to access the group file
* buflen - The size of the I/O buffer in bytes
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry with this name was found.
* = 1 : The entry with this name was found.
*
****************************************************************************/
static int grp_foreach(grp_foreach_match_t match, uintptr_t arg,
FAR struct group *entry, FAR char *buffer,
size_t buflen)
{
FAR FILE *stream;
FAR char *ptr;
FAR char *line;
FAR char *save;
size_t linelen;
unsigned int nmembers;
int ret;
stream = fopen(CONFIG_LIBC_GROUP_FILEPATH, "r");
if (stream == NULL)
{
int errcode = get_errno();
DEBUGASSERT(errcode > 0);
return -errcode;
}
/* Read the password file line by line until the record with the matching
* username is found, or until the end of the file is reached.
*
* The format of the password file is:
*
* user:x:uid:gid:home
*
* Where:
* user: User name
* x: Encrypted password
* uid: User ID
* gid: Group ID
* home: Login directory
*/
DEBUGASSERT(buflen > MEMBER_SIZE); /* Buffer must also be aligned */
line = buffer + MEMBER_SIZE;
linelen = buflen - MEMBER_SIZE;
while (fgets(line, linelen, stream) != NULL)
{
ptr = line;
entry->gr_name = ptr;
/* Skip to the end of the name and properly terminate it. The name
* must be terminated with the field delimiter ':'.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
/* Bad line format? */
continue;
}
*ptr++ = '\0';
entry->gr_passwd = ptr;
/* Skip to the end of the password and properly terminate it. The
* password must be terminated with the field delimiter ':'.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
/* Bad line format? */
continue;
}
*ptr++ = '\0';
save = ptr;
/* Skip to the end of the group ID and properly terminate it. The
* group ID must be terminated with the field delimiter ':'.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
/* Bad line format? */
continue;
}
*ptr++ = '\0';
entry->gr_gid = (gid_t)atoi(save);
/* This is followed by a variable number of user names. The ':'
* delimited will be followed by '\n' or '\0' if there are no users
* in the group
*/
nmembers = 0;
entry->gr_mem = (FAR char **)buffer;
if (*ptr != '\n' && *ptr != '\0')
{
for (; ; )
{
/* Add the next user name */
entry->gr_mem[nmembers] = ptr;
nmembers++;
if (nmembers >= CONFIG_LIBC_GROUP_NUSERS)
{
break;
}
/* Skip to the end of the user name and properly terminate it.
* The user name must be terminated with either (1) ','
* meaning that another user name is present, or (2) '\n' or
* '\0' meaning that we have reached the end of the line and
* there are no further user names.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ','; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
*ptr = '\0';
break;
}
*ptr++ = '\0';
}
}
/* The list terminates with a NULL pointer */
entry->gr_mem[nmembers] = NULL;
/* Check for a match */
ret = match(entry, arg);
if (ret != 0)
{
/* We either have the match or an error occurred. */
fclose(stream);
return ret;
}
}
fclose(stream);
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: grp_findby_name
*
* Description:
* Find group file entry using the group name.
*
* Input Parameters:
* gname - The group name
* entry - Location to return the parsed group file entry
* buffer - I/O buffer used to access the group file
* buflen - The size of the I/O buffer in bytes
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry with this name was found.
* = 1 : The entry with this name was found.
*
****************************************************************************/
int grp_findby_name(FAR const char *gname, FAR struct group *entry,
FAR char *buffer, size_t buflen)
{
return grp_foreach(grp_match_name, (uintptr_t)gname,
entry, buffer, buflen);
}
/****************************************************************************
* Name: grp_findby_gid
*
* Description:
* Find group file entry using the group ID.
*
* Input Parameters:
* gid - The group ID
* entry - Location to return the parsed group file entry
* buffer - I/O buffer used to access the group file
* buflen - The size of the I/O buffer in bytes
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry with this name was found.
* = 1 : The entry with this name was found.
*
****************************************************************************/
int grp_findby_gid(gid_t gid, FAR struct group *entry, FAR char *buffer,
size_t buflen)
{
/* Verify that the GID is in the valid range of 0 through INT16_MAX.
* OpenGroup.org does not specify a GID_MAX or GID_MIN. Instead we use a
* priori knowledge that gid_t is type int16_t.
*/
if ((uint16_t)gid > INT16_MAX)
{
return -EINVAL;
}
return grp_foreach(grp_match_gid, (uintptr_t)gid, entry, buffer, buflen);
}

View File

@ -0,0 +1,121 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrbuf.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrbuf.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <grp.h>
#include "grp/lib_grp.h"
#include "libc-musl.h"
/****************************************************************************
* Private Data
****************************************************************************/
static FAR char *g_buf;
static FAR struct group *g_grp;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrbuf
*
* Description:
* libc-musl/grp internal helper function for getgrgid and getgrnam to allocate
* and setup a group structure once a matching entry has been found.
*
* Input Parameters:
* gid - Value to set the group structure's gr_gid field to.
* name - Value to set the group structure's gr_name field to.
* passwd - Value to set the group structure's passwd field to.
*
* Returned Value:
* A pointer to a statically allocated group structure, or NULL if an
* error occurs, in which case errno is set appropriately.
*
****************************************************************************/
FAR struct group *getgrbuf(gid_t gid, FAR const char *name,
FAR const char *passwd)
{
FAR struct group *result;
FAR char *newbuf;
size_t buflen;
int err;
buflen = sizeof(FAR char **) + strlen(name) + 1 + strlen(passwd) + 1;
newbuf = (FAR char *)lib_realloc(g_buf, buflen);
if (!newbuf)
{
err = ENOMEM;
goto error;
}
g_buf = newbuf;
if (!g_grp)
{
g_grp = (FAR struct group *)lib_malloc(sizeof(struct group));
}
if (!g_grp)
{
err = ENOMEM;
goto error;
}
err = getgrbuf_r(gid, name, passwd, g_grp, g_buf, buflen, &result);
if (err)
{
goto error;
}
return result;
error:
lib_free(g_grp);
lib_free(g_buf);
g_grp = NULL;
g_buf = NULL;
set_errno(err);
return NULL;
}

View File

@ -0,0 +1,105 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrbufr.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrbufr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrbuf_r
*
* Description:
* libc-musl/grp internal helper function for getgrgid_r and getgrnam_r to setup
* the caller supplied 'grp' and 'buf' buffers once a matching entry has
* been found.
*
* Input Parameters:
* gid - Value to set grp->gr_gid to.
* name - Value to set grp->gr_name to.
* passwd - Value to set grp->passwd to.
* grp - Pointer to the space to store the retrieved group structure in.
* buf - String fields pointed to by the group struct are stored here.
* buflen - The length of buf in bytes.
* result - Pointer to the resulting group struct, or NULL in case of fail.
*
* Returned Value:
* On success getgrgid_r returns 0 and sets *result to grp. In case of
* failure an error number is returned.
*
****************************************************************************/
int getgrbuf_r(gid_t gid, FAR const char *name, FAR const char *passwd,
FAR struct group *grp, FAR char *buf, size_t buflen,
FAR struct group **result)
{
size_t reqdlen;
size_t padlen;
/* In 'buf' a NULL pointer value will be stored, which must be naturally
* aligned, followed by the null terminated group name string and the null
* terminated passwd string 'x' (indicating 'no password'). Make sure
* sufficient buffer space was supplied by the caller.
*/
padlen = sizeof(FAR void *) - ((uintptr_t)buf % sizeof(FAR char *));
reqdlen = sizeof(FAR void *) + strlen(name) + 1 + strlen(passwd) + 1;
if (buflen < padlen + reqdlen)
{
/* Insufficient buffer space supplied. */
*result = NULL;
return ERANGE;
}
grp->gr_mem = (FAR char **)&buf[padlen];
grp->gr_name = &buf[padlen + sizeof(FAR char *)];
grp->gr_passwd = &buf[padlen + sizeof(FAR char *) + strlen(name) + 1];
strcpy(grp->gr_name, name);
strcpy(grp->gr_passwd, passwd);
grp->gr_gid = gid;
*grp->gr_mem = NULL;
*result = grp;
return 0;
}

View File

@ -0,0 +1,83 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrgid.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrgid.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrgid
*
* Description:
* The getgrgid() function searches the group database for an entry with
* a matching gid.
*
* Input Parameters:
* gid - The gid to return a group structure for
*
* Returned Value:
* A pointer to a statically allocated group structure, or NULL if no
* matching entry is found or an error occurs. Applications wishing to
* check for error situations should set errno to 0 before calling
* getgrgid(). If getgrgid() returns a null pointer and errno is set to
* non-zero, an error occurred.
*
****************************************************************************/
FAR struct group *getgrgid(gid_t gid)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_gid(gid, &g_group, g_group_buffer, GRPBUF_RESERVE_SIZE);
if (ret != 1)
{
return NULL;
}
return &g_group;
#else
if (gid != ROOT_GID)
{
return NULL;
}
return getgrbuf(ROOT_GID, ROOT_NAME, ROOT_PASSWD);
#endif
}

View File

@ -0,0 +1,95 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrgidr.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrgidr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrgid_r
*
* Description:
* The getgrgid_r() function searches the group database for an entry with
* a matching gid and stores the retrieved group structure in the space
* pointed to by grp.
*
* Input Parameters:
* gid - The gid to return a group structure for.
* grp - Pointer to the space to store the retrieved group structure in.
* buf - The string fields pointed to by the group struct are stored here.
* buflen - The length of buf in bytes.
* result - Pointer to the resulting group struct, or NULL in case of fail.
*
* Returned Value:
* On success getgrgid_r returns 0 and sets *result to grp. If no match
* is found, 0 is returned and *result is set to NULL. In case of failure
* an error number is returned.
*
****************************************************************************/
int getgrgid_r(gid_t gid, FAR struct group *grp, FAR char *buf,
size_t buflen, FAR struct group **result)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_gid(gid, grp, buf, buflen);
if (ret != 1)
{
*result = NULL;
return ret < 0 ? -ret : 0;
}
*result = grp;
return 0;
#else
if (gid != ROOT_GID)
{
/* The only known group is 'root', which has a gid of 0. Thus, report
* back that no match was found.
*/
*result = NULL;
return 0;
}
return getgrbuf_r(ROOT_GID, ROOT_NAME, ROOT_PASSWD, grp, buf, buflen,
result);
#endif
}

View File

@ -0,0 +1,84 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrnam.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrnam.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrnam
*
* Description:
* The getgrnam() function searches the group database for an entry with
* a matching name.
*
* Input Parameters:
* name - The group name to return a group structure for
*
* Returned Value:
* A pointer to a statically allocated group structure, or NULL if no
* matching entry is found or an error occurs. Applications wishing to
* check for error situations should set errno to 0 before calling
* getgrnam(). If getgrnam() returns a null pointer and errno is set to
* non-zero, an error occurred.
*
****************************************************************************/
FAR struct group *getgrnam(FAR const char *name)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_name(name, &g_group, g_group_buffer, GRPBUF_RESERVE_SIZE);
if (ret != 1)
{
return NULL;
}
return &g_group;
#else
if (strcmp(name, "root"))
{
return NULL;
}
return getgrbuf(ROOT_GID, ROOT_NAME, ROOT_PASSWD);
#endif
}

View File

@ -0,0 +1,97 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrnamr.c
*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrnamr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrnam_r
*
* Description:
* The getgrnam_r() function searches the group database for an entry with
* a matching name and stores the retrieved group structure in the space
* pointed to by grp.
*
* Input Parameters:
* name - The name of the group to return a group structure for.
* grp - Pointer to the space to store the retrieved group structure in.
* buf - The string fields pointed to by the group struct are stored here.
* buflen - The length of buf in bytes.
* result - Pointer to the resulting group struct, or NULL in case of fail.
*
* Returned Value:
* On success getgrnam_r returns 0 and sets *result to grp. If no match
* is found, 0 is returned and *result is set to NULL. In case of failure
* an error number is returned.
*
****************************************************************************/
int getgrnam_r(FAR const char *name, FAR struct group *grp, FAR char *buf,
size_t buflen, FAR struct group **result)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_name(name, grp, buf, buflen);
if (ret != 1)
{
*result = NULL;
return ret < 0 ? -ret : 0;
}
*result = grp;
return 0;
#else
if (strcmp(name, ROOT_NAME))
{
/* The only known group is 'root', which has a gid of 0. Thus, report
* back that no match was found.
*/
*result = NULL;
return 0;
}
return getgrbuf_r(ROOT_GID, ROOT_NAME, ROOT_PASSWD, grp, buf, buflen,
result);
#endif
}

View File

@ -0,0 +1,100 @@
/****************************************************************************
* libs/libc-musl/grp/lib_grp.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_grp.h
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#ifndef __LIBS_LIBC_GRP_LIB_GRP_H
#define __LIBS_LIBC_GRP_LIB_GRP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ROOT_GID 0
#define ROOT_NAME "root"
#define ROOT_PASSWD "x"
/* Reserver space for a NULL terminated list for group member names */
#define MEMBER_SIZE ((CONFIG_LIBC_GROUP_NUSERS + 1) * sizeof(FAR char *))
/* Reserve space for the maximum line in the group file PLUS space for an
* array of Member names.
*/
#define GRPBUF_RESERVE_SIZE (CONFIG_LIBC_GROUP_LINESIZE + MEMBER_SIZE)
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#ifdef CONFIG_LIBC_GROUP_FILE
/* Data for non-reentrant group functions */
EXTERN struct group g_group;
EXTERN char g_group_buffer[GRPBUF_RESERVE_SIZE];
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
FAR struct group *getgrbuf(gid_t gid, FAR const char *name,
FAR const char *passwd);
int getgrbuf_r(gid_t gid, FAR const char *name, FAR const char *passwd,
FAR struct group *grp, FAR char *buf, size_t buflen,
FAR struct group **result);
#ifdef CONFIG_LIBC_GROUP_FILE
int grp_findby_name(FAR const char *gname, FAR struct group *entry,
FAR char *buffer, size_t buflen);
int grp_findby_gid(gid_t gid, FAR struct group *entry, FAR char *buffer,
size_t buflen);
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __LIBS_LIBC_GRP_LIB_GRP_H */

View File

@ -0,0 +1,53 @@
/****************************************************************************
* libs/libc-musl/grp/lib_grp_globals.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_grp_globals.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "grp/lib_grp.h"
#ifdef CONFIG_LIBC_GROUP_FILE
/****************************************************************************
* Public Data
****************************************************************************/
/* Data for non-reentrant group functions */
struct group g_group;
char g_group_buffer[GRPBUF_RESERVE_SIZE];
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* CONFIG_LIBC_GROUP_FILE */

View File

@ -0,0 +1,68 @@
/****************************************************************************
* libs/libc-musl/grp/lib_initgroups.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_initgroups.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: initgroups
*
* Description:
* The group database /etc/group is read to determine all groups of which
* user is a member. The additional group group is also added to this set,
* which is then used to set the supplementary group IDs of the calling
* process.
*
* Input Parameters:
* user - Name of the user to query the /etc/group database for.
* group - Additional gid to add to the list of group IDs.
*
* Returned Value:
* The initgroups() function returns zero if successful, and -1 in case of
* failure, in which case errno is set appropriately.
*
****************************************************************************/
int initgroups(FAR const char *user, gid_t group)
{
/* There currently is no support for supplementary group IDs in NuttX.
* Thus, just ignore this request silently and report success.
*/
return 0;
}

View File

@ -0,0 +1,32 @@
############################################################################
# libs/libc-musl/hex2bin/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_LIBC_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

View File

@ -0,0 +1,97 @@
/****************************************************************************
* libs/libc-musl/hex2bin/lib_fhex2mem.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_fhex2mem.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <assert.h>
#include <hex2bin.h>
#include <nuttx/streams.h>
#ifdef CONFIG_LIBC_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_LIBC_HEX2BIN */

View File

@ -0,0 +1,695 @@
/****************************************************************************
* libs/libc-musl/hex2bin/lib_hex2bin.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_hex2bin.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* References:
* - http://en.wikipedia.org/wiki/Intel_HEX
* - Hexadecimal Object File Format Specification, Revision A January 6,
* 1988, Intel
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include <debug.h>
#include <errno.h>
#include <hex2bin.h>
#include <nuttx/streams.h>
#include "libc-musl.h"
#ifdef CONFIG_LIBC_HEX2BIN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* ASCII record sizes */
#define BYTECOUNT_ASCSIZE 2
#define ADDRESS_ASCSIZE 4
#define RECTYPE_ASCSIZE 2
#define BYTECOUNT_LINENDX (0)
#define ADDRESS_LINENDX (BYTECOUNT_LINENDX + BYTECOUNT_ASCSIZE)
#define RECTYPE_LINENDX (ADDRESS_LINENDX + ADDRESS_ASCSIZE)
#define DATA_LINENDX (RECTYPE_LINENDX + RECTYPE_ASCSIZE)
#define HEADER_ASCSIZE DATA_LINENDX
#define CHECKSUM_ASCSIZE 2
#define TRAILER_SIZE (CHECKSUM_ASCSIZE)
#define MAXDATA_BINSIZE 255
#define RECORD_ASCSIZE(n) (HEADER_ASCSIZE + TRAILER_SIZE + 2*(n))
#define MAXRECORD_ASCSIZE RECORD_ASCSIZE(MAXDATA_BINSIZE)
#define MINRECORD_ASCSIZE RECORD_ASCSIZE(0)
#define LINE_ALLOC MAXRECORD_ASCSIZE
/* Binary record sizes */
#define BYTECOUNT_BINSIZE 1
#define ADDRESS_BINSIZE 2
#define RECTYPE_BINSIZE 1
#define BYTECOUNT_BINNDX (0)
#define ADDRESS_BINNDX (BYTECOUNT_BINNDX + BYTECOUNT_BINSIZE)
#define RECTYPE_BINNDX (ADDRESS_BINNDX + ADDRESS_BINSIZE)
#define DATA_BINNDX (RECTYPE_BINNDX + RECTYPE_BINSIZE)
#define HEADER_BINSIZE DATA_BINNDX
#define CHECKSUM_BINSIZE 1
#define TRAILER_BINSIZE CHECKSUM_BINSIZE
#define RECORD_BINSIZE(n) (HEADER_BINSIZE + TRAILER_BINSIZE + (n))
#define MAXRECORD_BINSIZE RECORD_BINSIZE(MAXDATA_BINSIZE)
#define MINRECORD_BKINSIZE RECORD_BINSIZE(0)
#define BIN_ALLOC MAXRECORD_BINSIZE
/* Record start code */
#define RECORD_STARTCODE ':'
/* Record Types */
#define RECORD_DATA 0 /* Data */
#define RECORD_EOF 1 /* End of file */
#define RECORD_EXT_SEGADDR 2 /* Extended segment address record */
#define RECORD_START_SEGADDR 3 /* Start segment address record */
#define RECORD_EXT_LINADDR 4 /* Extended linear address record */
#define RECORD_START_LINADDR 5 /* Start linear address record */
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nibble2bin
****************************************************************************/
static int nibble2bin(uint8_t ascii)
{
if (ascii >= '0' && ascii <= '9')
{
return (ascii - 0x30);
}
else if (ascii >= 'a' && ascii <= 'f')
{
return (ascii - 'a' + 10);
}
else if (ascii >= 'A' && ascii <= 'F')
{
return (ascii - 'A' + 10);
}
return -EINVAL;
}
/****************************************************************************
* Name: byte2bin
****************************************************************************/
static int byte2bin(FAR const uint8_t *ascii)
{
int nibble;
int byte;
/* Get the MS nibble (big endian order) */
nibble = nibble2bin(*ascii++);
if (nibble < 0)
{
return nibble;
}
byte = (nibble << 4);
/* Get the MS nibble */
nibble = nibble2bin(*ascii);
if (nibble < 0)
{
return nibble;
}
byte |= nibble;
return byte;
}
/****************************************************************************
* Name: word2bin
****************************************************************************/
#if 0 /* Not used */
static int word2bin(FAR const char *ascii)
{
int byte;
int word;
/* Get the MS byte (big endian order) */
byte = word2bin(ascii);
if (byte < 0)
{
return byte;
}
word = (byte << 8);
/* Get the MS byte */
byte = word2bin(ascii + 2);
if (byte < 0)
{
return byte;
}
word |= byte;
return word;
}
#endif
/****************************************************************************
* Name: data2bin
****************************************************************************/
int data2bin(FAR uint8_t *dest, FAR const uint8_t *src, int nsrcbytes)
{
int byte;
/* An even number of source bytes is expected */
if ((nsrcbytes & 1) != 0)
{
return -EINVAL;
}
/* Convert src bytes in groups of 2, writing one byte to the output on each
* pass through the loop.
*/
while (nsrcbytes > 0)
{
/* Get the MS nibble (big endian order) */
byte = byte2bin(src);
if (byte < 0)
{
return byte;
}
src += 2;
/* And write the byte to the destination */
*dest++ = byte;
nsrcbytes -= 2;
}
return OK;
}
/****************************************************************************
* Name: readstream
****************************************************************************/
static int readstream(FAR struct lib_instream_s *instream,
FAR uint8_t *line, unsigned int lineno)
{
int nbytes = 0;
int ch;
/* Skip until the beginning of line start code is encountered */
ch = instream->get(instream);
while (ch != RECORD_STARTCODE && ch != EOF)
{
ch = instream->get(instream);
}
/* Skip over the startcode */
if (ch != EOF)
{
ch = instream->get(instream);
}
/* Then read, verify, and buffer until the end of line is encountered */
while (ch != EOF && nbytes < (MAXRECORD_ASCSIZE - 1))
{
if (ch == '\n' || ch == '\r')
{
*line = '\0';
return nbytes;
}
/* Only hex data goes into the line buffer */
else if (isxdigit(ch))
{
*line++ = ch;
nbytes++;
}
else if (!isspace(ch)) /* Not expected */
{
lerr("Line %u ERROR: Unexpected character %c[%02x] in stream\n",
lineno, isprint(ch) ? ch : '.', ch);
break;
}
/* Read the next character from the input stream */
ch = instream->get(instream);
}
/* Some error occurred: Unexpected EOF, line too long, or bad character in
* stream
*/
lerr("Line %u ERROR: Failed to read line. %d characters read\n",
lineno, nbytes);
return EOF;
}
/****************************************************************************
* Name: hex2bin_swap16 and hex2bin_swap32
****************************************************************************/
static inline void hex2bin_swap16(FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount -= 2)
{
uint8_t b0 = data[0];
uint8_t b1 = data[1];
*data++ = b1;
*data++ = b0;
}
}
static inline void hex2bin_swap32(FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount -= 4)
{
uint8_t b0 = data[0];
uint8_t b1 = data[1];
uint8_t b2 = data[2];
uint8_t b3 = data[3];
*data++ = b3;
*data++ = b2;
*data++ = b1;
*data++ = b0;
}
}
/****************************************************************************
* Name: writedata
****************************************************************************/
static inline void writedata(FAR struct lib_sostream_s *outstream,
FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount--)
{
outstream->put(outstream, *data++);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: hex2bin
*
* Description:
* Read the Intel HEX ASCII data provided on the serial IN stream and write
* the binary to the seek-able serial OUT stream.
*
* These streams may be files or, in another usage example, the IN stream
* could be a serial port and the OUT stream could be a memory stream.
* This would decode and write the serial input to memory.
*
* Input Parameters:
* instream - The incoming stream from which Intel HEX data will be
* received.
* outstream - The outgoing stream in which binary data will be written.
* baseaddr - The base address of the outgoing stream. Seeking in the
* output stream will be relative to this address.
* endpaddr - The end address (plus 1) of the outgoing stream. This
* value is used only for range checking. endpaddr must
* be larger than baseaddr. A zero value for endpaddr
* disables range checking.
* 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 hex2bin(FAR struct lib_instream_s *instream,
FAR struct lib_sostream_s *outstream, uint32_t baseaddr,
uint32_t endpaddr, enum hex2bin_swap_e swap)
{
FAR uint8_t *alloc;
FAR uint8_t *line;
FAR uint8_t *bin;
int nbytes;
int bytecount;
uint32_t address;
uint32_t endaddr;
uint32_t expected;
uint32_t extension;
uint16_t address16;
uint8_t checksum;
unsigned int lineno;
int i;
int ret = OK;
/* Allocate buffer memory */
alloc = (FAR uint8_t *)lib_malloc(LINE_ALLOC + BIN_ALLOC);
if (alloc == NULL)
{
lerr("ERROR: Failed to allocate memory\n");
return -ENOMEM;
}
line = alloc;
bin = &alloc[LINE_ALLOC];
extension = 0;
expected = 0;
lineno = 0;
/* Read and process the HEX input stream stream until the end of file
* record is received (or until an error occurs)
*/
while ((nbytes = readstream(instream, line, lineno)) != EOF)
{
/* Increment the line number */
lineno++;
/* Did we read enough data to do anything? */
if (nbytes < MINRECORD_ASCSIZE)
{
lerr("Line %u ERROR: Record too short: %d\n", lineno, nbytes);
goto errout_with_einval;
}
/* We should always read an even number of bytes */
if ((nbytes & 1) != 0)
{
lerr("Line %u ERROR: Record length is odd: %d\n", lineno, nbytes);
goto errout_with_einval;
}
/* Get the data byte count */
bytecount = byte2bin(&line[BYTECOUNT_LINENDX]);
if (bytecount < 0)
{
lerr("Line %u ERROR: Failed to read bytecount: %d\n",
lineno, bytecount);
ret = bytecount;
goto errout_with_buffers;
}
/* Verify that the bytecount matches the length of the record */
if (RECORD_ASCSIZE(bytecount) != nbytes)
{
lerr("Line %u ERROR: Expected %d bytes, read %d\n",
lineno, RECORD_ASCSIZE(bytecount), nbytes);
goto errout_with_einval;
}
/* Convert the entire line to binary. We need to do this for
* checksum calculation which includes the entire line (minus
* the start code and the checksum at the end of the line itself)
*/
ret = data2bin(bin, line, nbytes);
if (ret < 0)
{
lerr("Line %u ERROR: Failed to convert line to binary: %d\n",
lineno, ret);
goto errout_with_buffers;
}
/* Calculate and verify the checksum over all of the data */
nbytes >>= 1; /* Number of bytes in bin[] */
checksum = 0;
for (i = 0; i < nbytes; i++)
{
checksum += bin[i];
}
if (checksum != 0)
{
lerr("Line %u ERROR: Bad checksum %02x\n", lineno, checksum);
goto errout_with_einval;
}
/* Get the 16-bit (unextended) address from the record */
address16 = (uint16_t)bin[ADDRESS_BINNDX] << 8 |
(uint16_t)bin[ADDRESS_BINNDX + 1];
/* Handle the record by its record type */
switch (bin[RECTYPE_BINNDX])
{
case RECORD_DATA: /* Data */
{
/* Swap data in place in the binary buffer as required */
switch (swap)
{
case HEX2BIN_NOSWAP: /* No swap, stream is the correct byte order */
break;
case HEX2BIN_SWAP16: /* Swap bytes in 16-bit values */
{
if ((bytecount & 1) != 0)
{
lerr("Line %d ERROR: Byte count %d is not a multiple "
"of 2\n",
lineno, bytecount);
goto errout_with_einval;
}
/* Do the byte swap */
hex2bin_swap16(&bin[DATA_BINNDX], bytecount);
}
break;
case HEX2BIN_SWAP32: /* Swap bytes in 32-bit values */
{
if ((bytecount & 3) != 0)
{
lerr("Line %d ERROR: Byte count %d is not a multiple "
"of 4\n",
lineno, bytecount);
goto errout_with_einval;
}
/* Do the byte swap */
hex2bin_swap32(&bin[DATA_BINNDX], bytecount);
}
break;
default:
{
lerr("ERROR: Invalid swap argument: %d\n", swap);
goto errout_with_einval;
}
}
/* Get and verify the full 32-bit address */
address = extension + (uint32_t)address16;
endaddr = address + bytecount;
if (address < baseaddr || (endpaddr != 0 && endaddr >= endpaddr))
{
lerr("Line %d ERROR: Extended address %08lx is out of "
"range\n",
lineno, (unsigned long)address);
goto errout_with_einval;
}
/* Seek to the correct position in the OUT stream if we have
* made an unexpected jump in the data address.
*/
if (address != expected)
{
off_t pos = outstream->seek(outstream,
address - baseaddr, SEEK_SET);
if (pos == (off_t)-1)
{
lerr("Line %u ERROR: Seek to address %08lu failed\n",
lineno, (unsigned long)address);
ret = -ESPIPE;
goto errout_with_buffers;
}
}
/* Transfer data to the OUT stream */
writedata(outstream, &bin[DATA_BINNDX], bytecount);
/* This is the next data address that we expect to see */
expected = address + bytecount;
}
break;
case RECORD_EOF: /* End of file */
/* End Of File record. Must occur exactly once per file in the
* last line of the file. The byte count is 00 and the data field
* is empty. Usually the address field is also 0000.
*/
if (bytecount == 0)
{
ret = OK;
goto exit_with_buffers;
}
lerr("Line %u ERROR: Nonzero bytecount %d in EOF\n",
lineno, bytecount);
goto errout_with_einval;
case RECORD_EXT_SEGADDR: /* Extended segment address record */
/* The address specified by the data field is multiplied by 16
* (shifted 4 bits left) and added to the subsequent data record
* addresses. This allows addressing of up to a megabyte of
* address space. The address field of this record has to be
* 0000, the byte count is 02 (the segment is 16-bit). The
* least significant hex digit of the segment address is always
* 0.
*/
if (bytecount != 2 || address16 != 0 || bin[DATA_BINNDX + 1] != 0)
{
lerr("Line %u ERROR: Invalid segment address\n", lineno);
lerr(" bytecount=%d address=%04x segment=%02x%02x\n",
bytecount, address16, bin[DATA_BINNDX],
bin[DATA_BINNDX + 1]);
goto errout_with_einval;
}
extension = (uint32_t)bin[DATA_BINNDX] << 12;
break;
case RECORD_START_SEGADDR: /* Start segment address record */
/* For 80x86 processors, it specifies the initial content of
* the CS:IP registers. The address field is 0000, the byte
* count is 04, the first two bytes are the CS value, the
* latter two are the IP value.
*/
break;
case RECORD_EXT_LINADDR: /* Extended linear address record */
/* The address field is 0000, the byte count is 02. The two
* data bytes (two hex digit pairs in big endian order)
* represent the upper 16 bits of the 32 bit address for
* all subsequent 00 type records until the next 04 type
* record comes. If there is not a 04 type record, the
* upper 16 bits default to 0000. To get the absolute
* address for subsequent 00 type records, the address
* specified by the data field of the most recent 04 record
* is added to the 00 record addresses.
*/
if (bytecount != 2 || address16 != 0)
{
lerr("Line %u ERROR: Invalid linear address\n", lineno);
lerr(" bytecount=%d address=%04x\n", bytecount, address16);
goto errout_with_einval;
}
extension = (uint32_t)bin[DATA_BINNDX] << 24 |
(uint32_t)bin[DATA_BINNDX + 1] << 16;
break;
case RECORD_START_LINADDR: /* Start linear address record */
/* The address field is 0000, the byte count is 04. The 4
* data bytes represent the 32-bit value loaded into the EIP
* register of the 80386 and higher CPU.
*/
break;
default:
break;
}
}
lerr("ERROR: No EOF record found\n");
errout_with_einval:
ret = -EINVAL;
errout_with_buffers:
exit_with_buffers:
lib_free(alloc);
return ret;
}
#endif /* CONFIG_LIBC_HEX2BIN */

View File

@ -0,0 +1,97 @@
/****************************************************************************
* libs/libc-musl/hex2bin/lib_hex2mem.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_hex2mem.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <assert.h>
#include <hex2bin.h>
#include <nuttx/streams.h>
#ifdef CONFIG_LIBC_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_LIBC_HEX2BIN */

View File

@ -0,0 +1,28 @@
############################################################################
# libs/libc/libc-musl/inttypes/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the inttypes C files to the build
CSRCS += imaxabs.c strtoimax.c strtoumax.c
# Add the inttypes directory to the build
DEPPATH += --dep-path inttypes
VPATH += :inttypes

View File

@ -0,0 +1,15 @@
/**
* @file imaxabs.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <inttypes.h>
intmax_t imaxabs(intmax_t a)
{
return a>0 ? a : -a;
}

View File

@ -0,0 +1,26 @@
/**
* @file strtoimax.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <nuttx/config.h>
#include <stdlib.h>
#include <inttypes.h>
/* Current implementation depends on strtoull() and, hence, is only
* available if long long types are supported.
*/
#ifdef CONFIG_HAVE_LONG_LONG
intmax_t strtoimax(const char *restrict s, char **restrict p, int base)
{
return strtoll(s, p, base);
}
#endif /* CONFIG_HAVE_LONG_LONG */

View File

@ -0,0 +1,16 @@
/**
* @file strtoumax.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <stdlib.h>
#include <inttypes.h>
uintmax_t strtoumax(const char *restrict s, char **restrict p, int base)
{
return strtoull(s, p, base);
}

View File

@ -0,0 +1,33 @@
############################################################################
# libs/libc-musl/kbin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
include $(TOPDIR)/Make.defs
all:
.PHONY: clean distclean
# Clean Targets:
clean:
$(call CLEAN)
# Deep clean -- removes all traces of the configuration
distclean: clean

View File

@ -0,0 +1,301 @@
"__errno","errno.h","defined(CONFIG_BUILD_FLAT)","FAR int *"
"__stack_chk_fail","ssp/ssp.h","defined(CONFIG_STACK_CANARIES)","void","void"
"_assert","assert.h","","void","FAR const char *","int"
"_alert","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..."
"_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..."
"_info","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO)","void","FAR const char *","..."
"_warn","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN)","void","FAR const char *","..."
"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 const struct aiocb * const []|FAR const struct aiocb * const *","int","FAR const struct timespec *"
"alarm","unistd.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","unsigned int","unsigned int"
"asprintf","stdio.h","","int","FAR char **","FAR const IPTR char *","..."
"atof","stdlib.h","defined(CONFIG_HAVE_DOUBLE)","double","FAR const char *"
"atoi","stdlib.h","","int","FAR const char *"
"atol","stdlib.h","","long","FAR const char *"
"atoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","FAR const char *"
"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 *"
"btowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","int"
"calloc","stdlib.h","","FAR void *","size_t","size_t"
"cfgetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *"
"cfsetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t"
"chdir","unistd.h","!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"
"ctime","time.h","","char *","const time_t *"
"dirname","libgen.h","","FAR char *","FAR char *"
"dlclose","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","int","FAR void *"
"dlerror","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","FAR char *","void"
"dlopen","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","FAR void *","FAR const char *","int"
"dlsym","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","FAR void *","FAR void *","FAR const char *"
"dlsymtab","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","int","FAR const struct symtab_s *","int"
"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 *","FAR dq_queue_t *"
"dq_addlast","queue.h","","void","FAR dq_entry_t *","FAR dq_queue_t *"
"dq_rem","queue.h","","void","FAR dq_entry_t *","FAR dq_queue_t *"
"dq_remfirst","queue.h","","FAR dq_entry_t *","FAR dq_queue_t *"
"dq_remlast","queue.h","","FAR dq_entry_t *","FAR dq_queue_t *"
"ether_ntoa","netinet/ether.h","","FAR char *","FAR const struct ether_addr *"
"fclose","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *"
"fdopen","stdio.h","defined(CONFIG_FILE_STREAM)","FAR FILE *","int","FAR const char *"
"feof","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *"
"ferror","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *"
"fflush","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *"
"ffs","strings.h","","int","int"
"fgetc","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *"
"fgetpos","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *","FAR fpos_t *"
"fgets","stdio.h","defined(CONFIG_FILE_STREAM)","FAR char *","FAR char *","int","FAR FILE *"
"fileno","stdio.h","","int","FAR FILE *"
"fnmatch","fnmatch.h","","int","FAR const char *","FAR const char *","int"
"fopen","stdio.h","defined(CONFIG_FILE_STREAM)","FAR FILE *","FAR const char *","FAR const char *"
"fprintf","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *","FAR const IPTR char *","..."
"fputc","stdio.h","defined(CONFIG_FILE_STREAM)","int","int","FAR FILE *"
"fputs","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR const IPTR char *","FAR FILE *"
"fread","stdio.h","defined(CONFIG_FILE_STREAM)","size_t","FAR void *","size_t","size_t","FAR FILE *"
"free","stdlib.h","","void","FAR void *"
"freeaddrinfo","netdb.h","defined(CONFIG_LIBC_NETDB)","void","FAR struct addrinfo *"
"fseek","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *","long int","int"
"fsetpos","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *","FAR fpos_t *"
"ftell","stdio.h","defined(CONFIG_FILE_STREAM)","long","FAR FILE *"
"fwrite","stdio.h","defined(CONFIG_FILE_STREAM)","size_t","FAR const void *","size_t","size_t","FAR FILE *"
"gai_strerror","netdb.h","defined(CONFIG_LIBC_NETDB)","FAR const char *","int"
"getaddrinfo","netdb.h","defined(CONFIG_LIBC_NETDB)","int","FAR const char *","FAR const char *","FAR const struct addrinfo *","FAR struct addrinfo **"
"getcwd","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char *","FAR char *","size_t"
"gethostbyname","netdb.h","defined(CONFIG_LIBC_NETDB)","FAR struct hostent *","FAR const char *"
"gethostbyname2","netdb.h","defined(CONFIG_LIBC_NETDB)","FAR struct hostent *","FAR const char *","int"
"gethostname","unistd.h","","int","FAR char *","size_t"
"getnameinfo","netdb.h","defined(CONFIG_LIBC_NETDB)","int","FAR const struct sockaddr *","socklen_t","FAR char *","socklen_t","FAR char *","socklen_t","int"
"getopt","unistd.h","","int","int","FAR char * const []|FAR char * const *","FAR const char *"
"getoptargp","unistd.h","","FAR char **"
"getopterrp","unistd.h","","FAR int *"
"getoptindp","unistd.h","","FAR int *"
"getoptoptp","unistd.h","","FAR int *"
"gets","stdio.h","defined(CONFIG_FILE_STREAM)","FAR char *","FAR char *"
"gettimeofday","sys/time.h","","int","FAR struct timeval *","FAR struct timezone *"
"gmtime","time.h","","FAR 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)","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 *"
"isspace","ctype.h","","int","int"
"isascii","ctype.h","","int","int"
"isprint","ctype.h","","int","int"
"isgraph","ctype.h","","int","int"
"iscntrl","ctype.h","","int","int"
"islower","ctype.h","","int","int"
"isupper","ctype.h","","int","int"
"isalpha","ctype.h","","int","int"
"isblank","ctype.h","","int","int"
"isdigit","ctype.h","","int","int"
"isalnum","ctype.h","","int","int"
"ispunct","ctype.h","","int","int"
"isxdigit","ctype.h","","int","int"
"toupper","ctype.h","","int","int"
"tolower","ctype.h","","int","int"
"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"
"localtime","time.h","","struct tm *","const time_t *"
"mallinfo","malloc.h","","struct mallinfo","void"
"malloc","stdlib.h","","FAR void *","size_t"
"malloc_size","malloc.h","","size_t","FAR void *"
"mblen","stdlib.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const char *","size_t"
"mbrlen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const char *","size_t","FAR mbstate_t *"
"mbrtowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char *","size_t","FAR mbstate_t *"
"mbsnrtowcs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char **","size_t","size_t","FAR mbstate_t *"
"mbsrtowcs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char **","size_t","FAR mbstate_t *"
"mbstowcs","stdlib.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char *","size_t"
"mbtowc","stdlib.h","defined(CONFIG_LIBC_WCHAR)","int","FAR wchar_t *","FAR const char *","size_t"
"memccpy","string.h","","FAR void *","FAR void *","FAR const void *","int","size_t"
"memchr","string.h","","FAR void *","FAR const void *","int","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","size_t"
"mkdtemp","stdlib.h","","FAR char *","FAR char *"
"mkfifo","sys/stat.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char *","mode_t"
"mkstemp","stdlib.h","","int","FAR char *"
"mktemp","stdlib.h","","FAR char *","FAR char *"
"mktime","time.h","","time_t","FAR struct tm *"
"ntohl","arpa/inet.h","","uint32_t","uint32_t"
"ntohs","arpa/inet.h","","uint16_t","uint16_t"
"perror","stdio.h","defined(CONFIG_FILE_STREAM)","void","FAR const char *"
"pipe","unistd.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|FAR int *"
"printf","stdio.h","","int","FAR const IPTR 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 const pthread_attr_t *","FAR struct sched_param *"
"pthread_attr_getschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR int *"
"pthread_attr_getstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR size_t *"
"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 *","size_t"
"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_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_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_cond_timedwait","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t *","FAR pthread_mutex_t *","FAR const struct timespec *"
"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_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_t *","FAR const pthread_attr_t *","pthread_startroutine_t","pthread_addr_t"
"pthread_getname_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","char *","size_t"
"pthread_mutex_lock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_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 *","FAR 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","FAR pthread_mutexattr_t *","int"
"pthread_once","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_once_t*","CODE void (*)(void)"
"pthread_setname_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","const char *"
"pthread_yield","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void"
"puts","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR const IPTR char *"
"qsort","stdlib.h","","void","FAR void *","size_t","size_t","int(*)(FAR const void *","FAR const void *)"
"rand","stdlib.h","","int"
"readdir_r","dirent.h","","int","FAR DIR *","FAR struct dirent *","FAR struct dirent **"
"readv","sys/uio.h","","ssize_t","int","FAR const struct iovec *","int"
"realloc","stdlib.h","","FAR void *","FAR void *","size_t"
"rewind","stdio.h","defined(CONFIG_FILE_STREAM)","void","FAR FILE *"
"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"
"setlocale","locale.h","defined(CONFIG_LIBC_LOCALE)","FAR char *","int","FAR const char *"
"setlogmask","syslog.h","","int","int"
"shutdown","sys/socket.h","defined(CONFIG_NET)","int","int","int"
"sigaddset","signal.h","","int","FAR sigset_t *","int"
"sigdelset","signal.h","","int","FAR sigset_t *","int"
"sigemptyset","signal.h","","int","FAR sigset_t *"
"sigfillset","signal.h","","int","FAR sigset_t *"
"sigismember","signal.h","","int","FAR const sigset_t *","int"
"signal","signal.h","","_sa_handler_t","int","_sa_handler_t"
"sleep","unistd.h","","unsigned int","unsigned int"
"snprintf","stdio.h","","int","FAR char *","size_t","FAR const IPTR char *","..."
"sprintf","stdio.h","","int","FAR char *","FAR const IPTR 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 *","FAR sq_queue_t *"
"sq_addlast","queue.h","","void","FAR sq_entry_t *","FAR sq_queue_t *"
"sq_rem","queue.h","","void","FAR sq_entry_t *","sFAR q_queue_t *"
"sq_remafter","queue.h","","FAR sq_entry_t","FAR sq_entry_t *","FAR sq_queue_t *"
"sq_remfirst","queue.h","","FAR sq_entry_t *","FAR sq_queue_t *"
"sq_remlast","queue.h","","FAR sq_entry_t *","FAR sq_queue_t *"
"srand","stdlib.h","","void","unsigned int"
"sscanf","stdio.h","","int","FAR const IPTR 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","defined(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","defined(CONFIG_HAVE_DOUBLE)","double","FAR const char *","FAR char **"
"strtoimax","inttypes.h","","intmax_t","FAR const char *","FAR char **","int"
"strtok","string.h","","FAR char *","FAR char *","FAR const char *"
"strtok_r","string.h","","FAR char *","FAR char *","FAR const char *","FAR char **"
"strtol","stdlib.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"
"strtoumax","inttypes.h","","uintmax_t","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","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","","void","int","FAR const IPTR char *","..."
"tcflush","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","int"
"tcgetattr","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *"
"tcsetattr","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *"
"telldir","dirent.h","","off_t","FAR DIR *"
"time","time.h","","time_t","FAR time_t *"
"towlower","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","wint_t"
"towupper","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","wint_t"
"truncate","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","FAR const char *","off_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"
"uname","sys/utsname.h","","int","FAR struct utsname *"
"ungetc","stdio.h","defined(CONFIG_FILE_STREAM)","int","int","FAR FILE *"
"usleep","unistd.h","","int","useconds_t"
"vasprintf","stdio.h","","int","FAR char **","FAR const IPTR char *","va_list"
"vfprintf","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR FILE *","FAR const IPTR char *","va_list"
"vprintf","stdio.h","","int","FAR const IPTR char *","va_list"
"vscanf","stdio.h","defined(CONFIG_FILE_STREAM)","int","FAR const IPTR char *","va_list"
"vsnprintf","stdio.h","","int","FAR char *","size_t","FAR const IPTR char *","va_list"
"vsprintf","stdio.h","","int","FAR char *","FAR const IPTR char *","va_list"
"vsscanf","stdio.h","","int","FAR const char *","FAR const IPTR char *","va_list"
"vsyslog","syslog.h","","void","int","FAR const IPTR char *","va_list"
"wcrtomb","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","wchar_t","FAR 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 wchar_t *","FAR const wchar_t *","size_t"
"wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *"
"wcsnrtombs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t **","size_t","size_t","FAR mbstate_t *"
"wcsrtombs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t **","size_t","FAR mbstate_t *"
"wcstod","wchar.h","defined(CONFIG_LIBC_WCHAR)","double","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"
"wcstombs","stdlib.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t *","size_t"
"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","FAR wchar_t *","FAR const wchar_t *","size_t"
"wctob","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
"wctomb","stdlib.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)","FAR wchar_t *","FAR const wchar_t *","wchar_t","size_t"
"wmemcmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *","size_t"
"wmemcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","FAR wchat_t *","FAR wchar_t *","FAR const wchar_t *","size_t"
"wmemmove","wchar.h","defined(CONFIG_LIBC_WCHAR)","FAR wchat_t *","FAR wchar_t *","FAR const wchar_t *","size_t"
"wmemset","wchar.h","defined(CONFIG_LIBC_WCHAR)","FAR wchat_t *","FAR wchar_t *","wchar_t","size_t"
"writev","sys/uio.h","","ssize_t","int","FAR const struct iovec *","int"
Can't render this file because it has a wrong number of fields in line 2.

View File

@ -0,0 +1,175 @@
/****************************************************************************
* libs/libc-musl/libc-musl.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file libc-musl.h
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#ifndef __LIBS_LIBC_LIBC_H
#define __LIBS_LIBC_LIBC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <semaphore.h>
#include <nuttx/lib/lib.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_LIBC_HOMEDIR
# define CONFIG_LIBC_HOMEDIR "/"
#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 */
#ifdef CONFIG_FILE_STREAM
void lib_stream_semtake(FAR struct streamlist *list);
void lib_stream_semgive(FAR struct streamlist *list);
#endif
/* Defined in lib_dtoa.c */
#ifdef CONFIG_LIBC_FLOATINGPOINT
FAR char *__dtoa(double d, int mode, int ndigits, FAR int *decpt,
FAR int *sign, FAR 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_libgetbase.c */
int lib_getbase(FAR const char *nptr, FAR const char **endptr);
/* Defined in lib_skipspace.c */
void lib_skipspace(FAR const char **pptr);
/* Defined in lib_isbasedigit.c */
bool lib_isbasedigit(int ch, int base, FAR int *value);
/* Defined in lib_checkbase.c */
int lib_checkbase(int base, FAR 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
#ifndef CONFIG_DISABLE_ENVIRON
int lib_restoredir(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __LIBS_LIBC_LIBC_H */

View File

@ -0,0 +1,28 @@
############################################################################
# libs/libc/libgen/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the libgen C files to the build
CSRCS += basename.c dirname.c
# Add the libgen directory to the build
DEPPATH += --dep-path libgen
VPATH += :libgen

View File

@ -0,0 +1,21 @@
/**
* @file basename.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <string.h>
#include <libgen.h>
char *basename(char *s)
{
size_t i;
if (!s || !*s) return ".";
i = strlen(s)-1;
for (; i&&s[i]=='/'; i--) s[i] = 0;
for (; i&&s[i-1]!='/'; i--);
return s+i;
}

View File

@ -0,0 +1,23 @@
/**
* @file dirname.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <string.h>
#include <libgen.h>
char *dirname(char *s)
{
size_t i;
if (!s || !*s) return ".";
i = strlen(s)-1;
for (; s[i]=='/'; i--) if (!i) return "/";
for (; s[i]!='/'; i--) if (!i) return ".";
for (; s[i]=='/'; i--) if (!i) return "/";
s[i+1] = 0;
return s;
}

View File

@ -0,0 +1,34 @@
############################################################################
# libs/libc-musl/locale/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_LIBC_LOCALE),y)
# Add the locale files to the build
CSRCS += lib_duplocale.c lib_freelocale.c lib_localeconv.c
CSRCS += lib_newlocale.c lib_setlocale.c lib_uselocale.c
CSRCS += lib_catalog.c lib_gettext.c lib_langinfo.c
# Add the locale directory to the build
DEPPATH += --dep-path locale
VPATH += :locale
endif

View File

@ -0,0 +1,374 @@
/****************************************************************************
* libs/libc-musl/locale/lib_catalog.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_catalog.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <nl_types.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef CONFIG_LIBC_LOCALE_CATALOG
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define CAT_MAGIC 0xff88ff89
/****************************************************************************
* Private Type Definitions
****************************************************************************/
begin_packed_struct
struct cathdr_s
{
uint32_t magic;
uint32_t nsets;
uint32_t size;
uint32_t msg_offset;
uint32_t txt_offset;
} end_packed_struct;
begin_packed_struct
struct catset_s
{
uint32_t setno;
uint32_t nmsgs;
uint32_t index;
} end_packed_struct;
begin_packed_struct
struct catmsg_s
{
uint32_t msgno;
uint32_t msglen;
uint32_t offset;
} end_packed_struct;
/****************************************************************************
* Private Functions
****************************************************************************/
static nl_catd catmap(FAR const char *path)
{
FAR const struct cathdr_s *hdr;
nl_catd catd = MAP_FAILED;
struct stat st;
int fd;
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
{
return catd;
}
if (fstat(fd, &st) >= 0)
{
catd = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (catd != MAP_FAILED)
{
hdr = (FAR const struct cathdr_s *)catd;
if (CAT_MAGIC != be32toh(hdr->magic) ||
st.st_size != sizeof(*hdr) + be32toh(hdr->size))
{
munmap(catd, st.st_size);
catd = MAP_FAILED;
set_errno(ENOENT);
}
}
}
close(fd);
return catd;
}
static int setcmp(FAR const void *a, FAR const void *b)
{
FAR const int *set_id = a;
FAR const struct catset_s *set = b;
return *set_id - be32toh(set->setno);
}
static int msgcmp(FAR const void *a, FAR const void *b)
{
FAR const int *msg_id = a;
FAR const struct catmsg_s *msg = b;
return *msg_id - be32toh(msg->msgno);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: catopen
*
* Description:
* The catopen() function shall open a message catalog and return a
* message catalog descriptor. The name argument specifies the name of
* the message catalog to be opened. If name contains a '/', then name
* specifies a pathname for the message catalog. Otherwise, the environment
* variable NLSPATH is used with name substituted for the %N conversion
* specification (see XBD Environment Variables); if NLSPATH exists in the
* environment when the process starts, then if the process has appropriate
* privileges, the behavior of catopen() is undefined. If NLSPATH does not
* exist in the environment, or if a message catalog cannot be found in any
* of the components specified by NLSPATH, then an implementation-defined
* default path shall be used. This default may be affected by the setting
* of LC_MESSAGES if the value of oflag is NL_CAT_LOCALE, or the LANG
* environment variable if oflag is 0.
*
* A message catalog descriptor shall remain valid in a process until that
* process closes it, or a successful call to one of the exec functions.
* A change in the setting of the LC_MESSAGES category may invalidate
* existing open catalogs.
*
* If a file descriptor is used to implement message catalog descriptors,
* the FD_CLOEXEC flag shall be set; see <fcntl.h>.
*
* If the value of the oflag argument is 0, the LANG environment variable
* is used to locate the catalog without regard to the LC_MESSAGES
* category. If the oflag argument is NL_CAT_LOCALE, the LC_MESSAGES
* category is used to locate the message catalog (see XBD
* Internationalization Variables ).
*
* Returned Value:
* Upon successful completion, catopen() shall return a message catalog
* descriptor for use on subsequent calls to catgets() and catclose().
* Otherwise, catopen() shall return (nl_catd) -1 and set errno to
* indicate the error.
*
****************************************************************************/
nl_catd catopen(FAR const char *name, int oflag)
{
FAR const char *path;
FAR const char *lang;
FAR const char *p;
FAR const char *z;
if (strchr(name, '/'))
{
return catmap(name);
}
path = getenv("NLSPATH");
if (path == NULL)
{
path = CONFIG_LIBC_LOCALE_PATH;
}
lang = oflag ? NULL : getenv("LANG");
if (lang == NULL)
{
lang = "";
}
for (p = path; *p; p = z)
{
char buf[PATH_MAX];
nl_catd catd;
size_t i;
z = strchr(p, ':');
if (z == NULL)
{
z = p + strlen(p);
}
for (i = 0; p < z; p++)
{
FAR const char *v;
size_t l;
if (*p == '%')
{
switch (*++p)
{
case 'N':
v = name;
l = strlen(v);
break;
case 'L':
v = lang;
l = strlen(v);
break;
case 'l':
v = lang;
l = strcspn(v, "_.@");
break;
case 't':
v = strchr(lang, '_');
if (v == NULL)
{
v = "\0";
}
l = strcspn(++v, ".@");
break;
case 'c':
v = "UTF-8";
l = 5;
break;
case '%':
v = "%";
l = 1;
break;
default:
v = NULL;
}
}
else
{
v = p;
l = 1;
}
if (v == NULL || i + l >= sizeof(buf))
{
break;
}
memcpy(buf + i, v, l);
i += l;
}
if (*z)
{
z++;
}
if (*p != ':' && *p != '\0')
{
continue;
}
/* Leading : or :: in NLSPATH is same as %N */
buf[i] = 0;
catd = catmap(i ? buf : name);
if (catd != MAP_FAILED)
{
return catd;
}
}
set_errno(ENOENT);
return MAP_FAILED;
}
/****************************************************************************
* Name: catgets
*
* Description:
* The catgets() function shall attempt to read message msg_id, in set
* set_id, from the message catalog identified by catd. The catd argument
* is a message catalog descriptor returned from an earlier call to
* catopen(). The results are undefined if catd is not a value returned
* by catopen() for a message catalog still open in the process. The s
* argument points to a default message string which shall be returned by
* catgets() if it cannot retrieve the identified message.
*
* The catgets() function need not be thread-safe.
*
* Returned Value:
* If the identified message is retrieved successfully, catgets() shall
* return a pointer to an internal buffer area containing the null-
* terminated message string. If the call is unsuccessful for any reason,
* s shall be returned and errno shall be set to indicate the error.
*
****************************************************************************/
FAR char *catgets(nl_catd catd, int set_id, int msg_id, FAR const char *s)
{
FAR const struct cathdr_s *hdr = (FAR const struct cathdr_s *)catd;
FAR const struct catset_s *set = (FAR const struct catset_s *)(hdr + 1);
FAR const struct catmsg_s *msg = (FAR const struct catmsg_s *)
((FAR const char *)(hdr + 1) + be32toh(hdr->msg_offset));
FAR const char *string =
((FAR const char *)(hdr + 1) + be32toh(hdr->txt_offset));
set = bsearch(&set_id, set, be32toh(hdr->nsets), sizeof(*set), setcmp);
if (set == NULL)
{
set_errno(ENOMSG);
return (FAR char *)s;
}
msg += be32toh(set->index);
msg = bsearch(&msg_id, msg, be32toh(set->nmsgs), sizeof(*msg), msgcmp);
if (msg == NULL)
{
set_errno(ENOMSG);
return (FAR char *)s;
}
return (FAR char *)(string + be32toh(msg->offset));
}
/****************************************************************************
* Name: catclose
*
* Description:
* The catclose() function shall close the message catalog identified by
* catd. If a file descriptor is used to implement the type nl_catd, that
* file descriptor shall be closed.
*
* Returned Value:
* Upon successful completion, catclose() shall return 0; otherwise,
* -1 shall be returned, and errno set to indicate the error.
*
****************************************************************************/
int catclose(nl_catd catd)
{
FAR const struct cathdr_s *hdr = (FAR const struct cathdr_s *)catd;
return munmap(catd, sizeof(*hdr) + be32toh(hdr->size));
}
#endif

View File

@ -0,0 +1,56 @@
/****************************************************************************
* libs/libc-musl/locale/lib_duplocale.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_duplocale.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <locale.h>
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: duplocale
*
* Description:
* locales are not supported by NuttX
*
****************************************************************************/
locale_t duplocale(locale_t locobj)
{
return localeconv();
}
#endif

View File

@ -0,0 +1,55 @@
/****************************************************************************
* libs/libc-musl/locale/lib_freelocale.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_freelocale.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <locale.h>
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: freelocale
*
* Description:
* locales are not supported by NuttX
*
****************************************************************************/
void freelocale(locale_t locobj)
{
}
#endif

View File

@ -0,0 +1,834 @@
/****************************************************************************
* libs/libc-musl/locale/lib_gettext.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_gettext.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <ctype.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <libintl.h>
#include <locale.h>
#include <nuttx/tls.h>
#include <strings.h>
#include <semaphore.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include "libc-musl.h"
#ifdef CONFIG_LIBC_LOCALE_GETTEXT
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MO_MAGIC 0x950412de
/****************************************************************************
* Private Types
****************************************************************************/
struct mofile_s
{
FAR struct mofile_s *next;
char path[PATH_MAX];
FAR const char *plural_rule;
unsigned long nplurals;
FAR void *map;
size_t size;
};
struct eval_s
{
unsigned long r;
unsigned long n;
int op;
};
/****************************************************************************
* Private Data
****************************************************************************/
static FAR const char *g_catname[] =
{
"LC_CTYPE",
"LC_NUMERIC",
"LC_TIME",
"LC_COLLATE",
"LC_MONETARY",
"LC_MESSAGES",
"LC_ALL",
};
static sem_t g_sem = SEM_INITIALIZER(1);
static FAR struct mofile_s *g_mofile;
#ifdef CONFIG_BUILD_KERNEL
static FAR char g_domain[NAME_MAX];
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static FAR const char *evalexpr(FAR struct eval_s *ev,
FAR const char *s, int d);
/****************************************************************************
* Private Functions
****************************************************************************/
static FAR char *gettextdomain(void)
{
FAR char *domain;
#ifdef CONFIG_BUILD_KERNEL
domain = g_domain;
#else
FAR struct task_info_s *info;
info = task_get_info();
domain = info->ta_domain;
#endif
return domain;
}
/* MO file format is documented here:
* https://www.gnu.org/software/gettext/manual/gettext.html#MO-Files
*/
static FAR void *momap(FAR const char *path, FAR size_t *size)
{
FAR uint32_t *map = MAP_FAILED;
struct stat st;
int fd;
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
{
return map;
}
if (fstat(fd, &st) >= 0)
{
*size = st.st_size;
map = mmap(NULL, *size, PROT_READ, MAP_SHARED, fd, 0);
if (map != MAP_FAILED &&
map[0] != MO_MAGIC && map[0] != __swap_uint32(MO_MAGIC))
{
munmap(map, *size);
map = MAP_FAILED;
}
}
close(fd);
return map;
}
static inline uint32_t moswap(uint32_t x, int sw)
{
return sw ? __swap_uint32(x) : x;
}
static FAR char *molookup(FAR char *p, size_t size, FAR const char *s)
{
FAR uint32_t *mo = (FAR uint32_t *)p;
int sw = mo[0] - MO_MAGIC;
uint32_t n = moswap(mo[2], sw);
uint32_t o = moswap(mo[3], sw);
uint32_t t = moswap(mo[4], sw);
uint32_t b = 0;
if (n > size / 8 || o > size - 8 * n ||
t > size - 8 * n || (o | t) % 4 != 0)
{
return NULL;
}
o /= 4;
t /= 4;
for (; ; )
{
uint32_t ol = moswap(mo[o + 2 * (b + n / 2)], sw);
uint32_t os = moswap(mo[o + 2 * (b + n / 2) + 1], sw);
int sign;
if (ol >= size || os >= size - ol || p[os + ol])
{
return NULL;
}
sign = strcmp(s, p + os);
if (sign == 0)
{
uint32_t tl = moswap(mo[t + 2 * (b + n / 2)], sw);
uint32_t ts = moswap(mo[t + 2 * (b + n / 2) + 1], sw);
if (tl >= size || ts >= size - tl || p[ts + tl])
{
return NULL;
}
return p + ts;
}
else if (n == 1)
{
return NULL;
}
else if (sign < 0)
{
n /= 2;
}
else
{
b += n / 2;
n -= n / 2;
}
}
return NULL;
}
static FAR const char *skipspace(FAR const char *s)
{
while (isspace(*s))
{
s++;
}
return s;
}
/* Grammar:
*
* Start = Expr ';'
* Expr = Or | Or '?' Expr ':' Expr
* Or = And | Or '||' And
* And = Eq | And '&&' Eq
* Eq = Rel | Eq '==' Rel | Eq '!=' Rel
* Rel = Add | Rel '<=' Add | Rel '>=' Add | Rel '<' Add | Rel '>' Add
* Add = Mul | Add '+' Mul | Add '-' Mul
* Mul = Prim | Mul '*' Prim | Mul '/' Prim | Mul '%' Prim
* Prim = '(' Expr ')' | '!' Prim | decimal | 'n'
*
* Internals:
*
* Recursive descent expression evaluator with stack depth limit.
* for binary operators an operator-precedence parser is used.
* eval* functions store the result of the parsed subexpression
* and return a pointer to the next non-space character.
*/
static FAR const char *evalprim(FAR struct eval_s *ev,
FAR const char *s, int d)
{
FAR char *e;
if (--d < 0)
{
return "";
}
s = skipspace(s);
if (isdigit(*s))
{
ev->r = strtoul(s, &e, 10);
if (e == s || ev->r == -1)
{
return "";
}
return skipspace(e);
}
if (*s == 'n')
{
ev->r = ev->n;
return skipspace(s + 1);
}
if (*s == '(')
{
s = evalexpr(ev, s + 1, d);
if (*s != ')')
{
return "";
}
return skipspace(s + 1);
}
if (*s == '!')
{
s = evalprim(ev, s + 1, d);
ev->r = !ev->r;
return s;
}
return "";
}
static bool binop(FAR struct eval_s *ev, int op, unsigned long left)
{
unsigned long a = left;
unsigned long b = ev->r;
switch (op)
{
case 0:
ev->r = a || b;
return true;
case 1:
ev->r = a && b;
return true;
case 2:
ev->r = a == b;
return true;
case 3:
ev->r = a != b;
return true;
case 4:
ev->r = a >= b;
return true;
case 5:
ev->r = a <= b;
return true;
case 6:
ev->r = a > b;
return true;
case 7:
ev->r = a < b;
return true;
case 8:
ev->r = a + b;
return true;
case 9:
ev->r = a - b;
return true;
case 10:
ev->r = a * b;
return true;
case 11:
if (b)
{
ev->r = a % b;
return true;
}
return false;
case 12:
if (b)
{
ev->r = a / b;
return true;
}
return false;
}
return false;
}
static FAR const char *parseop(FAR struct eval_s *ev, FAR const char *s)
{
static const char opch[] =
{
'|', '&', '=', '!', '>', '<', '+', '-', '*', '%', '/'
};
static const char opch2[] =
{
'|', '&', '=', '=', '=', '='
};
int i;
for (i = 0; i < sizeof(opch); i++)
{
if (*s == opch[i])
{
/* note: >,< are accepted with or without = */
if (i < sizeof(opch2) && *(s + 1) == opch2[i])
{
ev->op = i;
return s + 2;
}
if (i >= 4)
{
ev->op = i + 2;
return s + 1;
}
break;
}
}
ev->op = 13;
return s;
}
static FAR const char *evalbinop(FAR struct eval_s *ev,
FAR const char *s, int minprec, int d)
{
static const char prec[14] =
{
1, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 0
};
unsigned long left;
int op;
s = evalprim(ev, s, --d);
s = parseop(ev, s);
for (; ; )
{
/* ev->r (left hand side value) and ev->op are now set,
* get the right hand side or back out if op has low prec,
* if op was missing then prec[op]==0
*/
op = ev->op;
if (prec[op] <= minprec)
{
return s;
}
left = ev->r;
s = evalbinop(ev, s, prec[op], d);
if (!binop(ev, op, left))
{
return "";
}
}
}
static FAR const char *evalexpr(FAR struct eval_s *ev,
FAR const char *s, int d)
{
unsigned long a;
unsigned long b;
s = evalbinop(ev, s, 0, --d);
if (*s != '?')
{
return s;
}
a = ev->r;
s = evalexpr(ev, s + 1, d);
if (*s != ':')
{
return "";
}
b = ev->r;
s = evalexpr(ev, s + 1, d);
ev->r = a ? b : ev->r;
return s;
}
unsigned long eval(FAR const char *s, unsigned long n)
{
struct eval_s ev;
memset(&ev, 0, sizeof(ev));
ev.n = n;
s = evalexpr(&ev, s, 100);
return *s == ';' ? ev.r : -1;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dcngettext
*
* Description:
* The dcngettext function searches the message catalogs identified by
* domainname and category for a string which is equal to msgid1.
*
* The msgid1 parameter must contain the singular form of the string to
* be converted. It is also used as the key for the search in the catalog.
* The msgid2 parameter is the plural form. The parameter n is used to
* determine the plural form.
*
* Returned Value:
* If there is such a string available it is returned. Otherwise msgid1 is
* returned if n == 1, otherwise msgid2.
*
* Please note that although the return value is char * the returned string
* must not be changed. This broken type results from the history of the
* function and does not reflect the way the function should be used.
*
****************************************************************************/
FAR char *gettext(FAR const char *msgid)
{
return dgettext(NULL, msgid);
}
FAR char *dgettext(FAR const char *domainname,
FAR const char *msgid)
{
return dcgettext(domainname, msgid, LC_MESSAGES);
}
FAR char *dcgettext(FAR const char *domainname,
FAR const char *msgid,
int category)
{
return dcngettext(domainname, msgid, NULL, 1, category);
}
FAR char *ngettext(FAR const char *msgid1,
FAR const char *msgid2,
unsigned long int n)
{
return dngettext(NULL, msgid1, msgid2, n);
}
FAR char *dngettext(FAR const char *domainname,
FAR const char *msgid1,
FAR const char *msgid2,
unsigned long int n)
{
return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES);
}
FAR char *dcngettext(FAR const char *domainname,
FAR const char *msgid1,
FAR const char *msgid2,
unsigned long int n,
int category)
{
FAR struct mofile_s *mofile;
FAR const char *lang;
char path[PATH_MAX];
FAR char *notrans;
FAR char *trans;
notrans = (FAR char *)(n == 1 ? msgid1 : msgid2);
if (msgid1 == NULL)
{
return notrans;
}
if (category < 0 || category >= LC_ALL)
{
return notrans;
}
if (domainname == NULL)
{
domainname = textdomain(NULL);
}
lang = getenv("LANG");
if (lang == NULL)
{
lang = "C";
}
snprintf(path, PATH_MAX,
CONFIG_LIBC_LOCALE_PATH"/%s/%s/%s.mo",
lang, g_catname[category], domainname);
while (_SEM_WAIT(&g_sem) < 0);
for (mofile = g_mofile; mofile; mofile = mofile->next)
{
if (strcmp(mofile->path, path) == 0)
{
break;
}
}
if (mofile == NULL)
{
FAR const char *r;
mofile = lib_malloc(sizeof(*mofile));
if (mofile == NULL)
{
_SEM_POST(&g_sem);
return notrans;
}
strlcpy(mofile->path, path, PATH_MAX);
mofile->map = momap(path, &mofile->size);
if (mofile->map == MAP_FAILED)
{
_SEM_POST(&g_sem);
lib_free(mofile);
return notrans;
}
/* Initialize the default plural rule */
mofile->plural_rule = "n!=1;";
mofile->nplurals = 2;
/* Parse the plural rule from the header entry(empty string) */
r = molookup(mofile->map, mofile->size, "");
while (r != NULL && strncmp(r, "Plural-Forms:", 13))
{
r = strchr(r, '\n');
if (r != NULL)
{
r += 1;
}
}
if (r != NULL)
{
r = skipspace(r + 13);
if (strncmp(r, "nplurals=", 9) == 0)
{
mofile->nplurals = strtoul(r + 9, (FAR char **)&r, 10);
}
r = strchr(r, ';');
if (r != NULL)
{
r = skipspace(r + 1);
if (strncmp(r, "plural=", 7) == 0)
{
mofile->plural_rule = r + 7;
}
}
}
mofile->next = g_mofile;
g_mofile = mofile;
}
_SEM_POST(&g_sem); /* Leave look before search */
trans = molookup(mofile->map, mofile->size, msgid1);
if (trans == NULL)
{
return notrans;
}
/* Process the plural rule if request */
if (msgid2 && mofile->nplurals)
{
unsigned long plural = eval(mofile->plural_rule, n);
if (plural >= mofile->nplurals)
{
return notrans;
}
while (plural-- != 0)
{
size_t rem = mofile->size - (trans - (FAR char *)mofile->map);
size_t l = strnlen(trans, rem);
if (l + 1 >= rem)
{
return notrans;
}
trans += l + 1;
}
}
return trans;
}
/****************************************************************************
* Name: textdomain
*
* Description:
* The textdomain function sets the default domain, which is used in all
* future gettext calls, to domainname. Please note that dgettext and
* dcgettext calls are not influenced if the domainname parameter of these
* functions is not the null pointer.
*
* Before the first call to textdomain the default domain is messages. This
* is the name specified in the specification of the gettext API. This name
* is as good as any other name. No program should ever really use a domain
* with this name since this can only lead to problems.
*
* If the domainname parameter is the empty string the default domain is
* reset to its initial value, the domain with the name messages. This
* possibility is questionable to use since the domain messages really
* never should be used.
*
* Returned Value:
* The function returns the value which is from now on taken as the default
* domain. If the system went out of memory the returned value is NULL and
* the global variable errno is set to ENOMEM. Despite the return value
* type being char * the return string must not be changed. It is allocated
* internally by the textdomain function.
*
* If the domainname parameter is the null pointer no new default domain is
* set. Instead the currently selected default domain is returned.
*
****************************************************************************/
FAR char *textdomain(FAR const char *domainname)
{
FAR char *domain;
size_t domainlen;
domain = gettextdomain();
if (domainname == NULL)
{
return *domain ? domain : "messages";
}
domainlen = strnlen(domainname, NAME_MAX);
if (domainlen == NAME_MAX)
{
set_errno(ENOMEM);
return NULL;
}
memcpy(domain, domainname, domainlen + 1);
return domain;
}
/****************************************************************************
* Name: bindtextdomain
*
* Description:
* The bindtextdomain function can be used to specify the directory which
* contains the message catalogs for domain domainname for the different
* languages. To be correct, this is the directory where the hierarchy of
* directories is expected. Details are explained below.
*
* For the programmer it is important to note that the translations which
* come with the program have to be placed in a directory hierarchy
* starting at, say, /foo/bar. Then the program should make a
* bindtextdomain call to bind the domain for the current program to this
* directory. So it is made sure the catalogs are found. A correctly
* running program does not depend on the user setting an environment
* variable.
*
* The bindtextdomain function can be used several times and if the
* domainname argument is different the previously bound domains will not
* be overwritten.
*
* If the program which wish to use bindtextdomain at some point of time
* use the chdir function to change the current working directory it is
* important that the dirname strings ought to be an absolute pathname.
* Otherwise the addressed directory might vary with the time.
*
* Returned Value:
* If the dirname parameter is the null pointer bindtextdomain returns the
* currently selected directory for the domain with the name domainname.
*
* The bindtextdomain function returns a pointer to a string containing the
* name of the selected directory name. The string is allocated internally
* in the function and must not be changed by the user. If the system went
* out of core during the execution of bindtextdomain the return value is
* NULL and the global variable errno is set accordingly.
*
****************************************************************************/
FAR char *bindtextdomain(FAR const char *domainname,
FAR const char *dirname)
{
if (domainname == NULL || dirname)
{
set_errno(EINVAL); /* Only support the default path */
}
return NULL;
}
/****************************************************************************
* Name: bind_textdomain_codeset
*
* Description:
* The bind_textdomain_codeset function can be used to specify the output
* character set for message catalogs for domain domainname. The codeset
* argument must be a valid codeset name which can be used for the
* iconv_open function, or a null pointer.
*
* The bind_textdomain_codeset function can be used several times. If used
* multiple times with the same domainname argument, the later call
* overrides the settings made by the earlier one.
*
* Returned Value:
* If the codeset parameter is the null pointer, bind_textdomain_codeset
* returns the currently selected codeset for the domain with the name
* domainname. It returns NULL if no codeset has yet been selected.
*
* The bind_textdomain_codeset function returns a pointer to a string
* containing the name of the selected codeset. The string is allocated
* internally in the function and must not be changed by the user. If the
* system went out of core during the execution of bind_textdomain_codeset,
* the return value is NULL and the global variable errno is set
* accordingly.
*
****************************************************************************/
FAR char *bind_textdomain_codeset(FAR const char *domainname,
FAR const char *codeset)
{
if (codeset && strcasecmp(codeset, "UTF-8"))
{
set_errno(EINVAL); /* Only support utf8 */
}
return NULL;
}
#endif

View File

@ -0,0 +1,57 @@
/****************************************************************************
* libs/libc-musl/locale/lib_langinfo.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_langinfo.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <langinfo.h>
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nl_langinfo
*
* Description:
* locales are not supported by NuttX
*
****************************************************************************/
FAR char *nl_langinfo(nl_item item)
{
return "";
}
#endif

View File

@ -0,0 +1,93 @@
/****************************************************************************
* libs/libc-musl/locale/lib_localeconv.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_localeconv.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <locale.h>
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Private Data
****************************************************************************/
static struct lconv g_c_lconv =
{
.decimal_point = ".",
.thousands_sep = "",
.grouping = "",
.int_curr_symbol = "",
.currency_symbol = "",
.mon_decimal_point = "",
.mon_thousands_sep = "",
.mon_grouping = "",
.positive_sign = "",
.negative_sign = "",
.int_frac_digits = CHAR_MAX,
.frac_digits = CHAR_MAX,
.p_cs_precedes = CHAR_MAX,
.p_sep_by_space = CHAR_MAX,
.n_cs_precedes = CHAR_MAX,
.n_sep_by_space = CHAR_MAX,
.p_sign_posn = CHAR_MAX,
.n_sign_posn = CHAR_MAX,
.int_p_cs_precedes = CHAR_MAX,
.int_p_sep_by_space = CHAR_MAX,
.int_n_cs_precedes = CHAR_MAX,
.int_n_sep_by_space = CHAR_MAX,
.int_p_sign_posn = CHAR_MAX,
.int_n_sign_posn = CHAR_MAX,
};
/****************************************************************************
* 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)
{
return &g_c_lconv;
}
#endif

View File

@ -0,0 +1,58 @@
/****************************************************************************
* libs/libc-musl/locale/lib_newlocale.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_newlocale.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <locale.h>
#include <string.h>
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: newlocale
*
* Description:
* locales are not supported by NuttX
*
****************************************************************************/
locale_t newlocale(int category_mask, FAR const char *locale, locale_t base)
{
return !locale || !strcmp(locale, "POSIX") ||
!strcmp(locale, "C") || !strcmp(locale, "") ? localeconv() : NULL;
}
#endif

View File

@ -0,0 +1,64 @@
/****************************************************************************
* libs/libc-musl/locale/lib_setlocale.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_setlocale.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* 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 ((locale == NULL || 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