diff options
Diffstat (limited to 'lib/mlibc/options/ansi/include')
27 files changed, 2293 insertions, 0 deletions
diff --git a/lib/mlibc/options/ansi/include/alloca.h b/lib/mlibc/options/ansi/include/alloca.h new file mode 100644 index 0000000..0cc6bcb --- /dev/null +++ b/lib/mlibc/options/ansi/include/alloca.h @@ -0,0 +1,8 @@ + +#ifndef _ALLOCA_H +#define _ALLOCA_H + +#define alloca __builtin_alloca + +#endif // _ALLOCA_H + diff --git a/lib/mlibc/options/ansi/include/assert.h b/lib/mlibc/options/ansi/include/assert.h new file mode 100644 index 0000000..7eccae0 --- /dev/null +++ b/lib/mlibc/options/ansi/include/assert.h @@ -0,0 +1,46 @@ + +#ifndef _ASSERT_H +#define _ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +// NOTE: This is not ISO C. Declared in LSB +__attribute__ ((__noreturn__)) void __assert_fail(const char *assertion, const char *file, unsigned int line, + const char *function); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _ASSERT_H + +#include <mlibc-config.h> + +#if __MLIBC_GLIBC_OPTION +# include <bits/glibc/glibc_assert.h> +#endif + +// NOTE: [7.2] requires this be outside the include guard +#ifdef NDEBUG + +#undef assert +#define assert(ignore) ((void)0) + +#else // NDEBUG + +#undef assert +#define assert(assertion) ((void)((assertion) \ + || (__assert_fail(#assertion, __FILE__, __LINE__, __func__), 0))) + +#endif // NDEBUG + +#ifndef __cplusplus +#undef static_assert +#define static_assert _Static_assert +#endif diff --git a/lib/mlibc/options/ansi/include/bits/ansi/fenv.h b/lib/mlibc/options/ansi/include/bits/ansi/fenv.h new file mode 100644 index 0000000..677ddaa --- /dev/null +++ b/lib/mlibc/options/ansi/include/bits/ansi/fenv.h @@ -0,0 +1,54 @@ +#ifndef MLIBC_FENV_H +#define MLIBC_FENV_H + +#if defined(__x86_64__) || defined(__i386__) + +#define FE_DENORMAL 2 +#define FE_DIVBYZERO 4 +#define FE_INEXACT 32 +#define FE_INVALID 1 +#define FE_OVERFLOW 8 +#define FE_UNDERFLOW 16 + +#define FE_ALL_EXCEPT (FE_DENORMAL | FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +#define FE_TONEAREST 0 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xC00 + +#elif defined(__aarch64__) + +#define FE_INVALID 1 +#define FE_DIVBYZERO 2 +#define FE_OVERFLOW 4 +#define FE_UNDERFLOW 8 +#define FE_INEXACT 16 + +#define FE_ALL_EXCEPT 31 + +#define FE_TONEAREST 0 +#define FE_UPWARD 0x400000 +#define FE_DOWNWARD 0x800000 +#define FE_TOWARDZERO 0xC00000 + +#elif defined(__riscv) && __riscv_xlen == 64 + +#define FE_INEXACT 1 +#define FE_UNDERFLOW 2 +#define FE_OVERFLOW 4 +#define FE_DIVBYZERO 8 +#define FE_INVALID 16 + +#define FE_ALL_EXCEPT 31 + +#define FE_TONEAREST 0 +#define FE_TOWARDZERO 1 +#define FE_DOWNWARD 2 +#define FE_UPWARD 3 + +#else +#error Unknown architecture +#endif + +#endif // MLIBC_FENV_H diff --git a/lib/mlibc/options/ansi/include/bits/ansi/time_t.h b/lib/mlibc/options/ansi/include/bits/ansi/time_t.h new file mode 100644 index 0000000..1c29fa0 --- /dev/null +++ b/lib/mlibc/options/ansi/include/bits/ansi/time_t.h @@ -0,0 +1,8 @@ + +#ifndef MLIBC_TIME_T +#define MLIBC_TIME_T + +typedef long time_t; + +#endif + diff --git a/lib/mlibc/options/ansi/include/bits/ansi/timespec.h b/lib/mlibc/options/ansi/include/bits/ansi/timespec.h new file mode 100644 index 0000000..d34aa64 --- /dev/null +++ b/lib/mlibc/options/ansi/include/bits/ansi/timespec.h @@ -0,0 +1,13 @@ + +#ifndef MLIBC_TIMESPEC_H +#define MLIBC_TIMESPEC_H + +#include <bits/ansi/time_t.h> + +struct timespec { + time_t tv_sec; + long tv_nsec; +}; + +#endif // MLIBC_TIMESPEC_H + diff --git a/lib/mlibc/options/ansi/include/complex.h b/lib/mlibc/options/ansi/include/complex.h new file mode 100644 index 0000000..6191f28 --- /dev/null +++ b/lib/mlibc/options/ansi/include/complex.h @@ -0,0 +1,134 @@ +/* $NetBSD: complex.h,v 1.3 2010/09/15 16:11:30 christos Exp $ */ + +/* + * Written by Matthias Drochner. + * Public domain. + */ + +#ifndef _COMPLEX_H +#define _COMPLEX_H + +#define complex _Complex +#define _Complex_I 1.0fi +#define I _Complex_I + +#define CMPLX(x, y) ((double complex)__builtin_complex((double)(x), (double)(y))) +#define CMPLXF(x, y) ((float complex)__builtin_complex((float)(x), (float)(y))) +#define CMPLXL(x, y) ((long double complex)__builtin_complex((long double)(x), (long double)(y))) + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +/* 7.3.5 Trigonometric functions */ +/* 7.3.5.1 The cacos functions */ +double complex cacos(double complex); +float complex cacosf(float complex); + +/* 7.3.5.2 The casin functions */ +double complex casin(double complex); +float complex casinf(float complex); + +/* 7.3.5.1 The catan functions */ +double complex catan(double complex); +float complex catanf(float complex); + +/* 7.3.5.1 The ccos functions */ +double complex ccos(double complex); +float complex ccosf(float complex); + +/* 7.3.5.1 The csin functions */ +double complex csin(double complex); +float complex csinf(float complex); + +/* 7.3.5.1 The ctan functions */ +double complex ctan(double complex); +float complex ctanf(float complex); + +/* 7.3.6 Hyperbolic functions */ +/* 7.3.6.1 The cacosh functions */ +double complex cacosh(double complex); +float complex cacoshf(float complex); + +/* 7.3.6.2 The casinh functions */ +double complex casinh(double complex); +float complex casinhf(float complex); + +/* 7.3.6.3 The catanh functions */ +double complex catanh(double complex); +float complex catanhf(float complex); + +/* 7.3.6.4 The ccosh functions */ +double complex ccosh(double complex); +float complex ccoshf(float complex); + +/* 7.3.6.5 The csinh functions */ +double complex csinh(double complex); +float complex csinhf(float complex); + +/* 7.3.6.6 The ctanh functions */ +double complex ctanh(double complex); +float complex ctanhf(float complex); + +/* 7.3.7 Exponential and logarithmic functions */ +/* 7.3.7.1 The cexp functions */ +double complex cexp(double complex); +float complex cexpf(float complex); + +/* 7.3.7.2 The clog functions */ +double complex clog(double complex); +float complex clogf(float complex); + +/* 7.3.8 Power and absolute-value functions */ +/* 7.3.8.1 The cabs functions */ +/*#ifndef __LIBM0_SOURCE__ */ +/* avoid conflict with historical cabs(struct complex) */ +/* double cabs(double complex) __RENAME(__c99_cabs); + float cabsf(float complex) __RENAME(__c99_cabsf); + #endif +*/ +double cabs(double complex) ; +float cabsf(float complex) ; + +/* 7.3.8.2 The cpow functions */ +double complex cpow(double complex, double complex); +float complex cpowf(float complex, float complex); + +/* 7.3.8.3 The csqrt functions */ +double complex csqrt(double complex); +float complex csqrtf(float complex); + +/* 7.3.9 Manipulation functions */ +/* 7.3.9.1 The carg functions */ +double carg(double complex); +float cargf(float complex); + +/* 7.3.9.2 The cimag functions */ +double cimag(double complex); +float cimagf(float complex); +long double cimagl(long double complex); + +/* 7.3.9.3 The conj functions */ +double complex conj(double complex); +float complex conjf(float complex); +/*long double complex conjl(long double complex); */ + +/* 7.3.9.4 The cproj functions */ +double complex cproj(double complex); +float complex cprojf(float complex); +/*long double complex cprojl(long double complex); */ + +/* 7.3.9.5 The creal functions */ +double creal(double complex); +float crealf(float complex); +long double creall(long double complex); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif /* ! _COMPLEX_H */ diff --git a/lib/mlibc/options/ansi/include/ctype.h b/lib/mlibc/options/ansi/include/ctype.h new file mode 100644 index 0000000..7cd1ec8 --- /dev/null +++ b/lib/mlibc/options/ansi/include/ctype.h @@ -0,0 +1,46 @@ +#ifndef _CTYPE_H +#define _CTYPE_H + +#include <mlibc-config.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +// Character classification function [7.4.1] +int isalnum(int c); +int isalpha(int c); +int isblank(int c); +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int isxdigit(int c); + +// glibc extensions. +int isascii(int c); + +// Character case mapping functions [7.4.2] +int tolower(int c); +int toupper(int c); + +#endif /* !__MLIBC_ABI_ONLY */ + +// Borrowed from glibc +#define toascii(c) ((c) & 0x7f) + +#ifdef __cplusplus +} +#endif + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_ctype.h> +#endif + +#endif // _CTYPE_H diff --git a/lib/mlibc/options/ansi/include/errno.h b/lib/mlibc/options/ansi/include/errno.h new file mode 100644 index 0000000..7730b16 --- /dev/null +++ b/lib/mlibc/options/ansi/include/errno.h @@ -0,0 +1,31 @@ +#ifndef _ERRNO_H +#define _ERRNO_H + +#include <abi-bits/errno.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +// Some programs define their own errno as an "extern int" if it is not a macro. +#define errno __mlibc_errno +extern __thread int __mlibc_errno; + +int *__errno_location(void); + +// Linux extensions. + +extern char *program_invocation_name; +extern char *program_invocation_short_name; +extern char *__progname; +extern char *__progname_full; + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _ERRNO_H diff --git a/lib/mlibc/options/ansi/include/fenv.h b/lib/mlibc/options/ansi/include/fenv.h new file mode 100644 index 0000000..11e38f3 --- /dev/null +++ b/lib/mlibc/options/ansi/include/fenv.h @@ -0,0 +1,44 @@ + +#ifndef _FENV_H +#define _FENV_H + +#include <bits/types.h> +#include <bits/ansi/fenv.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + __mlibc_uint32 __control_word; + __mlibc_uint32 __status_word; + __mlibc_uint32 __unused[5]; + __mlibc_uint32 __mxcsr; +} fenv_t; + +typedef __mlibc_uint16 fexcept_t; + +#ifndef __MLIBC_ABI_ONLY + +int feclearexcept(int); +int fegetenv(fenv_t *); +int fegetexceptflag(fexcept_t *, int); +int fegetround(void); +int feholdexcept(fenv_t *); +int feraiseexcept(int); +int fesetenv(const fenv_t *); +int fesetexceptflag(const fexcept_t *, int); +int fesetround(int); +int fetestexcept(int); +int feupdateenv(const fenv_t *); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#define FE_DFL_ENV ((const fenv_t *) -1) + +#endif // _FENV_H + diff --git a/lib/mlibc/options/ansi/include/inttypes.h b/lib/mlibc/options/ansi/include/inttypes.h new file mode 100644 index 0000000..5495440 --- /dev/null +++ b/lib/mlibc/options/ansi/include/inttypes.h @@ -0,0 +1,146 @@ +#ifndef _STDINT_H +#define _STDINT_H + +#include <stdint.h> + +/* Even though this is not strictly not-ABI, it is mlibc-printf specific therefore */ +/* gate behind !__MLIBC_ABI_ONLY */ +#ifndef __MLIBC_ABI_ONLY + +#if UINTPTR_MAX == UINT64_MAX +# define __PRI64 "l" +# define __PRIPTR "l" +#else +# define __PRI64 "ll" +# define __PRIPTR "" +#endif + +// TODO: This is extremly unelegant and fragile. +#define PRId8 "d" +#define PRIi8 "i" +#define PRIdLEAST8 "d" +#define PRIiLEAST8 "i" +#define PRIdFAST8 "d" +#define PRIiFAST8 "i" +#define PRId16 "d" +#define PRIi16 "i" +#define PRIdLEAST16 "d" +#define PRIiLEAST16 "i" +#define PRIdFAST16 "ld" +#define PRIiFAST16 "li" +#define PRId32 "d" +#define PRIi32 "i" +#define PRIdLEAST32 "d" +#define PRIiLEAST32 "i" +#define PRIdFAST32 "ld" +#define PRIiFAST32 "li" +#define PRId64 __PRI64 "d" +#define PRIi64 __PRI64 "i" +#define PRIdLEAST64 __PRI64 "d" +#define PRIiLEAST64 __PRI64 "i" +#define PRIdFAST64 __PRI64 "d" +#define PRIiFAST64 __PRI64 "i" +#define PRIdMAX __PRI64 "d" +#define PRIiMAX __PRI64 "i" +#define PRIdPTR __PRIPTR "d" +#define PRIiPTR __PRIPTR "i" +#define PRIo8 "o" +#define PRIu8 "u" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIoLEAST8 "o" +#define PRIuLEAST8 "u" +#define PRIxLEAST8 "x" +#define PRIXLEAST8 "X" +#define PRIoFAST8 "o" +#define PRIuFAST8 "u" +#define PRIxFAST8 "x" +#define PRIXFAST8 "X" +#define PRIo16 "o" +#define PRIu16 "u" +#define PRIx16 "x" +#define PRIX16 "X" +#define PRIoLEAST16 "o" +#define PRIuLEAST16 "u" +#define PRIxLEAST16 "x" +#define PRIXLEAST16 "X" +#define PRIoFAST16 "lo" +#define PRIuFAST16 "lu" +#define PRIxFAST16 "lx" +#define PRIXFAST16 "lX" +#define PRIo32 "o" +#define PRIu32 "u" +#define PRIx32 "x" +#define PRIX32 "X" +#define PRIoLEAST32 "o" +#define PRIuLEAST32 "u" +#define PRIxLEAST32 "x" +#define PRIXLEAST32 "X" +#define PRIoFAST32 "lo" +#define PRIuFAST32 "lu" +#define PRIxFAST32 "lx" +#define PRIXFAST32 "lX" +#define PRIo64 __PRI64 "o" +#define PRIu64 __PRI64 "u" +#define PRIx64 __PRI64 "x" +#define PRIX64 __PRI64 "X" +#define PRIoLEAST64 __PRI64 "o" +#define PRIuLEAST64 __PRI64 "u" +#define PRIxLEAST64 __PRI64 "x" +#define PRIXLEAST64 __PRI64 "X" +#define PRIoFAST64 __PRI64 "o" +#define PRIuFAST64 __PRI64 "u" +#define PRIxFAST64 __PRI64 "x" +#define PRIXFAST64 __PRI64 "X" +#define PRIoMAX __PRI64 "o" +#define PRIuMAX __PRI64 "u" +#define PRIxMAX __PRI64 "x" +#define PRIXMAX __PRI64 "X" +#define PRIoPTR __PRIPTR "o" +#define PRIuPTR __PRIPTR "u" +#define PRIxPTR __PRIPTR "x" +#define PRIXPTR __PRIPTR "X" + +#define SCNu32 "u" +#define SCNu64 __PRI64 "u" +#define SCNuMAX __PRI64 "u" +#define SCNx16 "hx" +#define SCNx32 "x" +#define SCNx64 __PRI64 "x" +#define SCNxMAX __PRI64 "x" +#define SCNi8 "hhi" +#define SCNxPTR __PRIPTR "x" + +#define SCNi8 "hhi" +#define SCNi64 __PRI64 "i" + +#define SCNd32 "d" +#define SCNd64 __PRI64 "d" + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +#ifndef __MLIBC_ABI_ONLY + +intmax_t imaxabs(intmax_t); +imaxdiv_t imaxdiv(intmax_t, intmax_t); +intmax_t strtoimax(const char *__restrict, char **__restrict, int); +uintmax_t strtoumax(const char *__restrict, char **__restrict, int); +intmax_t wcstoimax(const __WCHAR_TYPE__ *__restrict, __WCHAR_TYPE__ **__restrict, int); +uintmax_t wcstoumax(const __WCHAR_TYPE__ *__restrict, __WCHAR_TYPE__ **__restrict, int); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _STDINT_H diff --git a/lib/mlibc/options/ansi/include/limits.h b/lib/mlibc/options/ansi/include/limits.h new file mode 100644 index 0000000..86b786e --- /dev/null +++ b/lib/mlibc/options/ansi/include/limits.h @@ -0,0 +1,117 @@ +#ifndef _LIMITS_H +#define _LIMITS_H + +#define CHAR_BIT 8 + +#ifndef MB_LEN_MAX +# define MB_LEN_MAX 4 +#endif + +#ifdef LONG_MAX +# ifdef LONG_MAX == INT32_MAX +# define LONG_BIT 32 +# else +// Safe assumption +# define LONG_BIT 64 +# endif +#elif defined __LONG_MAX__ +# if __LONG_MAX__ == INT32_MAX +# define LONG_BIT 32 +# else +// Safe assumption +# define LONG_BIT 64 +# endif +#else +# error "Unsupported configuration, please define either LONG_MAX or __LONG_MAX__" +#endif + +#undef SCHAR_MIN +#undef SCHAR_MAX +#undef CHAR_MIN +#undef CHAR_MAX +#undef UCHAR_MAX +#undef SHRT_MIN +#undef SHRT_MAX +#undef USHRT_MAX +#undef INT_MIN +#undef INT_MAX +#undef UINT_MAX +#undef LONG_MIN +#undef LONG_MAX +#undef ULONG_MAX +#undef LLONG_MIN +#undef LLONG_MAX +#undef ULLONG_MAX + +#define SCHAR_MIN (-__SCHAR_MAX__ - 1) +#define SCHAR_MAX __SCHAR_MAX__ +#if __SCHAR_MAX__ == __INT_MAX__ +# define UCHAR_MAX (__SCHAR_MAX__ * 2U + 1U) +#else +# define UCHAR_MAX (__SCHAR_MAX__ * 2 + 1) +#endif + +#ifdef __CHAR_UNSIGNED__ +# define CHAR_MAX UCHAR_MAX +# if __SCHAR_MAX__ == __INT_MAX__ +# define CHAR_MIN 0U +# else +# define CHAR_MIN 0 +# endif +#else +# define CHAR_MAX SCHAR_MAX +# define CHAR_MIN SCHAR_MIN +#endif + +#define SHRT_MIN (-__SHRT_MAX__ - 1) +#define SHRT_MAX __SHRT_MAX__ +#if __SHRT_MAX_ == __INT_MAX__ +# define USHRT_MAX (__SHRT_MAX__ * 2U + 1U) +#else +# define USHRT_MAX (__SHRT_MAX__ * 2 + 1) +#endif + +#define INT_MIN (-__INT_MAX__ - 1) +#define INT_MAX __INT_MAX__ +#define UINT_MAX (__INT_MAX__ * 2 + 1) + +#define LONG_MIN (-__LONG_MAX__ - 1L) +#define LONG_MAX __LONG_MAX__ +#define ULONG_MAX (__LONG_MAX__ * 2UL + 1UL) + +#define LLONG_MIN (-__LONG_LONG_MAX__ - 1LL) +#define LLONG_MAX __LONG_LONG_MAX__ +#define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1ULL) + +#define NAME_MAX 255 +#define PATH_MAX 4096 +#define LINE_MAX 4096 +#define PIPE_BUF 4096 + +#define CHARCLASS_NAME_MAX 14 +#define RE_DUP_MAX 255 + +// This value is a guaranteed minimum, get the current maximum from sysconf +#define NGROUPS_MAX 8 +// POSIX states 9 is the minimum for NL_ARGMAX +#define NL_ARGMAX 9 + +#if INTPTR_MAX == INT64_MAX +# define SSIZE_MAX LONG_MAX +#elif INTPTR_MAX == INT32_MAX +# define SSIZE_MAX INT_MAX +#endif + +#define _POSIX_ARG_MAX 4096 +#define _POSIX_OPEN_MAX 16 +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_NAME_MAX 14 +#define _POSIX_TZNAME_MAX 6 +#define _XOPEN_NAME_MAX 255 + +#define PTHREAD_STACK_MIN 16384 +#define PTHREAD_KEYS_MAX 1024 + +#include <abi-bits/limits.h> + +#endif // _LIMITS_H diff --git a/lib/mlibc/options/ansi/include/locale.h b/lib/mlibc/options/ansi/include/locale.h new file mode 100644 index 0000000..3b4773d --- /dev/null +++ b/lib/mlibc/options/ansi/include/locale.h @@ -0,0 +1,81 @@ + +#ifndef _LOCALE_H +#define _LOCALE_H + +#include <mlibc-config.h> + +#include <bits/null.h> + +#define LC_ALL 1 +#define LC_COLLATE 2 +#define LC_CTYPE 3 +#define LC_MONETARY 4 +#define LC_NUMERIC 5 +#define LC_TIME 6 +#define LC_MESSAGES 7 + +#define LC_GLOBAL_LOCALE ((locale_t) -1L) + +#define LC_CTYPE_MASK (1<<LC_CTYPE) +#define LC_NUMERIC_MASK (1<<LC_NUMERIC) +#define LC_TIME_MASK (1<<LC_TIME) +#define LC_COLLATE_MASK (1<<LC_COLLATE) +#define LC_MONETARY_MASK (1<<LC_MONETARY) +#define LC_MESSAGES_MASK (1<<LC_MESSAGES) +#define LC_ALL_MASK 0x7FFFFFFF + +#ifdef __cplusplus +extern "C" { +#endif + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char *currency_symbol; + char frac_digits; + char p_cs_precedes; + char n_cs_precedes; + char p_sep_by_space; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char *int_curr_symbol; + char int_frac_digits; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + +#ifndef __MLIBC_ABI_ONLY + +// [C11/7.11.1] setlocale() function + +char *setlocale(int category, const char *locale); + +// [C11/7.11.2] Locale inquiry function + +struct lconv *localeconv(void); + +#endif /* !__MLIBC_ABI_ONLY */ + +// posix extension + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_locale.h> +#endif // __MLIBC_POSIX_OPTION + +#ifdef __cplusplus +} +#endif + +#endif // _LOCALE_H + diff --git a/lib/mlibc/options/ansi/include/math.h b/lib/mlibc/options/ansi/include/math.h new file mode 100644 index 0000000..7d7ab3c --- /dev/null +++ b/lib/mlibc/options/ansi/include/math.h @@ -0,0 +1,383 @@ + +#ifndef _MATH_H +#define _MATH_H + +#include <bits/inline-definition.h> + +// this is a posix extension +#define M_E 2.7182818284590452354 +#define M_LOG2E 1.4426950408889634074 +#define M_LOG10E 0.43429448190325182765 +#define M_LN2 0.69314718055994530942 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.70710678118654752440 +#define M_PIl 3.141592653589793238462643383279502884L + +// The following two definitions are from musl. +#define FP_ILOGBNAN (-1 - (int)(((unsigned)-1) >> 1)) +#define FP_ILOGB0 FP_ILOGBNAN + +#ifdef __cplusplus +extern "C" { +#endif + +typedef double double_t; +typedef float float_t; + +#define HUGE_VAL (__builtin_huge_val()) +#define HUGE_VALF (__builtin_huge_valf()) +#define HUGE_VALL (__builtin_huge_vall()) +#define INFINITY (__builtin_inff()) +#define NAN (__builtin_nanf("")) + +// [C11/7.12.1 Treatment of error conditions] + +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 +#define math_errhandling 3 + +// [C11/7.12.3 Classification macros] + +// NOTE: fpclassify always returns exactly one of those constants +// However making them bitwise disjoint simplifies isfinite() etc. +#define FP_INFINITE 1 +#define FP_NAN 2 +#define FP_NORMAL 4 +#define FP_SUBNORMAL 8 +#define FP_ZERO 16 + +#ifndef __MLIBC_ABI_ONLY + +int __fpclassify(double x); +int __fpclassifyf(float x); +int __fpclassifyl(long double x); + +#define fpclassify(x) \ + (sizeof(x) == sizeof(double) ? __fpclassify(x) : \ + (sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ + (sizeof(x) == sizeof(long double) ? __fpclassifyl(x) : \ + 0))) + +#define isfinite(x) (fpclassify(x) & (FP_NORMAL | FP_SUBNORMAL | FP_ZERO)) +#define isnan(x) (fpclassify(x) == FP_NAN) +#define isinf(x) (fpclassify(x) == FP_INFINITE) +#define isnormal(x) (fpclassify(x) == FP_NORMAL) + +// FIXME: this is gcc specific +#define signbit(x) (__builtin_signbit(x)) + +// [C11/7.12.14 Comparison macros] +#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) + +__MLIBC_INLINE_DEFINITION int __mlibc_isless(double_t x, double_t y) { return !isunordered(x, y) && x < y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessf(float_t x, float_t y) { return !isunordered(x, y) && x < y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessl(long double x, long double y) { return !isunordered(x, y) && x < y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessequal(double_t x, double_t y) { return !isunordered(x, y) && x <= y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessequalf(float_t x, float_t y) { return !isunordered(x, y) && x <= y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessequall(long double x, long double y) { return !isunordered(x, y) && x <= y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessgreater(double_t x, double_t y) { return !isunordered(x, y) && x != y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessgreaterf(float_t x, float_t y) { return !isunordered(x, y) && x != y; } +__MLIBC_INLINE_DEFINITION int __mlibc_islessgreaterl(long double x, long double y) { return !isunordered(x, y) && x != y; } +__MLIBC_INLINE_DEFINITION int __mlibc_isgreater(double_t x, double_t y) { return !isunordered(x, y) && x > y; } +__MLIBC_INLINE_DEFINITION int __mlibc_isgreaterf(float_t x, float_t y) { return !isunordered(x, y) && x > y; } +__MLIBC_INLINE_DEFINITION int __mlibc_isgreaterl(long double x, long double y) { return !isunordered(x, y) && x > y; } +__MLIBC_INLINE_DEFINITION int __mlibc_isgreaterequal(double_t x, double_t y) { return !isunordered(x, y) && x >= y; } +__MLIBC_INLINE_DEFINITION int __mlibc_isgreaterequalf(float_t x, float_t y) { return !isunordered(x, y) && x >= y; } +__MLIBC_INLINE_DEFINITION int __mlibc_isgreaterequall(long double x, long double y) { return !isunordered(x, y) && x >= y; } + +// TODO: We chould use _Generic here but that does not work in C++ code. +#define __MLIBC_CHOOSE_COMPARISON(x, y, p) ( \ + sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ + sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ + p##l(x, y) ) + +#define isless(x, y) __MLIBC_CHOOSE_COMPARISON(x, y, __mlibc_isless) +#define islessequal(x, y) __MLIBC_CHOOSE_COMPARISON(x, y, __mlibc_islessequal) +#define islessgreater(x, y) __MLIBC_CHOOSE_COMPARISON(x, y, __mlibc_islessgreater) +#define isgreater(x, y) __MLIBC_CHOOSE_COMPARISON(x, y, __mlibc_isgreater) +#define isgreaterequal(x, y) __MLIBC_CHOOSE_COMPARISON(x, y, __mlibc_isgreaterequal) + +// this is a gnu extension +void sincos(double, double *, double *); +void sincosf(float, float *, float *); +void sincosl(long double, long double *, long double *); + +double exp10(double); +float exp10f(float); +long double exp10l(long double); + +double pow10(double); +float pow10f(float); +long double pow10l(long double); + +// [C11/7.12.4 Trigonometric functions] + +double acos(double x); +float acosf(float x); +long double acosl(long double x); + +double asin(double x); +float asinf(float x); +long double asinl(long double x); + +double atan(double x); +float atanf(float x); +long double atanl(long double x); + +double atan2(double x, double y); +float atan2f(float x, float y); +long double atan2l(long double x, long double y); + +double cos(double x); +float cosf(float x); +long double cosl(long double x); + +double sin(double x); +float sinf(float x); +long double sinl(long double x); + +double tan(double x); +float tanf(float x); +long double tanl(long double x); + +// [C11/7.12.5 Hyperbolic functions] + +double acosh(double x); +float acoshf(float x); +long double acoshl(long double x); + +double asinh(double x); +float asinhf(float x); +long double asinhl(long double x); + +double atanh(double x); +float atanhf(float x); +long double atanhl(long double x); + +double cosh(double x); +float coshf(float x); +long double coshl(long double x); + +double sinh(double x); +float sinhf(float x); +long double sinhl(long double x); + +double tanh(double x); +float tanhf(float x); +long double tanhl(long double x); + +// [C11/7.12.6 Exponential and logarithmic functions] + +double exp(double x); +float expf(float x); +long double expl(long double x); + +double exp2(double x); +float exp2f(float x); +long double exp2l(long double x); + +double expm1(double x); +float expm1f(float x); +long double expm1l(long double x); + +double frexp(double x, int *power); +float frexpf(float x, int *power); +long double frexpl(long double x, int *power); + +int ilogb(double x); +int ilogbf(float x); +int ilogbl(long double x); + +double ldexp(double x, int power); +float ldexpf(float x, int power); +long double ldexpl(long double x, int power); + +double log(double x); +float logf(float x); +long double logl(long double x); + +double log10(double x); +float log10f(float x); +long double log10l(long double x); + +double log1p(double x); +float log1pf(float x); +long double log1pl(long double x); + +double log2(double x); +float log2f(float x); +long double log2l(long double x); + +double logb(double x); +float logbf(float x); +long double logbl(long double x); + +double modf(double x, double *integral); +float modff(float x, float *integral); +long double modfl(long double x, long double *integral); + +double scalbn(double x, int power); +float scalbnf(float x, int power); +long double scalbnl(long double x, int power); + +double scalbln(double x, long power); +float scalblnf(float x, long power); +long double scalblnl(long double x, long power); + +// [C11/7.12.7 Power and absolute-value functions] + +double cbrt(double x); +float cbrtf(float x); +long double cbrtl(long double x); + +double fabs(double x); +float fabsf(float x); +long double fabsl(long double x); + +double hypot(double x, double y); +float hypotf(float x, float y); +long double hypotl(long double x, long double y); + +double pow(double x, double y); +float powf(float x, float y); +long double powl(long double x, long double y); + +double sqrt(double x); +float sqrtf(float x); +long double sqrtl(long double x); + +// [C11/7.12.8 Error and gamma functions] + +double erf(double x); +float erff(float x); +long double erfl(long double x); + +double erfc(double x); +float erfcf(float x); +long double erfcl(long double x); + +double lgamma(double x); +float lgammaf(float x); +long double lgammal(long double x); + +double tgamma(double x); +float tgammaf(float x); +long double tgammal(long double x); + +// [C11/7.12.9 Nearest integer functions] + +double ceil(double x); +float ceilf(float x); +long double ceill(long double x); + +double floor(double x); +float floorf(float x); +long double floorl(long double x); + +double nearbyint(double x); +float nearbyintf(float x); +long double nearbyintl(long double x); + +double rint(double x); +float rintf(float x); +long double rintl(long double x); + +long lrint(double x); +long lrintf(float x); +long lrintl(long double x); + +long long llrint(double x); +long long llrintf(float x); +long long llrintl(long double x); + +double round(double x); +float roundf(float x); +long double roundl(long double x); + +long lround(double x); +long lroundf(float x); +long lroundl(long double x); + +long long llround(double x); +long long llroundf(float x); +long long llroundl(long double x); + +double trunc(double x); +float truncf(float x); +long double truncl(long double x); + +// [C11/7.12.10 Remainder functions] + +double fmod(double x, double y); +float fmodf(float x, float y); +long double fmodl(long double x, long double y); + +double remainder(double x, double y); +float remainderf(float x, float y); +long double remainderl(long double x, long double y); + +double remquo(double x, double y, int *quotient); +float remquof(float x, float y, int *quotient); +long double remquol(long double x, long double y, int *quotient); + +// [C11/7.12.11 Manipulation functions] + +double copysign(double x, double sign); +float copysignf(float x, float sign); +long double copysignl(long double x, long double sign); + +double nan(const char *tag); +float nanf(const char *tag); +long double nanl(const char *tag); + +double nextafter(double x, double dir); +float nextafterf(float x, float dir); +long double nextafterl(long double x, long double dir); + +double nexttoward(double x, long double dir); +float nexttowardf(float x, long double dir); +long double nexttowardl(long double x, long double dir); + +// [C11/7.12.12 Maximum, minimum and positive difference functions] + +double fdim(double x, double y); +float fdimf(float x, float y); +long double fdiml(long double x, long double y); + +double fmax(double x, double y); +float fmaxf(float x, float y); +long double fmaxl(long double x, long double y); + +double fmin(double x, double y); +float fminf(float x, float y); +long double fminl(long double x, long double y); + +// [C11/7.12.13 Floating multiply-add] + +double fma(double, double, double); +float fmaf(float, float, float); +long double fmal(long double, long double, long double); + +extern int signgam; +#define __signgam signgam + +// BSD floating-point classification functions - obsolete + +int finite(double x); +int finitef(float x); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _MATH_H + diff --git a/lib/mlibc/options/ansi/include/mlibc/ansi-sysdeps.hpp b/lib/mlibc/options/ansi/include/mlibc/ansi-sysdeps.hpp new file mode 100644 index 0000000..203084e --- /dev/null +++ b/lib/mlibc/options/ansi/include/mlibc/ansi-sysdeps.hpp @@ -0,0 +1,71 @@ +#ifndef MLIBC_ANSI_SYSDEPS +#define MLIBC_ANSI_SYSDEPS + +#include <stddef.h> + +#include <abi-bits/seek-whence.h> +#include <abi-bits/vm-flags.h> +#include <abi-bits/pid_t.h> +#include <abi-bits/mode_t.h> +#include <bits/off_t.h> +#include <bits/ssize_t.h> +#include <bits/ansi/time_t.h> +#include <signal.h> +#include <stdarg.h> + +struct rusage; + +namespace [[gnu::visibility("hidden")]] mlibc { + +[[noreturn]] void sys_exit(int status); +[[noreturn, gnu::weak]] void sys_thread_exit(); + +// If *stack is not null, it should point to the lowest addressable byte of the stack. +// Returns the new stack pointer in *stack and the stack base in *stack_base. +[[gnu::weak]] int sys_prepare_stack(void **stack, void *entry, void *user_arg, void* tcb, size_t *stack_size, size_t *guard_size, void **stack_base); +[[gnu::weak]] int sys_clone(void *tcb, pid_t *pid_out, void *stack); + +int sys_futex_wait(int *pointer, int expected, const struct timespec *time); +int sys_futex_wake(int *pointer); + +int sys_open(const char *pathname, int flags, mode_t mode, int *fd); +[[gnu::weak]] int sys_flock(int fd, int options); + +[[gnu::weak]] int sys_open_dir(const char *path, int *handle); +[[gnu::weak]] int sys_read_entries(int handle, void *buffer, size_t max_size, + size_t *bytes_read); + +int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read); + +int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written); +[[gnu::weak]] int sys_pread(int fd, void *buf, size_t n, off_t off, ssize_t *bytes_read); + +int sys_seek(int fd, off_t offset, int whence, off_t *new_offset); +int sys_close(int fd); + +int sys_clock_get(int clock, time_t *secs, long *nanos); +[[gnu::weak]] int sys_clock_getres(int clock, time_t *secs, long *nanos); +[[gnu::weak]] int sys_sleep(time_t *secs, long *nanos); +// In contrast to the isatty() library function, the sysdep function uses return value +// zero (and not one) to indicate that the file is a terminal. +[[gnu::weak]] int sys_isatty(int fd); +[[gnu::weak]] int sys_rmdir(const char *path); +[[gnu::weak]] int sys_unlinkat(int dirfd, const char *path, int flags); +[[gnu::weak]] int sys_rename(const char *path, const char *new_path); +[[gnu::weak]] int sys_renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path); + +[[gnu::weak]] int sys_sigprocmask(int how, const sigset_t *__restrict set, + sigset_t *__restrict retrieve); +[[gnu::weak]] int sys_sigaction(int, const struct sigaction *__restrict, + struct sigaction *__restrict); + +[[gnu::weak]] int sys_fork(pid_t *child); +[[gnu::weak]] int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid); +[[gnu::weak]] int sys_execve(const char *path, char *const argv[], char *const envp[]); + +[[gnu::weak]] pid_t sys_getpid(); +[[gnu::weak]] int sys_kill(int, int); + +} //namespace mlibc + +#endif // MLIBC_ANSI_SYSDEPS diff --git a/lib/mlibc/options/ansi/include/mlibc/environment.hpp b/lib/mlibc/options/ansi/include/mlibc/environment.hpp new file mode 100644 index 0000000..7fd5cf9 --- /dev/null +++ b/lib/mlibc/options/ansi/include/mlibc/environment.hpp @@ -0,0 +1,10 @@ +#ifndef MLIBC_ENVIRONMENT_HPP +#define MLIBC_ENVIRONMENT_HPP + +namespace mlibc { + +int putenv(char *string); + +} // namespace mlibc + +#endif // MLIBC_ENVIRONMENT_HPP diff --git a/lib/mlibc/options/ansi/include/mlibc/file-io.hpp b/lib/mlibc/options/ansi/include/mlibc/file-io.hpp new file mode 100644 index 0000000..1155a2b --- /dev/null +++ b/lib/mlibc/options/ansi/include/mlibc/file-io.hpp @@ -0,0 +1,111 @@ +#ifndef MLIBC_FILE_IO_HPP +#define MLIBC_FILE_IO_HPP + +#include <stdio.h> + +#include <mlibc/lock.hpp> +#include <mlibc/allocator.hpp> +#include <frg/list.hpp> + +namespace mlibc { + +enum class stream_type { + unknown, + file_like, + pipe_like +}; + +enum class buffer_mode { + unknown, + no_buffer, + line_buffer, + full_buffer +}; + +struct abstract_file : __mlibc_file_base { +public: + abstract_file(void (*do_dispose)(abstract_file *) = nullptr); + + abstract_file(const abstract_file &) = delete; + + abstract_file &operator= (const abstract_file &) = delete; + + virtual ~abstract_file(); + + void dispose(); + + virtual int close() = 0; + virtual int reopen(const char *path, const char *mode) = 0; + + int read(char *buffer, size_t max_size, size_t *actual_size); + int write(const char *buffer, size_t max_size, size_t *actual_size); + int unget(char c); + + int update_bufmode(buffer_mode mode); + + void purge(); + int flush(); + + int tell(off_t *current_offset); + int seek(off_t offset, int whence); + +protected: + virtual int determine_type(stream_type *type) = 0; + virtual int determine_bufmode(buffer_mode *mode) = 0; + virtual int io_read(char *buffer, size_t max_size, size_t *actual_size) = 0; + virtual int io_write(const char *buffer, size_t max_size, size_t *actual_size) = 0; + virtual int io_seek(off_t offset, int whence, off_t *new_offset) = 0; + + int _reset(); +private: + int _init_type(); + int _init_bufmode(); + + int _write_back(); + int _save_pos(); + + void _ensure_allocation(); + + stream_type _type; + buffer_mode _bufmode; + void (*_do_dispose)(abstract_file *); + +public: + // lock for file operations + RecursiveFutexLock _lock; + // All files are stored in a global linked list, so that they can be flushed at exit(). + frg::default_list_hook<abstract_file> _list_hook; +}; + +struct fd_file : abstract_file { + fd_file(int fd, void (*do_dispose)(abstract_file *) = nullptr, bool force_unbuffered = false); + + int fd(); + + int close() override; + int reopen(const char *path, const char *mode) override; + + static int parse_modestring(const char *mode); + +protected: + int determine_type(stream_type *type) override; + int determine_bufmode(buffer_mode *mode) override; + + int io_read(char *buffer, size_t max_size, size_t *actual_size) override; + int io_write(const char *buffer, size_t max_size, size_t *actual_size) override; + int io_seek(off_t offset, int whence, off_t *new_offset) override; + +private: + // Underlying file descriptor. + int _fd; + bool _force_unbuffered; +}; + +template <typename T> +void file_dispose_cb(abstract_file *base) { + frg::destruct(getAllocator(), static_cast<T *>(base)); +} + +} // namespace mlibc + +#endif // MLIBC_FILE_IO_HPP diff --git a/lib/mlibc/options/ansi/include/setjmp.h b/lib/mlibc/options/ansi/include/setjmp.h new file mode 100644 index 0000000..30346f0 --- /dev/null +++ b/lib/mlibc/options/ansi/include/setjmp.h @@ -0,0 +1,48 @@ + +#ifndef _SETJMP_H +#define _SETJMP_H + +#include <mlibc-config.h> +#include <bits/machine.h> +#include <abi-bits/signal.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// [C11/7.13] Non-local jumps + +typedef struct __jmp_buf { + struct __mlibc_jmpbuf_register_state reg_state; +} jmp_buf[1]; + +#ifndef __MLIBC_ABI_ONLY + +__attribute__((__returns_twice__)) int setjmp(jmp_buf buffer); +__attribute__((__noreturn__)) void longjmp(jmp_buf buffer, int value); + +#endif /* !__MLIBC_ABI_ONLY */ + +// POSIX Non-local jumps signal extensions + +typedef struct __sigjmp_buf { + struct __mlibc_jmpbuf_register_state reg_state; + int savesigs; + sigset_t sigset; +} sigjmp_buf[1]; + +#ifndef __MLIBC_ABI_ONLY + +#if __MLIBC_POSIX_OPTION +__attribute__((__returns_twice__)) int sigsetjmp(sigjmp_buf buffer, int savesigs); +__attribute__((__noreturn__)) void siglongjmp(sigjmp_buf buffer, int value); +#endif // __MLIBC_POSIX_OPTION + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _SETJMP_H + diff --git a/lib/mlibc/options/ansi/include/signal.h b/lib/mlibc/options/ansi/include/signal.h new file mode 100644 index 0000000..e27592b --- /dev/null +++ b/lib/mlibc/options/ansi/include/signal.h @@ -0,0 +1,48 @@ +#ifndef _SIGNAL_H +#define _SIGNAL_H + +#include <abi-bits/signal.h> +#include <mlibc-config.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// [7.14] Signal handling basics + +typedef int sig_atomic_t; + +#define CLD_EXITED 1 +#define CLD_KILLED 2 +#define CLD_DUMPED 3 +#define CLD_TRAPPED 4 +#define CLD_STOPPED 5 +#define CLD_CONTINUED 6 + +#ifndef __MLIBC_ABI_ONLY + +// [7.14.1] signal() function + +__sighandler signal(int sig, __sighandler handler); + +// [7.14.2] raise() function + +int raise(int sig); + +#endif /* !__MLIBC_ABI_ONLY */ + +#define _NSIG NSIG + +#ifdef __cplusplus +} +#endif + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_signal.h> +#endif + +#if __MLIBC_GLIBC_OPTION +# include <bits/glibc/glibc_signal.h> +#endif + +#endif // _SIGNAL_H diff --git a/lib/mlibc/options/ansi/include/stdc-predef.h b/lib/mlibc/options/ansi/include/stdc-predef.h new file mode 100644 index 0000000..a0e3e92 --- /dev/null +++ b/lib/mlibc/options/ansi/include/stdc-predef.h @@ -0,0 +1,6 @@ +#ifndef _STDC_PREDEF_H +#define _STDC_PREDEF_H + +#define __STDC_ISO_10646__ 201206L + +#endif /* _STDC_PREDEF_H */ diff --git a/lib/mlibc/options/ansi/include/stdio.h b/lib/mlibc/options/ansi/include/stdio.h new file mode 100644 index 0000000..168a3c7 --- /dev/null +++ b/lib/mlibc/options/ansi/include/stdio.h @@ -0,0 +1,229 @@ + +#ifndef _STDIO_H +#define _STDIO_H + +#include <abi-bits/seek-whence.h> +#include <bits/null.h> +#include <bits/size_t.h> +#include <mlibc-config.h> + +// Glibc extensions require ssize_t. +#include <bits/ssize_t.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// [C11-7.21.1] I/O related types + +#define __MLIBC_EOF_BIT 1 +#define __MLIBC_ERROR_BIT 2 + +struct __mlibc_file_base { + // Buffer for I/O operations. + // We reserve a few extra bytes for ungetc operations. This means + // that __buffer_ptr will point a few bytes *into* the allocation. + char *__buffer_ptr; + + // Number of bytes the buffer can hold. + size_t __buffer_size; + + // Current offset inside the buffer. + size_t __offset; + + // Position inside the buffer that matches the current file pointer. + size_t __io_offset; + + // Valid region of the buffer. + size_t __valid_limit; + + // Begin and end of the dirty region inside the buffer. + size_t __dirty_begin; + size_t __dirty_end; + + // This points to the same place as __buffer_ptr, or a few bytes earlier + // if there are bytes pushed by ungetc. If buffering is disabled, calls + // to ungetc will trigger an allocation. + char *__unget_ptr; + + // 0 if we are currently reading from the buffer. + // 1 if we are currently writing to the buffer. + // This is only really important for pipe-like streams. + int __io_mode; + + // EOF and error bits. + int __status_bits; +}; + +typedef struct __mlibc_file_base FILE; +typedef size_t fpos_t; + +// [C11-7.21.1] I/O related macros + +#define _IOFBF 1 +#define _IOLBF 2 +#define _IONBF 3 + +#define BUFSIZ 512 + +#define EOF (-1) + +#define FOPEN_MAX 1024 +#define FILENAME_MAX 256 +#define L_tmpnam 256 + +#define TMP_MAX 1024 + +#ifndef __MLIBC_ABI_ONLY + +extern FILE *stderr; +extern FILE *stdin; +extern FILE *stdout; + +// [C11-7.21.4] Operations on files + +int remove(const char *filename); +int rename(const char *old_path, const char *new_path); +int renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path); +FILE *tmpfile(void); +char *tmpnam(char *buffer); + +// [C11-7.21.5] File access functions + +int fclose(FILE *stream); +int fflush(FILE *stream); +FILE *fopen(const char *__restrict filename, const char *__restrict mode); +FILE *freopen(const char *__restrict filename, const char *__restrict mode, FILE *__restrict stream); +void setbuf(FILE *__restrict stream, char *__restrict buffer); +int setvbuf(FILE *__restrict stream, char *__restrict buffer, int mode, size_t size); +void setlinebuf(FILE *stream); +void setbuffer(FILE *, char *, size_t); + +// [C11-7.21.6] Formatted input/output functions + +__attribute__((__format__(printf, 2, 3))) +int fprintf(FILE *__restrict stream, const char *__restrict format, ...); + +__attribute__((__format__(scanf, 2, 3))) +int fscanf(FILE *__restrict stream, const char *__restrict format, ...); + +__attribute__((__format__(printf, 1, 2))) +int printf(const char *__restrict format, ...); + +__attribute__((__format__(scanf, 1, 2))) +int scanf(const char *__restrict format, ...); + +__attribute__((__format__(printf, 3, 4))) +int snprintf(char *__restrict buffer, size_t max_size, const char *__restrict format, ...); + +__attribute__((__format__(printf, 2, 3))) +int sprintf(char *__restrict buffer, const char *__restrict format, ...); + +__attribute__((__format__(scanf, 2, 3))) +int sscanf(const char *__restrict buffer, const char *__restrict format, ...); + +__attribute__((__format__(printf, 2, 0))) +int vfprintf(FILE *__restrict stream, const char *__restrict format, __builtin_va_list args); + +__attribute__((__format__(scanf, 2, 0))) +int vfscanf(FILE *__restrict stream, const char *__restrict format, __builtin_va_list args); + +__attribute__((__format__(printf, 1, 0))) +int vprintf(const char *__restrict format, __builtin_va_list args); + +__attribute__((__format__(scanf, 1, 0))) +int vscanf(const char *__restrict format, __builtin_va_list args); + +__attribute__((__format__(printf, 3, 0))) +int vsnprintf(char *__restrict buffer, size_t max_size, + const char *__restrict format, __builtin_va_list args); + +__attribute__((__format__(printf, 2, 0))) +int vsprintf(char *__restrict buffer, const char *__restrict format, __builtin_va_list args); + +__attribute__((__format__(scanf, 2, 0))) +int vsscanf(const char *__restrict buffer, const char *__restrict format, __builtin_va_list args); + +// this is a gnu extension +__attribute__((__format__(printf, 2, 0))) +int vasprintf(char **, const char *, __builtin_va_list); + +// [C11-7.21.7] Character input/output functions + +int fgetc(FILE *stream); +char *fgets(char *__restrict buffer, size_t max_size, FILE *__restrict stream); +int fputc(int c, FILE *stream); +int fputs(const char *__restrict string, FILE *__restrict stream); +char *gets(char *s); +int getc(FILE *stream); +int getchar(void); +int putc(int c, FILE *stream); +int putchar(int c); +int puts(const char *string); +int ungetc(int c, FILE *stream); + +// [C11-7.21.8] Direct input/output functions + +size_t fread(void *__restrict buffer, size_t size, size_t count, FILE *__restrict stream); +size_t fwrite(const void *__restrict buffer, size_t size, size_t count, FILE *__restrict stream); + +// [C11-7.21.9] File positioning functions + +int fgetpos(FILE *__restrict stream, fpos_t *__restrict position); +int fseek(FILE *stream, long offset, int whence); +int fsetpos(FILE *stream, const fpos_t *position); +long ftell(FILE *stream); +void rewind(FILE *stream); + +// [C11-7.21.10] Error handling functions + +void clearerr(FILE *stream); +int feof(FILE *stream); +int ferror(FILE *stream); +void perror(const char *string); + +// POSIX unlocked I/O extensions. + +int getc_unlocked(FILE *); +int getchar_unlocked(void); +int putc_unlocked(int, FILE *); +int putchar_unlocked(int); + +// GLIBC extensions. + +ssize_t getline(char **, size_t *, FILE *); +ssize_t getdelim(char **, size_t *, int, FILE *); + +int asprintf(char **, const char *, ...); + +// Linux unlocked I/O extensions. + +void flockfile(FILE *); +void funlockfile(FILE *); +int ftrylockfile(FILE *); + +void clearerr_unlocked(FILE *); +int feof_unlocked(FILE *); +int ferror_unlocked(FILE *); +int fileno_unlocked(FILE *); +int fflush_unlocked(FILE *); +int fgetc_unlocked(FILE *); +int fputc_unlocked(int, FILE *); +size_t fread_unlocked(void *__restrict, size_t, size_t, FILE *__restrict); +size_t fwrite_unlocked(const void *__restrict, size_t, size_t, FILE *__restrict); + +char *fgets_unlocked(char *, int, FILE *); +int fputs_unlocked(const char *, FILE *); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_stdio.h> +#endif + +#endif // _STDIO_H + diff --git a/lib/mlibc/options/ansi/include/stdlib.h b/lib/mlibc/options/ansi/include/stdlib.h new file mode 100644 index 0000000..d0e916a --- /dev/null +++ b/lib/mlibc/options/ansi/include/stdlib.h @@ -0,0 +1,128 @@ +#ifndef _STDLIB_H +#define _STDLIB_H + +#include <alloca.h> +#include <mlibc-config.h> +#include <bits/null.h> +#include <bits/size_t.h> +#include <bits/wchar_t.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// [7.22] General utilities + +typedef struct { + int quot, rem; +} div_t; + +typedef struct { + long quot, rem; +} ldiv_t; + +typedef struct { + long long quot, rem; +} lldiv_t; + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 0x7FFFFFFF + +// TODO: this should not be a compile-time constant +#define MB_CUR_MAX 4 + +#ifndef __MLIBC_ABI_ONLY + +// [7.22.1] Numeric conversion functions + +double atof(const char *string); +int atoi(const char *string); +long atol(const char *string); +long long atoll(const char *string); +double strtod(const char *__restrict string, char **__restrict end); +float strtof(const char *__restrict string, char **__restrict end); +long double strtold(const char *__restrict string, char **__restrict end); +long strtol(const char *__restrict string, char **__restrict end, int base); +long long strtoll(const char *__restrict string, char **__restrict end, int base); +unsigned long strtoul(const char *__restrict string, char **__restrict end, int base); +unsigned long long strtoull(const char *__restrict string, char **__restrict end, int base); + +// [7.22.2] Pseudo-random sequence generation functions + +int rand(void); +int rand_r(unsigned *); +void srand(unsigned int); + +// [7.22.3] Memory management functions + +void *aligned_alloc(size_t alignment, size_t size); +void *calloc(size_t count, size_t size); +void free(void *pointer); +void *malloc(size_t size); +void *realloc(void *pointer, size_t size); + +int posix_memalign(void **, size_t, size_t); + +// [7.22.4] Communication with the environment + +__attribute__((__noreturn__)) void abort(void); +int atexit(void (*func)(void)); +int at_quick_exit(void (*func)(void)); +__attribute__((__noreturn__)) void exit(int status); +__attribute__((__noreturn__)) void _Exit(int status); +char *getenv(const char *name); +__attribute__((__noreturn__)) void quick_exit(int status); +int system(const char *string); + +// GLIBC extension. +char *mktemp(char *); + +// [7.22.5] Searching and sorting utilities + +void *bsearch(const void *key, const void *base, size_t count, size_t size, + int (*compare)(const void *, const void *)); +void qsort(void *base, size_t count, size_t size, + int (*compare)(const void *, const void *)); +void qsort_r(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *, void *), + void *arg); + +// [7.22.6] Integer arithmetic functions + +int abs(int number); +long labs(long number); +long long llabs(long long number); + +div_t div(int number, int denom); +ldiv_t ldiv(long number, long denom); +lldiv_t lldiv(long long number, long long denom); + +// [7.22.7] Multibyte character conversion functions + +int mblen(const char *, size_t); +int mbtowc(wchar_t *__restrict wc, const char *__restrict mb_chr, size_t max_size); +int wctomb(char *mb_chr, wchar_t wc); + +// [7.22.8] Multibyte string conversion functions + +size_t mbstowcs(wchar_t *__restrict wc_string, const char *__restrict mb_string, size_t max_size); +size_t wcstombs(char *mb_string, const wchar_t *__restrict wc_string, size_t max_size); + +#endif /* !__MLIBC_ABI_ONLY */ + +#if __MLIBC_GLIBC_OPTION +typedef int (*comparison_fn_t) (const void *, const void *); +#endif + +#ifdef __cplusplus +} +#endif + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_stdlib.h> +#endif + +#endif // _STDLIB_H + diff --git a/lib/mlibc/options/ansi/include/string.h b/lib/mlibc/options/ansi/include/string.h new file mode 100644 index 0000000..5297e36 --- /dev/null +++ b/lib/mlibc/options/ansi/include/string.h @@ -0,0 +1,107 @@ +#ifndef _STRING_H +#define _STRING_H + +#include <mlibc-config.h> +#include <bits/null.h> +#include <bits/size_t.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +// [7.24.2] Copying functions + +void *memcpy(void *__restrict dest, const void *__restrict src, size_t size); +void *memmove(void *dest, const void *src, size_t size); +char *strcpy(char *__restrict dest, const char *src); +char *strncpy(char *__restrict dest, const char *src, size_t max_size); + +// [7.24.3] Concatenation functions + +char *strcat(char *__restrict dest, const char *__restrict src); +char *strncat(char *__restrict dest, const char *__restrict src, size_t max_size); + +// [7.24.4] Comparison functions + +int memcmp(const void *a, const void *b, size_t size); +int strcmp(const char *a, const char *b); +int strcoll(const char *a, const char *b); +int strncmp(const char *a, const char *b, size_t max_size); +size_t strxfrm(char *__restrict dest, const char *__restrict src, size_t max_size); + +// [7.24.5] Search functions + +void *memchr(const void *s, int c, size_t size); +char *strchr(const char *s, int c); +size_t strcspn(const char *s, const char *chrs); +char *strpbrk(const char *s, const char *chrs); +char *strrchr(const char *s, int c); +size_t strspn(const char *s, const char *chrs); +char *strstr(const char *pattern, const char *s); +char *strtok(char *__restrict s, const char *__restrict delimiter); + +// This is a GNU extension. +char *strchrnul(const char *, int); + +// [7.24.6] Miscellaneous functions + +void *memset(void *dest, int c, size_t size); +char *strerror(int errnum); +size_t strlen(const char *s); + +#endif /* !__MLIBC_ABI_ONLY */ + +#if __MLIBC_POSIX_OPTION && (defined(_BSD_SOURCE) || defined(_GNU_SOURCE)) +#include <strings.h> +#endif + +#ifndef __MLIBC_ABI_ONLY + +// POSIX extensions. +int strerror_r(int, char *, size_t); +void *mempcpy(void *, const void *, size_t); + +// GNU extensions. +int strverscmp(const char *l0, const char *r0); +int ffsl(long i); +int ffsll(long long i); +void *memmem(const void *, size_t, const void *, size_t); + +/* Handling the basename mess: + * If <libgen.h> is included *at all*, we use the XPG-defined basename + * implementation, otherwise, we use the GNU one. Since our ABI previously + * provided the XPG one under basename, we'll have to diverge from GNU here and + * provide __mlibc_gnu_basename instead. + */ +#if __MLIBC_GLIBC_OPTION && defined(_GNU_SOURCE) && !defined(basename) +char *__mlibc_gnu_basename_c(const char *path); + +# ifdef __cplusplus +extern "C++" { +static inline const char *__mlibc_gnu_basename(const char *path) { + return __mlibc_gnu_basename_c(path); +} +static inline char *__mlibc_gnu_basename(char *path) { + return __mlibc_gnu_basename_c(path); +} +} +# else +# define __mlibc_gnu_basename __mlibc_gnu_basename_c +# endif + +#define basename __mlibc_gnu_basename +#endif + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_string.h> +#endif + +#endif // _STRING_H diff --git a/lib/mlibc/options/ansi/include/threads.h b/lib/mlibc/options/ansi/include/threads.h new file mode 100644 index 0000000..f96abcd --- /dev/null +++ b/lib/mlibc/options/ansi/include/threads.h @@ -0,0 +1,61 @@ +#ifndef _THREADS_H +#define _THREADS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <bits/threads.h> + +enum { + mtx_plain, + mtx_recursive, + mtx_timed, +}; + +enum { + thrd_success, + thrd_timedout, + thrd_busy, + thrd_error, + thrd_nomem, +}; + +typedef struct __mlibc_thread_data *thrd_t; +typedef struct __mlibc_mutex mtx_t; +typedef struct __mlibc_cond cnd_t; +#ifndef __cplusplus +#define thread_local _Thread_local +#endif + +typedef int (*thrd_start_t)(void*); + +#ifndef __MLIBC_ABI_ONLY + +int thrd_create(thrd_t *thr, thrd_start_t func, void *arg); +int thrd_equal(thrd_t lhs, thrd_t rhs); +thrd_t thrd_current(void); +int thrd_sleep(const struct timespec *duration, struct timespec *remaining); +void thrd_yield(void); +int thrd_detach(thrd_t thr); +int thrd_join(thrd_t thr, int *res); +__attribute__((__noreturn__)) void thrd_exit(int res); + +int mtx_init(mtx_t *mtx, int type); +void mtx_destroy(mtx_t *mtx); +int mtx_lock(mtx_t *mtx); +int mtx_unlock(mtx_t *mtx); + +int cnd_init(cnd_t *cond); +void cnd_destroy(cnd_t *cond); +int cnd_broadcast(cnd_t *cond); +int cnd_wait(cnd_t *cond, mtx_t *mtx); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif /* _THREADS_H */ + diff --git a/lib/mlibc/options/ansi/include/time.h b/lib/mlibc/options/ansi/include/time.h new file mode 100644 index 0000000..a3239e9 --- /dev/null +++ b/lib/mlibc/options/ansi/include/time.h @@ -0,0 +1,154 @@ +#ifndef _TIME_H +#define _TIME_H + +#include <bits/null.h> +#include <bits/size_t.h> +#include <bits/ansi/time_t.h> +#include <bits/ansi/timespec.h> +#include <mlibc-config.h> + +// [7.27.1] Components of time + +#define CLOCKS_PER_SEC ((clock_t)1000000) + +#define TIME_UTC 1 + +// POSIX extensions. + +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 +#define CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOCK_THREAD_CPUTIME_ID 3 +#define CLOCK_MONOTONIC_RAW 4 +#define CLOCK_REALTIME_COARSE 5 +#define CLOCK_MONOTONIC_COARSE 6 +#define CLOCK_BOOTTIME 7 +#define CLOCK_REALTIME_ALARM 8 +#define CLOCK_BOOTTIME_ALARM 9 + +#ifdef __cplusplus +extern "C" { +#endif + +// [7.27.1] Components of time + +typedef long clock_t; // Matches Linux' ABI. + +struct tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; + long int tm_gmtoff; + const char *tm_zone; +}; + +#ifndef __MLIBC_ABI_ONLY + +// [7.27.2] Time manipulation functions + +clock_t clock(void); +double difftime(time_t a, time_t b); +time_t mktime(struct tm *ptr); +time_t time(time_t *timer); +int timespec_get(struct timespec *ptr, int base); + +// [7.27.3] Time conversion functions + +char *asctime(const struct tm *ptr); +char *ctime(const time_t *timer); +struct tm *gmtime(const time_t *timer); +struct tm *gmtime_r(const time_t *__restrict timer, struct tm *__restrict result); +struct tm *localtime(const time_t *timer); +size_t strftime(char *__restrict dest, size_t max_size, + const char *__restrict format, const struct tm *__restrict ptr); + +void tzset(void); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +// POSIX extensions. + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_time.h> +# include <bits/posix/timer_t.h> +#endif // __MLIBC_POSIX_OPTION + +#include <abi-bits/clockid_t.h> + +#define TIMER_ABSTIME 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +extern int daylight; +extern long timezone; +extern char *tzname[2]; + +int nanosleep(const struct timespec *, struct timespec *); + +int clock_getres(clockid_t, struct timespec *); +int clock_gettime(clockid_t, struct timespec *); +int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); +int clock_settime(clockid_t, const struct timespec *); + +struct tm *localtime_r(const time_t *, struct tm *); +char *asctime_r(const struct tm *tm, char *buf); +char *ctime_r(const time_t *, char *); + +#if __MLIBC_POSIX_OPTION +char *strptime(const char *__restrict, const char *__restrict, + struct tm *__restrict); +#endif /* __MLIBC_POSIX_OPTION */ + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +// GNU extensions. + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +time_t timelocal(struct tm *); +time_t timegm(struct tm *); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +// Linux extensions. + +#ifdef __cplusplus +extern "C" { +#endif + +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; + +#ifdef __cplusplus +} +#endif + +#endif // _TIME_H diff --git a/lib/mlibc/options/ansi/include/uchar.h b/lib/mlibc/options/ansi/include/uchar.h new file mode 100644 index 0000000..3651a60 --- /dev/null +++ b/lib/mlibc/options/ansi/include/uchar.h @@ -0,0 +1,29 @@ +#ifndef _UCHAR_H +#define _UCHAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <bits/mbstate.h> +#include <bits/size_t.h> + +#ifndef __cplusplus +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; +#endif /* __cplusplus */ + +typedef struct __mlibc_mbstate mbstate_t; + +#ifndef __MLIBC_ABI_ONLY + +size_t c32rtomb(char *pmb, char32_t c32, mbstate_t *ps); +size_t mbrtoc32(char32_t *pc32, const char *pmb, size_t max, mbstate_t *ps); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif /* _UCHAR_H */ diff --git a/lib/mlibc/options/ansi/include/wchar.h b/lib/mlibc/options/ansi/include/wchar.h new file mode 100644 index 0000000..27198c5 --- /dev/null +++ b/lib/mlibc/options/ansi/include/wchar.h @@ -0,0 +1,128 @@ +#ifndef _WCHAR_H +#define _WCHAR_H + +#include <bits/null.h> +#include <bits/size_t.h> +#include <bits/wchar_t.h> +#include <bits/wchar.h> +#include <bits/wint_t.h> +#include <bits/mbstate.h> + +#define WEOF 0xffffffffU + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct __mlibc_file_base FILE; + +typedef struct __mlibc_mbstate mbstate_t; + +// MISSING: struct tm + +#ifndef __MLIBC_ABI_ONLY + +// [7.28.2] Wide formatted I/O functions + +int fwprintf(FILE *__restrict, const wchar_t *__restrict, ...); +int fwscanf(FILE *__restrict, const wchar_t *__restrict, ...); +int vfwprintf(FILE *__restrict, const wchar_t *__restrict, __builtin_va_list); +int vfwscanf(FILE *__restrict, const wchar_t *__restrict, __builtin_va_list); + +int swprintf(wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); +int swscanf(wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); +int vswprintf(wchar_t *__restrict, size_t, const wchar_t *__restrict, __builtin_va_list); +int vswscanf(wchar_t *__restrict, size_t, const wchar_t *__restrict, __builtin_va_list); + +int wprintf(const wchar_t *__restrict, ...); +int wscanf(const wchar_t *__restrict, ...); +int vwprintf(const wchar_t *__restrict, __builtin_va_list); +int vwscanf(const wchar_t *__restrict, __builtin_va_list); + +// [7.28.3] Wide character I/O functions + +wint_t fgetwc(FILE *); +wchar_t *fgetws(wchar_t *__restrict, int, FILE *__restrict); +wint_t fputwc(wchar_t, FILE *); +int fputws(const wchar_t *__restrict, FILE *__restrict); +int fwide(FILE *, int); +wint_t getwc(FILE *); +wint_t getwchar(void); +wint_t putwc(wchar_t, FILE *); +wint_t putwchar(wchar_t); +wint_t ungetwc(wint_t, FILE *); + +// [7.28.4] Wide string functions + +double wcstod(const wchar_t *__restrict, wchar_t **__restrict); +float wcstof(const wchar_t *__restrict, wchar_t **__restrict); +long double wcstold(const wchar_t *__restrict, wchar_t **__restrict); + +long wcstol(const wchar_t *__restrict, wchar_t **__restrict, int); +long long wcstoll(const wchar_t *__restrict, wchar_t **__restrict, int); +unsigned long wcstoul(const wchar_t *__restrict, wchar_t **__restrict, int); +unsigned long long wcstoull(const wchar_t *__restrict, wchar_t **__restrict, int); + +wchar_t *wcscpy(wchar_t *__restrict, const wchar_t *__restrict); +wchar_t *wcsncpy(wchar_t *__restrict, const wchar_t *__restrict, size_t); +wchar_t *wmemcpy(wchar_t *__restrict, const wchar_t *__restrict, size_t); +wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); + +wchar_t *wcscat(wchar_t *__restrict, const wchar_t *__restrict); +wchar_t *wcsncat(wchar_t *__restrict, const wchar_t *__restrict, size_t); + +int wcscmp(const wchar_t *, const wchar_t *); +int wcscoll(const wchar_t *, const wchar_t *); +int wcsncmp(const wchar_t *, const wchar_t *, size_t); +int wcsxfrm(wchar_t *__restrict, const wchar_t *__restrict, size_t); +int wmemcmp(const wchar_t *, const wchar_t *, size_t); + +wchar_t *wcschr(const wchar_t *, wchar_t); +size_t wcscspn(const wchar_t *, const wchar_t *); +wchar_t *wcspbrk(const wchar_t *, const wchar_t *); +wchar_t *wcsrchr(const wchar_t *, wchar_t); +size_t wcsspn(const wchar_t *, const wchar_t *); +wchar_t *wcsstr(const wchar_t *, const wchar_t *); +wchar_t *wcstok(wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); +wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); + +size_t wcslen(const wchar_t *); +wchar_t *wmemset(wchar_t *, wchar_t, size_t); + +// [7.28.5] Wide date/time functions + +/* POSIX says: + * The tag tm is declared as naming an incomplete structure type, the contents of which are + * described in the header <time.h>. */ +struct tm; +size_t wcsftime(wchar_t *__restrict, size_t, const wchar_t *__restrict, + const struct tm *__restrict); + +// [7.28.6] Wide conversion functions + +wint_t btowc(int c); +int wctob(wint_t); + +int mbsinit(const mbstate_t *); +size_t mbrlen(const char *__restrict, size_t, mbstate_t *__restrict); +size_t mbrtowc(wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); +size_t wcrtomb(char *__restrict, wchar_t, mbstate_t *__restrict); +size_t mbsrtowcs(wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); +size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); +size_t wcsrtombs(char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); +size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); + +// POSIX extensions +int wcwidth(wchar_t wc); +int wcswidth(const wchar_t *, size_t); +wchar_t *wcsdup(const wchar_t *s); +int wcsncasecmp(const wchar_t*, const wchar_t*, size_t); +int wcscasecmp(const wchar_t *, const wchar_t *); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _WCHAR_H diff --git a/lib/mlibc/options/ansi/include/wctype.h b/lib/mlibc/options/ansi/include/wctype.h new file mode 100644 index 0000000..df5d37a --- /dev/null +++ b/lib/mlibc/options/ansi/include/wctype.h @@ -0,0 +1,52 @@ +#ifndef _WCTYPE_H +#define _WCTYPE_H + +#include <mlibc-config.h> +#include <bits/wint_t.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned long wctype_t; +typedef unsigned long wctrans_t; + +#ifndef __MLIBC_ABI_ONLY + +// [C11/7.30.2.2] Extensible wide character classification functions. + +int iswalnum(wint_t); +int iswalpha(wint_t); +int iswblank(wint_t); +int iswcntrl(wint_t); +int iswdigit(wint_t); +int iswgraph(wint_t); +int iswlower(wint_t); +int iswprint(wint_t); +int iswpunct(wint_t); +int iswspace(wint_t); +int iswupper(wint_t); +int iswxdigit(wint_t); + +wctype_t wctype(const char *); +int iswctype(wint_t, wctype_t); + +// [C11/7.30.3] Wide character case mapping utilities. + +wint_t towlower(wint_t); +wint_t towupper(wint_t); + +wctrans_t wctrans(const char *); +wint_t towctrans(wint_t, wctrans_t); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#if __MLIBC_POSIX_OPTION +# include <bits/posix/posix_wctype.h> +#endif + +#endif // _WCTYPE_H |