diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
commit | 7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch) | |
tree | 092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src | |
parent | 6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff) |
merge sources into single tree
Diffstat (limited to 'src')
820 files changed, 12433 insertions, 0 deletions
diff --git a/src/9899-1990 b/src/9899-1990 deleted file mode 160000 -Subproject fe15b79118a2ea4e3f1a95603532fa8b7efd490 diff --git a/src/9899-1990-AMD1 b/src/9899-1990-AMD1 deleted file mode 160000 -Subproject 88c492054f519996680ae7b1556729032de5b0f diff --git a/src/9899-1999 b/src/9899-1999 deleted file mode 160000 -Subproject 6d267bee341a4d601c15157fe76ff4fe907614a diff --git a/src/9899-2011 b/src/9899-2011 deleted file mode 160000 -Subproject 08382806cd4202e4b42e3980f6a8dfd52b09601 diff --git a/src/9899-2011-EXT1 b/src/9899-2011-EXT1 deleted file mode 160000 -Subproject e2417e445112670d103aefdab5575363feddfa3 diff --git a/src/POSIX.1-1988 b/src/POSIX.1-1988 deleted file mode 160000 -Subproject 4661b9c5d1b9481c28af417e22ff4ee2ccb26b1 diff --git a/src/POSIX.1-1990 b/src/POSIX.1-1990 deleted file mode 160000 -Subproject 901bc6f935aa15073cf3527e94e09b6111693d9 diff --git a/src/XOPEN-1994 b/src/XOPEN-1994 deleted file mode 160000 -Subproject 7de254d1c687505a530f37b0a5e11795c2a75d2 diff --git a/src/__DATE__.c b/src/__DATE__.c new file mode 100644 index 00000000..14e40fcb --- /dev/null +++ b/src/__DATE__.c @@ -0,0 +1,12 @@ +#define __DATE__ /** date of compilation **/ + +/*** +is automatically defined by the compiler as the date of program +compilation, in the format DEFINITION("Mmm dd yyyy"). +***/ + +/* +VALUE_TYPE(string literal) +VALUE_FIXED(VAR("date-of-compilation")) +STDC(1) +*/ diff --git a/src/__FILE__.c b/src/__FILE__.c new file mode 100644 index 00000000..257ae89b --- /dev/null +++ b/src/__FILE__.c @@ -0,0 +1,14 @@ +#define __FILE__ /** source file name **/ + +/*** +is automatically defined by the compiler as the file name of the +current source file being compiled as a character string literal. + +THIS() can be changed using PPDIR(line). +***/ + +/* +VALUE_TYPE(string literal) +VALUE_FIXED(VAR(the current file name)) +STDC(1) +*/ diff --git a/src/__LINE__.c b/src/__LINE__.c new file mode 100644 index 00000000..c6acb1b1 --- /dev/null +++ b/src/__LINE__.c @@ -0,0 +1,14 @@ +#define __LINE__ /** source file line number **/ + +/*** +is automatically defined by the compiler as the current logical source +line in the source file being compiled. + +THIS() can be changed during compilation using PPDIR(line). +***/ + +/* +VALUE_TYPE(TYPE(int)) +VALUE_FIXED(VAR(the current line number)) +STDC(1) +*/ diff --git a/src/__STDC_HOSTED__.c b/src/__STDC_HOSTED__.c new file mode 100644 index 00000000..18df218b --- /dev/null +++ b/src/__STDC_HOSTED__.c @@ -0,0 +1,12 @@ +#define __STDC_HOSTED__ + +/** hosted or free-standing implementation **/ + +/*** +is defined to the integer constant CONST(1) if the implementation +is hosted, CONST(0) otherwise. +***/ + +/* +STDC(199901) +*/ diff --git a/src/__STDC_IEC_559_COMPLEX__.c b/src/__STDC_IEC_559_COMPLEX__.c new file mode 100644 index 00000000..4bb15a57 --- /dev/null +++ b/src/__STDC_IEC_559_COMPLEX__.c @@ -0,0 +1,12 @@ +#define __STDC_IEC_559_COMPLEX__ + +/** IEC 60559 complex arithmetic **/ + +/*** +is defined to CONST(1) if the implementation conforms to Annex G +of ISO/IEC 9899 (IEC 60559 complex arithmetic). +***/ + +/* +STDC(199901) +*/ diff --git a/src/__STDC_IEC_559__.c b/src/__STDC_IEC_559__.c new file mode 100644 index 00000000..595e8764 --- /dev/null +++ b/src/__STDC_IEC_559__.c @@ -0,0 +1,12 @@ +#define __STDC_IEC_559__ + +/** IEC 60559 floating-point arithmetic **/ + +/*** +is defined to CONST(1) if the implementation conforms to Annex G +of ISO/IEC 9899 (IEC 60559 floating-point arithmetic). +***/ + +/* +STDC(199901) +*/ diff --git a/src/__STDC_ISO_10646__.c b/src/__STDC_ISO_10646__.c new file mode 100644 index 00000000..9aaff74f --- /dev/null +++ b/src/__STDC_ISO_10646__.c @@ -0,0 +1,15 @@ +#define __STDC_ISO_10646__ + +/** supported UCS version **/ + +/*** +is defined if TYPE(wchar_t) represents characters encoded +in conformance with ISO/IEC 10646. In this case, THIS() is +defined as an integer CONST(yyyymmL), where CONST(yyyy) +represents the year and CONST(mm) the month of the supported +version of ISO/IEC 10646. +***/ + +/* +STDC(199901) +*/ diff --git a/src/__STDC_VERSION__.c b/src/__STDC_VERSION__.c new file mode 100644 index 00000000..dedec29d --- /dev/null +++ b/src/__STDC_VERSION__.c @@ -0,0 +1,11 @@ +#define __STDC_VERSION__ /** supported C standard **/ +/*** +declares the supported version of ISO/IEC 9899. If THIS() is not defined, +the implementation only supports ISO/IEC 9899:1990, without AMD1. +***/ +/* +VALUE_SELECT(`199409L', `ISO/IEC 9899:1990 AMD1') +VALUE_SELECT(`199901L', `ISO/IEC 9899:1999') +VALUE_SELECT(`201112L', `ISO/IEC 9899:2011') +STDC(199409) +*/ diff --git a/src/__STDC__.c b/src/__STDC__.c new file mode 100644 index 00000000..5bcfe7aa --- /dev/null +++ b/src/__STDC__.c @@ -0,0 +1,14 @@ +#define __STDC__ (1) + +/** standard C support **/ + +/*** +is automatically defined by the compiler to indicate that it supports +some version of ISO/IEC 9899. +***/ + +/* +VALUE_TYPE(TYPE(int)) +VALUE_FIXED(1) +STDC(1) +*/ diff --git a/src/__TIME__.c b/src/__TIME__.c new file mode 100644 index 00000000..472e42c0 --- /dev/null +++ b/src/__TIME__.c @@ -0,0 +1,12 @@ +#define __TIME__ /** time of compilation **/ + +/*** +is automatically defined by the compiler as the time of compilation +in the format DEFINITION("hh:mm:ss"). +***/ + +/* +VALUE_TYPE(string literal) +VALUE_FIXED(VAR("time of compilation")) +STDC(1) +*/ diff --git a/src/assert/NDEBUG.c b/src/assert/NDEBUG.c new file mode 100644 index 00000000..b09e73ce --- /dev/null +++ b/src/assert/NDEBUG.c @@ -0,0 +1,14 @@ +/* #undef NDEBUG */ + +#define NDEBUG /** control program diagnostics **/ + +/*** +THIS() is not defined by the compiler or any header. If it is defined +by the programmer before including HEADER(assert.h), it causes +FUNCTION(assert) to be a void statement. Otherwise, FUNCTION(assert) has +its normal behavior. +***/ + +/* +STDC(1) +*/ diff --git a/src/assert/__assert.c b/src/assert/__assert.c new file mode 100644 index 00000000..630fdec1 --- /dev/null +++ b/src/assert/__assert.c @@ -0,0 +1,15 @@ +#include <assert.h> +#include "stdio.h" +#include "stdlib.h" + +void __assert(const char *expr, const char *file, int line, const char *func) +{ + if (func) { + fprintf(stderr, "Assertion failed: %s (%s:%d:%s())\n", expr, + file, line, func); + } else { + fprintf(stderr, "Assertion failed: %s (%s:%d)\n", expr, file, + line); + } + abort(); +} diff --git a/src/assert/assert.c b/src/assert/assert.c new file mode 100644 index 00000000..65e4ea6e --- /dev/null +++ b/src/assert/assert.c @@ -0,0 +1,44 @@ +#include <assert.h> + +#undef assert + +#ifdef NDEBUG + +#define assert(ignore) ((void)0) + +#else + +#if __STDC_VERSION__ < 199901L +#define __func__ ((char*)0) +#endif + +#define assert(__exp__) \ + ((void)(__exp__ ? 0 : __assert(#__exp__, __FILE__, __LINE__, __func__))) + +#endif + +/* in c89 - void assert(int expression); */ +/* in c99 - void assert(/scalar/ expression); */ + +/** insert program diagnostics **/ + +/*** +adds mandatory checks to programs. If ARGUMENT(expression) is false, +FUNCTION(assert) prints a diagnostic message to IDENTIFIER(stderr). The +message includes the text of the failed assertion as well as the file name and +line number of the source where the assertion failed. Compilers supporting +std(C99) or higher will also include the name of the function in which the +assertion failed. After printing the diagnostic message, THIS() +causes abnormal program termination by calling FUNCTION(abort). + +If the macro IDENTIFIER(NDEBUG) is defined, THIS() is +defined as DEFINITION(((void)0)). +***/ + +/* +PROTOTYPE(void assert(int expression);) +IMPLEMENTATION(The format of the diagnostic message, TODO: document this here) +UNDEFINED(The THIS() macro is suppressed) +UNDEFINED(ARGUMENT(expression) does not have a scalar type) +STDC(1) +*/ diff --git a/src/complex/I.c b/src/complex/I.c new file mode 100644 index 00000000..de7929a8 --- /dev/null +++ b/src/complex/I.c @@ -0,0 +1,13 @@ +#include <complex.h> + +#ifdef __STDC_IEC_559_COMPLEX__ +#define I _Imaginary_I +#else +#define I _Complex_I +#endif + +/* see appendix G for whether or not to set __STDC_IEC_559_COMPLEX__ == 1 */ + +/* +STDC(199901) +*/ diff --git a/src/complex/_Complex_I.c b/src/complex/_Complex_I.c new file mode 100644 index 00000000..0cb6aede --- /dev/null +++ b/src/complex/_Complex_I.c @@ -0,0 +1,7 @@ +#include <complex.h> + +#define _Complex_I (const float _Complex)1 /* TODO: imaginary unit */ + +/* +STDC(199901) +*/ diff --git a/src/complex/_Imaginary_I.c b/src/complex/_Imaginary_I.c new file mode 100644 index 00000000..9357dc4f --- /dev/null +++ b/src/complex/_Imaginary_I.c @@ -0,0 +1,10 @@ +#include <complex.h> + +#ifdef __STDC_IEC_559_COMPLEX__ +#define _Imaginary_I (const float _Imaginary)1 /* TODO: imaginary unit */ +#endif + +/* This should only be defined if imaginary types are supported. */ +/* +STDC(199901) +*/ diff --git a/src/complex/cabs.c b/src/complex/cabs.c new file mode 100644 index 00000000..a408518b --- /dev/null +++ b/src/complex/cabs.c @@ -0,0 +1,23 @@ +# define TGSOURCE "cabs.c" +#include "nontstd/tgmath.h" + +#include <complex.h> + +TYPE TGFN(cabs)(TYPE complex z) +{ + return 0.0; +} + +/*d +The cabs functions compute the complex absolute value (also called norm, modulus, or +magnitude) of z. +d*/ + +/*r +The cabs functions return the complex absolute value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/cacos.c b/src/complex/cacos.c new file mode 100644 index 00000000..0eb88f4c --- /dev/null +++ b/src/complex/cacos.c @@ -0,0 +1,25 @@ +# define TGSOURCE "cacos.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(cacos)(TYPE complex z) +{ + return I; +} + +/*d +The cacos functions compute the complex arc cosine of z, with branch cuts outside the +interval [−1, +1] along the real axis. +d*/ + +/*r +The cacos functions return the complex arc cosine value, in the range of a strip +mathematically unbounded along the imaginary axis and in the interval [0, Ï€ ] along the +real axis +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/cacosh.c b/src/complex/cacosh.c new file mode 100644 index 00000000..8589b691 --- /dev/null +++ b/src/complex/cacosh.c @@ -0,0 +1,26 @@ +# define TGSOURCE "cacosh.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(cacosh)(TYPE complex z) +{ + return 0.0; +} + + +/*d +The cacosh functions compute the complex arc hyperbolic cosine of z, with a branch +cut at values less than 1 along the real axis. +d*/ + +/*r +The cacosh functions return the complex arc hyperbolic cosine value, in the range of a +half-strip of non-negative values along the real axis and in the interval [−i Ï€ , +i Ï€ ] along +the imaginary axis. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/carg.c b/src/complex/carg.c new file mode 100644 index 00000000..15772f8a --- /dev/null +++ b/src/complex/carg.c @@ -0,0 +1,23 @@ +# define TGSOURCE "carg.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE TGFN(carg)(TYPE complex z) +{ + return 0.0; +} + +/*d +The carg functions compute the argument (also called phase angle) of z, with a branch +cut along the negative real axis. +d*/ + +/*r +The carg functions return the value of the argument in the interval [− Ï€ , + Ï€ ]. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/casin.c b/src/complex/casin.c new file mode 100644 index 00000000..e96fee43 --- /dev/null +++ b/src/complex/casin.c @@ -0,0 +1,25 @@ +# define TGSOURCE "casin.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(casin)(TYPE complex z) +{ + return 0; +} + +/*d +The casin functions compute the complex arc sine of z, with branch cuts outside the +interval [−1, +1] along the real axis. +d*/ + +/*r +The casin functions return the complex arc sine value, in the range of a strip +mathematically unbounded along the imaginary axis and in the interval [− Ï€ /2, + Ï€ /2] +along the real axis. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/casinh.c b/src/complex/casinh.c new file mode 100644 index 00000000..fe1b20fb --- /dev/null +++ b/src/complex/casinh.c @@ -0,0 +1,25 @@ +# define TGSOURCE "casinh.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(casinh)(TYPE complex z) +{ + return 0.0; +} + +/*d +The casinh functions compute the complex arc hyperbolic sine of z, with branch cuts +outside the interval [−i, +i] along the imaginary axis. +d*/ + +/*r +The casinh functions return the complex arc hyperbolic sine value, in the range of a +strip mathematically unbounded along the real axis and in the interval [−i Ï€ /2, +i Ï€ /2] +along the imaginary axis. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/catan.c b/src/complex/catan.c new file mode 100644 index 00000000..6c162c3f --- /dev/null +++ b/src/complex/catan.c @@ -0,0 +1,25 @@ +# define TGSOURCE "catan.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(catan)(TYPE complex z) +{ + return 0.0; +} + +/*d +The catan functions compute the complex arc tangent of z, with branch cuts outside the +interval [−i, +i] along the imaginary axis. +d*/ + +/*r +The catan functions return the complex arc tangent value, in the range of a strip +mathematically unbounded along the imaginary axis and in the interval [− Ï€ /2, + Ï€ /2] +along the real axis. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/catanh.c b/src/complex/catanh.c new file mode 100644 index 00000000..e8eff5cd --- /dev/null +++ b/src/complex/catanh.c @@ -0,0 +1,26 @@ +# define TGSOURCE "catanh.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(catanh)(TYPE complex z) +{ + return 0.0; +} + +/*d +The catanh functions compute the complex arc hyperbolic tangent of z, with branch +cuts outside the interval [−1, +1] along the real axis. +d*/ + +/*r +The catanh functions return the complex arc hyperbolic tangent value, in the range of a +strip mathematically unbounded along the real axis and in the interval [−i Ï€ /2, +i Ï€ /2] +along the imaginary axis. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/ccos.c b/src/complex/ccos.c new file mode 100644 index 00000000..4fffc92f --- /dev/null +++ b/src/complex/ccos.c @@ -0,0 +1,22 @@ +# define TGSOURCE "ccos.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(ccos)(TYPE complex z) +{ + return 0.0; +} + +/*d +The ccos functions compute the complex cosine of z. +d*/ + +/*r +The ccos functions return the complex cosine value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/ccosh.c b/src/complex/ccosh.c new file mode 100644 index 00000000..87ad53d6 --- /dev/null +++ b/src/complex/ccosh.c @@ -0,0 +1,23 @@ +# define TGSOURCE "ccosh.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(ccosh)(TYPE complex z) +{ + return 0.0; +} + +/*d +The ccosh functions compute the complex hyperbolic cosine of z. +d*/ + +/*r +The ccosh functions return the complex hyperbolic cosine value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/cexp.c b/src/complex/cexp.c new file mode 100644 index 00000000..d20eb6a6 --- /dev/null +++ b/src/complex/cexp.c @@ -0,0 +1,23 @@ +# define TGSOURCE "cexp.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(cexp)(TYPE complex z) +{ + return 0.0; +} + +/*d +The cexp functions compute the complex base-e exponential of z. +d*/ + +/*r +The cexp functions compute the complex base-e exponential of z. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/cimag.c b/src/complex/cimag.c new file mode 100644 index 00000000..3284d4ca --- /dev/null +++ b/src/complex/cimag.c @@ -0,0 +1,23 @@ +# define TGSOURCE "cimag.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE TGFN(cimag)(TYPE complex z) +{ + return 0.0; +} + +/*d +The cimag functions compute the imaginary part of z. 164) +d*/ + +/*r +The cimag functions return the imaginary part value (as a real). +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/clog.c b/src/complex/clog.c new file mode 100644 index 00000000..8b958fea --- /dev/null +++ b/src/complex/clog.c @@ -0,0 +1,26 @@ +# define TGSOURCE "clog.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(clog)(TYPE complex z) +{ + return 0.0; +} + +/*d +The clog functions compute the complex natural (base-e) logarithm of z, with a branch +cut along the negative real axis. +d*/ + +/*r +The clog functions return the complex natural logarithm value, in the range of a strip +mathematically unbounded along the real axis and in the interval [−i Ï€ , +i Ï€ ] along the +imaginary axis. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/complex.c b/src/complex/complex.c new file mode 100644 index 00000000..9649b03c --- /dev/null +++ b/src/complex/complex.c @@ -0,0 +1,7 @@ +#include <complex.h> +#define complex _Complex + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/conj.c b/src/complex/conj.c new file mode 100644 index 00000000..18cadb9d --- /dev/null +++ b/src/complex/conj.c @@ -0,0 +1,23 @@ +# define TGSOURCE "conj.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(conj)(TYPE complex z) +{ + return 0.0; +} + +/*d +The conj functions compute the complex conjugate of z, by rev ersing the sign of its +imaginary part. +d*/ + +/*r +The conj functions return the complex conjugate value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/complex/cpow.c b/src/complex/cpow.c new file mode 100644 index 00000000..5e778b1a --- /dev/null +++ b/src/complex/cpow.c @@ -0,0 +1,23 @@ +# define TGSOURCE "cpow.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(cpow)(TYPE complex x, TYPE complex y) +{ + return 0.0; +} + +/*d +The cpow functions compute the complex power function x y , with a branch cut for the +first parameter along the negative real axis. +d*/ + +/*r +The cpow functions return the complex power function value. +r*/ +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/cproj.c b/src/complex/cproj.c new file mode 100644 index 00000000..406ff812 --- /dev/null +++ b/src/complex/cproj.c @@ -0,0 +1,27 @@ +# define TGSOURCE "cproj.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(cproj)(TYPE complex z) +{ + return 0.0; +} + +/*d +The cproj functions compute a projection of z onto the Riemann sphere: z projects to +z except that all complex infinities (even those with one infinite part and one NaN part) +project to positive infinity on the real axis. If z has an infinite part, then cproj(z) is +equivalent to +INFINITY + I * copysign(0.0, cimag(z)) +d*/ + +/*r +The cproj functions return the value of the projection onto the Riemann sphere. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/creal.c b/src/complex/creal.c new file mode 100644 index 00000000..9888a274 --- /dev/null +++ b/src/complex/creal.c @@ -0,0 +1,23 @@ +# define TGSOURCE "creal.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE TGFN(creal)(TYPE complex z) +{ + return 0.0; +} + +/*d +The creal functions compute the real part of z. 165) +d*/ + +/*r +The creal functions return the real part value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/csin.c b/src/complex/csin.c new file mode 100644 index 00000000..575c7eb9 --- /dev/null +++ b/src/complex/csin.c @@ -0,0 +1,23 @@ +# define TGSOURCE "csin.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(csin)(TYPE complex z) +{ + return 0.0; +} + +/*d +The csin functions compute the complex sine of z. +d*/ + +/*r +The csin functions return the complex sine value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/csinh.c b/src/complex/csinh.c new file mode 100644 index 00000000..c4db9865 --- /dev/null +++ b/src/complex/csinh.c @@ -0,0 +1,23 @@ +# define TGSOURCE "csinh.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(csinh)(TYPE complex z) +{ + return 0.0; +} + +/*d +The csinh functions compute the complex hyperbolic sine of z. +d*/ + +/*r +The csinh functions return the complex hyperbolic sine value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/csqrt.c b/src/complex/csqrt.c new file mode 100644 index 00000000..edbbd394 --- /dev/null +++ b/src/complex/csqrt.c @@ -0,0 +1,25 @@ +# define TGSOURCE "csqrt.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(csqrt)(TYPE complex z) +{ + return 0.0; +} + +/*d +The csqrt functions compute the complex square root of z, with a branch cut along the +negative real axis. +d*/ + +/*r +The csqrt functions return the complex square root value, in the range of the right half- +plane (including the imaginary axis). +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/ctan.c b/src/complex/ctan.c new file mode 100644 index 00000000..34705e84 --- /dev/null +++ b/src/complex/ctan.c @@ -0,0 +1,23 @@ +# define TGSOURCE "ctan.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(ctan)(TYPE complex z) +{ + return 0.0; +} + +/*d +The ctan functions compute the complex tangent of z. +d*/ + +/*r +The ctan functions return the complex tangent value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/ctanh.c b/src/complex/ctanh.c new file mode 100644 index 00000000..f4d5683c --- /dev/null +++ b/src/complex/ctanh.c @@ -0,0 +1,23 @@ +# define TGSOURCE "ctanh.c" +#include "nonstd/tgmath.h" + +#include <complex.h> + +TYPE complex TGFN(ctanh)(TYPE complex z) +{ + return 0.0; +} + +/*d +The ctanh functions compute the complex hyperbolic tangent of z. +d*/ + +/*r +The ctanh functions return the complex hyperbolic tangent value. +r*/ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/complex/imaginary.c b/src/complex/imaginary.c new file mode 100644 index 00000000..4b3da25d --- /dev/null +++ b/src/complex/imaginary.c @@ -0,0 +1,13 @@ +#include <complex.h> + +#ifdef __STDC_IEC_559_COMPLEX__ +#define imaginary _Imaginary +#endif + +/* This should only be defined if imaginary types are supported. */ + +/* +STDC(199901) +LINK(m) +*/ + diff --git a/src/ctype/isalnum.c b/src/ctype/isalnum.c new file mode 100644 index 00000000..507655ae --- /dev/null +++ b/src/ctype/isalnum.c @@ -0,0 +1,23 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" + +/** test whether a character is alphanumeric **/ +int isalnum(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is an alpanumeric character); + RETURN(0, ARGUMENT(c) is not an alphanumeric character); + */ + return isalpha(c) || isdigit(c); +} + +/*** +tests whether ARGUMENT(c) is a character in the class +CHARACTER_CLASS(alpha) or CHARACTER_CLASS(digit) in the current locale. +***/ +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/ctype/isalpha.c b/src/ctype/isalpha.c new file mode 100644 index 00000000..2b893425 --- /dev/null +++ b/src/ctype/isalpha.c @@ -0,0 +1,26 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" + +/** test whether a character is alphabetic **/ +int isalpha(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is an alphabetic character) + RETURN(0, ARGUMENT(c) is not an alphabetic character) + */ + return islower(c) || isupper(c); +} + +/*** +tests whether ARGUMENT(c) is a character in the class +CHARACTER_CLASS(alpha) in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for characters for which FUNCTION(isupper) or FUNCTION(islower) is true') +OTHER_LOCALES(`THIS is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true') +STDC(1) +*/ diff --git a/src/ctype/isblank.c b/src/ctype/isblank.c new file mode 100644 index 00000000..1a597f82 --- /dev/null +++ b/src/ctype/isblank.c @@ -0,0 +1,39 @@ +#include <ctype.h> +#include "limits.h" +#include "locale.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" +#include "nonstd/assert.h" + +/** test whether a character is blank **/ +int isblank(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, "unsigned char", EOF); + + unsigned int *map = __libc(CTYPE); + + return map[c] & BLANK; +} + +/*** +The fn(isblank) functions tests whether a character is a of the character +class cclass(blank) in the current locale. + +In the locale(C) and locale(POSIX) locales, only the standard blank characters +space (char( )) horizontal tab (char(\t)) are blank. + +In other locales, fn(isblank) will return true for the standard blank characters +as well as other characters for which fn(isspace) is true and the character is +used to separate words on a line a text. +***/ + +/* RETURN(NZ): arg(c) is a blank character */ +/* RETURN(0): arg(c) is not a blank character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199901) +*/ diff --git a/src/ctype/iscntrl.c b/src/ctype/iscntrl.c new file mode 100644 index 00000000..31804123 --- /dev/null +++ b/src/ctype/iscntrl.c @@ -0,0 +1,29 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is a control character */ +int iscntrl(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a control character); + RETURN(0, ARGUMENT(c) is not a control character); + */ + + return map[c] == 0 || (map[c] == SPACE && c != ' '); +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(cntrl) in the +current locale. +***/ + +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/ctype/isdigit.c b/src/ctype/isdigit.c new file mode 100644 index 00000000..7a19fe19 --- /dev/null +++ b/src/ctype/isdigit.c @@ -0,0 +1,26 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" + +/** test whether a character is a digit **/ +int isdigit(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a digit); + RETURN(0, ARGUMENT(c) is not a digit); + */ + + return isxdigit(c) && !isalpha(c); +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(digit) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for characters CHAR(0), CHAR(1), CHAR(2), CHAR(3), CHAR(4), CHAR(5), CHAR(6), CHAR(7), CHAR(8), and CHAR(9)') +STDC(1) +*/ diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c new file mode 100644 index 00000000..8ad3be0b --- /dev/null +++ b/src/ctype/isgraph.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is graphic **/ +int isgraph(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a graphic character); + RETURN(0, ARGUMENT(c) is not a graphic character); + */ + + return map[c] & ~SPACE; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(graph) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for all printable characters other than SPACE()') +STDC(1) +*/ diff --git a/src/ctype/islower.c b/src/ctype/islower.c new file mode 100644 index 00000000..082697dd --- /dev/null +++ b/src/ctype/islower.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/internal.h" +#include "nonstd/ctype.h" + +/** test whether a character is a lowercase letter **/ +int islower(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a lowercase letter); + RETURN(0, ARGUMENT(c) is not a lowercase letter); + */ + return map[c] & LOWER; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(lower) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the characters CHAR(a), CHAR(b), CHAR(c), CHAR(d), CHAR(e), CHAR(f), CHAR(g), CHAR(h), CHAR(i), CHAR(j), CHAR(k), CHAR(l), CHAR(m), CHAR(n), CHAR(o), CHAR(p), CHAR(q), CHAR(s), CHAR(t), CHAR(u), CHAR(w), CHAR(x), CHAR(y), and CHAR(z)') +OTHER_LOCALES(`THIS() is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true') +STDC(1) +*/ diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c new file mode 100644 index 00000000..58120351 --- /dev/null +++ b/src/ctype/isprint.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is printable **/ +int isprint(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a printable character); + RETURN(0, ARGUMENT(c) is not a printable character); + */ + + return map[c] & ~SPACE || c == ' '; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(print) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for any printing character including SPACE()') +STDC(1) +*/ diff --git a/src/ctype/ispunct.c b/src/ctype/ispunct.c new file mode 100644 index 00000000..bad66523 --- /dev/null +++ b/src/ctype/ispunct.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is punctuation **/ +int ispunct(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a punctuation character); + RETURN(0, ARGUMENT(c) is not a punctuation character); + */ + + return map[c] & PUNCT; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(punct) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for printing characters for which neither FUNCTION(isspace) nor FUNCTION(isalnum) is true') +STDC(1) +*/ diff --git a/src/ctype/isspace.c b/src/ctype/isspace.c new file mode 100644 index 00000000..a83cb584 --- /dev/null +++ b/src/ctype/isspace.c @@ -0,0 +1,31 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is white-space **/ +int isspace(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a white-space character); + RETURN(0, ARGUMENT(c) is not a white-space character); + */ + + return map[c] & SPACE; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(space) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the standard white-space characters: SPACE, form feed (CHAR(\f)), new-line (CHAR(\n)), carriage return (CHAR(\r)), horizontal tab (CHAR(\t)), and vertical tab (CHAR(\v))') +OTHER_LOCALES(`THIS() is true for the standard white-space characters and a set of characters for which FUNCTION(isalnum) is false') +STDC(1) +*/ diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c new file mode 100644 index 00000000..84247c28 --- /dev/null +++ b/src/ctype/isupper.c @@ -0,0 +1,31 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is an uppercase letter **/ +int isupper(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is an uppercase letter); + RETURN(0, ARGUMENT(c) is not an uppercase letter); + */ + + return map[c] & UPPER; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(upper) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the characters CHAR(A), CHAR(B), CHAR(C), CHAR(D), CHAR(E), CHAR(F), CHAR(G), CHAR(H), CHAR(I), CHAR(J), CHAR(K), CHAR(L), CHAR(M), CHAR(N), CHAR(O), CHAR(P), CHAR(Q), CHAR(S), CHAR(T), CHAR(U), CHAR(W), CHAR(X), CHAR(Y), and CHAR(Z)') +OTHER_LOCALES(`THIS() is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true') +STDC(1) +*/ diff --git a/src/ctype/isxdigit.c b/src/ctype/isxdigit.c new file mode 100644 index 00000000..37857d92 --- /dev/null +++ b/src/ctype/isxdigit.c @@ -0,0 +1,29 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is a hexadecimal digit **/ +int isxdigit(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a hexadecimal digit); + RETURN(0, ARGUMENT(c) is not a hexadecimal digit); + */ + return map[c] & XDIGIT; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(xdigit) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the characters CHAR(0), CHAR(1), CHAR(2), CHAR(3), CHAR(4), CHAR(5), CHAR(6), CHAR(7), CHAR(8), CHAR(9), CHAR(a), CHAR(b), CHAR(c), CHAR(d), CHAR(e), CHAR(f), CHAR(A), CHAR(B), CHAR(C), CHAR(D), CHAR(E), and CHAR(F)') +STDC(1) +*/ diff --git a/src/ctype/tolower.c b/src/ctype/tolower.c new file mode 100644 index 00000000..b684eb7a --- /dev/null +++ b/src/ctype/tolower.c @@ -0,0 +1,29 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** convert an uppercase letter to lowercase **/ +int tolower(int c) +{ + unsigned char *map = __libc(TOLOWER); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN_SUCCESS(ARGUMENT(c) converted to lowercase); + RETURN_FAILURE(ARGUMENT(c), ARGUMENT(c) was not an uppercase letter or it has no equivalent lowercase letter); + */ + + return map[c]; +} + +/*** +converts an uppercase letter to its equivalent lowercase letter in the current +locale. +***/ + +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/ctype/toupper.c b/src/ctype/toupper.c new file mode 100644 index 00000000..f4611bc7 --- /dev/null +++ b/src/ctype/toupper.c @@ -0,0 +1,27 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/internal.h" + +/** convert a lowercase letter to uppercase **/ +int toupper(int c) +{ + unsigned char *map = __libc(TOUPPER); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN_SUCCESS(ARGUMENT(c) converted to uppercase); + RETURN_FAILURE(ARGUMENT(c), ARGUMENT(c) was not a lowercase letter or it has no equivalent upercase letter); + */ + return map[c]; +} + +/*** +converts a lowercase letter to its equivalent uppercase letter in the current +locale. +***/ + +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/errno/EDOM.c b/src/errno/EDOM.c new file mode 100644 index 00000000..927df956 --- /dev/null +++ b/src/errno/EDOM.c @@ -0,0 +1,10 @@ +#include <errno.h> +#define EDOM (1) +/** domain error **/ +/*** +is used to indicate that an argument supplied to a function is outside the +defined input domain. +***/ +/* +STDC(1) +*/ diff --git a/src/errno/EILSEQ.c b/src/errno/EILSEQ.c new file mode 100644 index 00000000..cb8f42e7 --- /dev/null +++ b/src/errno/EILSEQ.c @@ -0,0 +1,7 @@ +#include <errno.h> +#define EILSEQ (3) +/** Illegal sequence / Illegal byte sequence **/ + +/* +STDC(199409) +*/ diff --git a/src/errno/ERANGE.c b/src/errno/ERANGE.c new file mode 100644 index 00000000..70b47572 --- /dev/null +++ b/src/errno/ERANGE.c @@ -0,0 +1,9 @@ +#include <errno.h> +#define ERANGE (2) +/** out of range **/ +/*** +used to indicated that the result of an operation is too large or too small. +***/ +/* +STDC(1) +*/ diff --git a/src/errno/__errno.c b/src/errno/__errno.c new file mode 100644 index 00000000..c46c86c7 --- /dev/null +++ b/src/errno/__errno.c @@ -0,0 +1,8 @@ +#include <errno.h> +#include "nonstd/internal.h" + +int *__errno(void) +{ + return __libc(ERRNO); +} + diff --git a/src/errno/errno.c b/src/errno/errno.c new file mode 100644 index 00000000..007526b8 --- /dev/null +++ b/src/errno/errno.c @@ -0,0 +1,23 @@ +#include <errno.h> +#define errno (*__errno()) + +/** get system errors **/ + +/*** +is a modifiable lvalue of type TYPE(int) which is used to +indicate errors in standard library functions. It may be a macro or an +identifier with external linkage. It is initialized to 0 at program start, +but no function in the standard library will set it to 0. Library functions +may set it to a non-zero value if its use is not documented in their +description. +***/ + +/* +UNSPECIFIED(Whether THIS() is declared as a macro or an identifier with external linkage (C89, C95, and C99 only)) +UNDEFINED(A macro definition of THIS() is suppressed) +UNDEFINED(A program defines an identifier named THIS()) +*/ + +/* +STDC(1) +*/ diff --git a/src/fenv/FE_ALL_EXCEPT.c b/src/fenv/FE_ALL_EXCEPT.c new file mode 100644 index 00000000..bf470e4c --- /dev/null +++ b/src/fenv/FE_ALL_EXCEPT.c @@ -0,0 +1,12 @@ +#include <fenv.h> + +#define FE_ALL_EXCEPT (FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW) + +/* The bitwise OR of all supported macros */ + +/* see appendix F regarding __STDC_IEC_559__ == 1 */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_DFL_ENV.c b/src/fenv/FE_DFL_ENV.c new file mode 100644 index 00000000..0cde32e9 --- /dev/null +++ b/src/fenv/FE_DFL_ENV.c @@ -0,0 +1,18 @@ +#include <fenv.h> + extern fenv_t const *FE_DFL_ENV; +#define FE_DFL_ENV ((const fenv_t*)FE_DFL_ENV) + +/* */ +/* represents the default floating-point environment — the one installed at program startup */ +/* — and has type ‘‘pointer to const-qualified fenv_t’’. It can be used as an argument to */ +/* <fenv.h> functions that manage the floating-point environment. */ +/* */ +/* Additional implementation-defined environments, with macro definitions beginning with */ +/* FE_ and an uppercase letter, and having type ‘‘pointer to const-qualified fenv_t’’, may */ +/* also be specified by the implementation. */ +/* */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_DIVBYZERO.c b/src/fenv/FE_DIVBYZERO.c new file mode 100644 index 00000000..80542670 --- /dev/null +++ b/src/fenv/FE_DIVBYZERO.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_DIVBYZERO (1<<0) +#else +#undef FE_DIVBYZERO +#endif + +/* Defined iff this exception is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_DOWNWARD.c b/src/fenv/FE_DOWNWARD.c new file mode 100644 index 00000000..702a50e9 --- /dev/null +++ b/src/fenv/FE_DOWNWARD.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_DOWNWARD (3) +#else +#undef FE_DOWNWARD +#endif + +/* Defined iff this operation is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_INEXACT.c b/src/fenv/FE_INEXACT.c new file mode 100644 index 00000000..59428fd4 --- /dev/null +++ b/src/fenv/FE_INEXACT.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_INEXACT (1<<1) +#else +#undef FE_INEXACT +#endif + +/* Defined iff this exception is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_INVALID.c b/src/fenv/FE_INVALID.c new file mode 100644 index 00000000..975ef8c6 --- /dev/null +++ b/src/fenv/FE_INVALID.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_INVALID (1<<2) +#else +#undef FE_INVALID +#endif + +/* Defined iff this exception is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_OVERFLOW.c b/src/fenv/FE_OVERFLOW.c new file mode 100644 index 00000000..f2edcf93 --- /dev/null +++ b/src/fenv/FE_OVERFLOW.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_OVERFLOW (1<<3) +#else +#undef FE_OVERFLOW +#endif + +/* Defined iff this exception is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_TONEAREST.c b/src/fenv/FE_TONEAREST.c new file mode 100644 index 00000000..df11a2bb --- /dev/null +++ b/src/fenv/FE_TONEAREST.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_TONEAREST (1) +#else +#undef FE_TONEAREST +#endif + +/* Defined iff this operation is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_TOWARDZERO.c b/src/fenv/FE_TOWARDZERO.c new file mode 100644 index 00000000..5f3454a7 --- /dev/null +++ b/src/fenv/FE_TOWARDZERO.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_TOWARDZERO (0) +#else +#undef FE_TOWARDZERO +#endif + +/* Defined iff this operation is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_UNDERFLOW.c b/src/fenv/FE_UNDERFLOW.c new file mode 100644 index 00000000..96fe5b75 --- /dev/null +++ b/src/fenv/FE_UNDERFLOW.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_UNDERFLOW (1<<4) +#else +#undef FE_UNDERFLOW +#endif + +/* Defined iff this exception is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/FE_UPWARD.c b/src/fenv/FE_UPWARD.c new file mode 100644 index 00000000..dbba8275 --- /dev/null +++ b/src/fenv/FE_UPWARD.c @@ -0,0 +1,14 @@ +#include <fenv.h> + +#if 0 +#define FE_UPWARD (2) +#else +#undef FE_UPWARD +#endif + +/* Defined iff this operation is supported */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/feclearexcept.c b/src/fenv/feclearexcept.c new file mode 100644 index 00000000..646b4669 --- /dev/null +++ b/src/fenv/feclearexcept.c @@ -0,0 +1,16 @@ +#include <fenv.h> + +int feclearexcept(int excepts) +{ + return excepts; +} + +/*d +The feclearexcept function clears the supported floating-point exceptions +represented by its argument. +d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fegetenv.c b/src/fenv/fegetenv.c new file mode 100644 index 00000000..b4795af7 --- /dev/null +++ b/src/fenv/fegetenv.c @@ -0,0 +1,16 @@ +#include <fenv.h> + +int fegetenv(fenv_t *envp) +{ + return 0; +} + +/*d +The fegetenv function stores the current floating-point environment in the object +pointed to by envp. +d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fegetexceptflag.c b/src/fenv/fegetexceptflag.c new file mode 100644 index 00000000..45e4bf98 --- /dev/null +++ b/src/fenv/fegetexceptflag.c @@ -0,0 +1,17 @@ +#include <fenv.h> + +int fegetexceptflag(fexcept_t *flagp, int excepts) +{ + return excepts; +} + +/*d +The fegetexceptflag function stores an implementation-defined representation of +the states of the floating-point status flags indicated by the argument excepts in the +object pointed to by the argument flagp. +d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fegetround.c b/src/fenv/fegetround.c new file mode 100644 index 00000000..13e5bf34 --- /dev/null +++ b/src/fenv/fegetround.c @@ -0,0 +1,21 @@ +#include <fenv.h> + +int fegetround(void) +{ + return 0; +} + +/*d +The fegetround function gets the current rounding direction. +d*/ + +/*r +The fegetround function returns the value of the rounding direction macro +representing the current rounding direction or a negative value if there is no such +rounding direction macro or the current rounding direction is not determinable. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/feholdexcept.c b/src/fenv/feholdexcept.c new file mode 100644 index 00000000..11b46ede --- /dev/null +++ b/src/fenv/feholdexcept.c @@ -0,0 +1,23 @@ +#include <fenv.h> + +int feholdexcept(fenv_t *envp) +{ + return 0; +} + +/*d +The feholdexcept function saves the current floating-point environment in the object +pointed to by envp, clears the floating-point status flags, and then installs a non-stop +(continue on floating-point exceptions) mode, if available, for all floating-point +exceptions. 180) +d*/ + +/*r +The feholdexcept function returns zero if and only if non-stop floating-point +exception handling was successfully installed. +r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fenv_t.c b/src/fenv/fenv_t.c new file mode 100644 index 00000000..2d644c75 --- /dev/null +++ b/src/fenv/fenv_t.c @@ -0,0 +1,10 @@ +#include <fenv.h> + +typedef unsigned long long int fenv_t; + +/*d Represents the entire floating-point environment d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/feraiseexcept.c b/src/fenv/feraiseexcept.c new file mode 100644 index 00000000..9f555dde --- /dev/null +++ b/src/fenv/feraiseexcept.c @@ -0,0 +1,19 @@ +#include <fenv.h> + +int feraiseexcept(int excepts) +{ + return excepts; +} + +/*d +The feraiseexcept function raises the supported floating-point exceptions +represented by its argument. 178) The order in which these floating-point exceptions are +raised is unspecified, except as stated in F.7.6. Whether the feraiseexcept function +additionally raises the ‘‘inexact’’ floating-point exception whenever it raises the +‘‘overflow’’ or ‘‘underflow’’ floating-point exception is implementation-defined. +d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fesetenv.c b/src/fenv/fesetenv.c new file mode 100644 index 00000000..1d6ea32a --- /dev/null +++ b/src/fenv/fesetenv.c @@ -0,0 +1,19 @@ +#include <fenv.h> + +int fesetenv(const fenv_t *envp) +{ + return 0; +} + +/*d +The fesetenv function establishes the floating-point environment represented by the +object pointed to by envp. The argument envp shall point to an object set by a call to +fegetenv or feholdexcept, or equal a floating-point environment macro. Note that +fesetenv merely installs the state of the floating-point status flags represented through +its argument, and does not raise these floating-point exceptions. +d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fesetexceptflag.c b/src/fenv/fesetexceptflag.c new file mode 100644 index 00000000..07fc7f5f --- /dev/null +++ b/src/fenv/fesetexceptflag.c @@ -0,0 +1,20 @@ +#include <fenv.h> + +int fesetexceptflag(const fexcept_t *flagp, int excepts) +{ + return 0; +} + +/*d +The fesetexceptflag function sets the floating-point status flags indicated by the +argument excepts to the states stored in the object pointed to by flagp. The value of +*flagp shall have been set by a previous call to fegetexceptflag whose second +argument represented at least those floating-point exceptions represented by the argument +excepts. This function does not raise floating-point exceptions, but only sets the state +of the flags. +d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fesetround.c b/src/fenv/fesetround.c new file mode 100644 index 00000000..d0f50c76 --- /dev/null +++ b/src/fenv/fesetround.c @@ -0,0 +1,23 @@ +#include <fenv.h> + +int fesetround(int round) +{ + return round; +} + +/*d */ +/* The fesetround function establishes the rounding direction represented by its */ +/* argument round. If the argument is not equal to the value of a rounding direction macro, */ +/* the rounding direction is not changed. */ +/* d*/ + +/*r */ +/* The fesetround function returns a zero value if and only if the argument is equal to a */ +/* rounding direction macro (that is, if and only if the requested rounding direction was */ +/* established). */ +/* r*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fetestexcept.c b/src/fenv/fetestexcept.c new file mode 100644 index 00000000..185fc530 --- /dev/null +++ b/src/fenv/fetestexcept.c @@ -0,0 +1,33 @@ +#include <fenv.h> + +int fetestexcept(int excepts) +{ + return excepts; +} + +/*d +The fetestexcept function determines which of a specified subset of the floating- +point exception flags are currently set. The excepts argument specifies the floating- +point status flags to be queried. 179) +d*/ + +/*r +The fetestexcept function returns the value of the bitwise OR of the floating-point +exception macros corresponding to the currently set floating-point exceptions included in +excepts. +r*/ + +/* example + #pragma STDC FENV_ACCESS ON + int set_excepts; + feclearexcept(FE_INVALID | FE_OVERFLOW); + // maybe raise exceptions + set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW); + if (set_excepts & FE_INVALID) f(); + if (set_excepts & FE_OVERFLOW) g(); +*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/feupdateenv.c b/src/fenv/feupdateenv.c new file mode 100644 index 00000000..b11a20fc --- /dev/null +++ b/src/fenv/feupdateenv.c @@ -0,0 +1,19 @@ +#include <fenv.h> + +int feupdateenv(const fenv_t *envp) +{ + return 0; +} + +/*d */ +/* The feupdateenv function saves the currently raised floating-point exceptions in its */ +/* automatic storage, installs the floating-point environment represented by the object */ +/* pointed to by envp, and then raises the saved floating-point exceptions. The argument */ +/* envp shall point to an object set by a call to feholdexcept or fegetenv, or equal a */ +/* floating-point environment macro. */ +/* d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/fenv/fexcept_t.c b/src/fenv/fexcept_t.c new file mode 100644 index 00000000..9bc9303b --- /dev/null +++ b/src/fenv/fexcept_t.c @@ -0,0 +1,11 @@ +#include <fenv.h> + +typedef unsigned long long int fexcept_t; + +/*d Represents the floating-point status flags collectively, including any status the */ +/* implementation associates with the flags. d*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/float/DBL_DIG.c b/src/float/DBL_DIG.c new file mode 100644 index 00000000..9f656012 --- /dev/null +++ b/src/float/DBL_DIG.c @@ -0,0 +1,16 @@ +#include <float.h> +#define DBL_DIG (15) + +/** double significant digits **/ + +/*** +is the number of significant digits in a decimal representation of a +TYPE(double) that are guaranteed accuracy. +***/ + +/* +VALUE_MIN(10) +*/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_EPSILON.c b/src/float/DBL_EPSILON.c new file mode 100644 index 00000000..5e4bd6b8 --- /dev/null +++ b/src/float/DBL_EPSILON.c @@ -0,0 +1,16 @@ +#include <float.h> +#define DBL_EPSILON (2.220446E-16) + +/** double epsilon **/ + +/*** +is the difference between LITERAL(1) and the next smallest number +representable as a TYPE(double). +***/ + +/* +VALUE_MIN(1e-9) +*/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MANT_DIG.c b/src/float/DBL_MANT_DIG.c new file mode 100644 index 00000000..b89e6ac1 --- /dev/null +++ b/src/float/DBL_MANT_DIG.c @@ -0,0 +1,13 @@ +#include <float.h> +#define DBL_MANT_DIG (53) + +/** double mantissa **/ + +/*** +is the number of digits, in base-IDENTIFIER(FLT_RADIX), in the +floating-point significand for TYPE(double) variables. It is not necessarily +a constant value. +***/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MAX.c b/src/float/DBL_MAX.c new file mode 100644 index 00000000..91d1e704 --- /dev/null +++ b/src/float/DBL_MAX.c @@ -0,0 +1,15 @@ +#include <float.h> +#define DBL_MAX (1.797693E+308) + +/** double maximum value **/ + +/*** +is the maximum representable finite TYPE(double) value. +***/ + +/* +VALUE_MIN(1e+37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MAX_10_EXP.c b/src/float/DBL_MAX_10_EXP.c new file mode 100644 index 00000000..8238d34b --- /dev/null +++ b/src/float/DBL_MAX_10_EXP.c @@ -0,0 +1,16 @@ +#include <float.h> +#define DBL_MAX_10_EXP (308) + +/** double maximum base-10 exponent **/ + +/*** +is the largest integer for which POW(10,THIS()) is a finite +TYPE(double). +***/ + +/* +VALUE_MIN(37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MAX_EXP.c b/src/float/DBL_MAX_EXP.c new file mode 100644 index 00000000..38fdb2a8 --- /dev/null +++ b/src/float/DBL_MAX_EXP.c @@ -0,0 +1,12 @@ +#include <float.h> +#define DBL_MAX_EXP (1024) + +/** double maximum exponent **/ + +/*** +is the largest integer for which +POW(IDENTIFIER(FLT_RADIX),THIS() - 1) is a finite TYPE(double). +***/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MIN.c b/src/float/DBL_MIN.c new file mode 100644 index 00000000..7f3c9ce1 --- /dev/null +++ b/src/float/DBL_MIN.c @@ -0,0 +1,15 @@ +#include <float.h> +#define DBL_MIN (2.225074E-308) + +/** double minimum positive number **/ + +/*** +is the smallest normalized value of a TYPE(double). +***/ + +/* +VALUE_MIN(1e-37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MIN_10_EXP.c b/src/float/DBL_MIN_10_EXP.c new file mode 100644 index 00000000..f329b0a1 --- /dev/null +++ b/src/float/DBL_MIN_10_EXP.c @@ -0,0 +1,16 @@ +#include <float.h> +#define DBL_MIN_10_EXP (-307) + +/** double minimum base-10 exponent **/ + +/*** +is the smallest negative integer for which POW(10, THIS()) +is a normalized TYPE(double). +***/ + +/* +VALUE_MIN(-37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/DBL_MIN_EXP.c b/src/float/DBL_MIN_EXP.c new file mode 100644 index 00000000..cc5dd645 --- /dev/null +++ b/src/float/DBL_MIN_EXP.c @@ -0,0 +1,12 @@ +#include <float.h> +#define DBL_MIN_EXP (-1021) + +/** double minimum exponent **/ + +/*** +is the smallest negative integer for which +POW(IDENTIFIER(FLT_RADIX), THIS() - 1) is a normalized TYPE(double). +***/ +/* +STDC(1) +*/ diff --git a/src/float/DECIMAL_DIG.c b/src/float/DECIMAL_DIG.c new file mode 100644 index 00000000..6003cb49 --- /dev/null +++ b/src/float/DECIMAL_DIG.c @@ -0,0 +1,10 @@ +#include <float.h> + +#define DECIMAL_DIG (10) + +/* MIN: 10 */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/float/FLT_DIG.c b/src/float/FLT_DIG.c new file mode 100644 index 00000000..43a17c3f --- /dev/null +++ b/src/float/FLT_DIG.c @@ -0,0 +1,16 @@ +#include <float.h> +#define FLT_DIG (6) + +/** float significant digits **/ + +/*** +is the number of significant digits in a decimal representation of a +TYPE(float) that are guaranteed accuracy. +***/ + +/* +VALUE_MIN(6) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_EPSILON.c b/src/float/FLT_EPSILON.c new file mode 100644 index 00000000..31640457 --- /dev/null +++ b/src/float/FLT_EPSILON.c @@ -0,0 +1,16 @@ +#include <float.h> +#define FLT_EPSILON (1.192093E-07) + +/** float epsilon **/ + +/*** +is the difference between LITERAL(1) and the next smallest number +representable as a TYPE(float). +***/ + +/* +VALUE_MIN(1e-5) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_EVAL_METHOD.c b/src/float/FLT_EVAL_METHOD.c new file mode 100644 index 00000000..46fa8194 --- /dev/null +++ b/src/float/FLT_EVAL_METHOD.c @@ -0,0 +1,13 @@ +#include <float.h> + +#define FLT_EVAL_METHOD (-1) + +/* -1: indeterminable */ +/* 0: float as float; double as double; long double as long double */ +/* 1: float as double; double as double; long double as long double */ +/* 2: all as long double */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/float/FLT_MANT_DIG.c b/src/float/FLT_MANT_DIG.c new file mode 100644 index 00000000..608ff5f9 --- /dev/null +++ b/src/float/FLT_MANT_DIG.c @@ -0,0 +1,13 @@ +#include <float.h> +#define FLT_MANT_DIG (24) + +/** float mantissa **/ + +/*** +is the number of digits, in base-IDENTIFIER(FLT_RADIX), in the +floating-point significand for TYPE(float) variables. It is not necessarily +a constant value. +***/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_MAX.c b/src/float/FLT_MAX.c new file mode 100644 index 00000000..ecd59b0d --- /dev/null +++ b/src/float/FLT_MAX.c @@ -0,0 +1,15 @@ +#include <float.h> +#define FLT_MAX (3.402823E+38) + +/** float maximum value **/ + +/*** +is the maximum representable finite TYPE(float) value. +***/ + +/* +VALUE_MIN(1e+37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_MAX_10_EXP.c b/src/float/FLT_MAX_10_EXP.c new file mode 100644 index 00000000..2b64a7e7 --- /dev/null +++ b/src/float/FLT_MAX_10_EXP.c @@ -0,0 +1,15 @@ +#include <float.h> +#define FLT_MAX_10_EXP (38) + +/** float maximum base-10 exponent **/ + +/*** +is the largest integer for which POW(10, THIS()) is a finite TYPE(float). +***/ + +/* +VALUE_MIN(37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_MAX_EXP.c b/src/float/FLT_MAX_EXP.c new file mode 100644 index 00000000..d912e1ec --- /dev/null +++ b/src/float/FLT_MAX_EXP.c @@ -0,0 +1,12 @@ +#include <float.h> +#define FLT_MAX_EXP (128) + +/** float maximum exponent **/ + +/*** +is the largest integer for which +POW(IDENTIFIER(FLT_RADIX), THIS() - 1) is a finite TYPE(float). +***/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_MIN.c b/src/float/FLT_MIN.c new file mode 100644 index 00000000..aac248c5 --- /dev/null +++ b/src/float/FLT_MIN.c @@ -0,0 +1,15 @@ +#include <float.h> +#define FLT_MIN (1.175494E-38) + +/** float minimum positive number **/ + +/*** +is the smallest normalized value of a TYPE(float). +***/ + +/* +VALUE_MIN(1e-37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_MIN_10_EXP.c b/src/float/FLT_MIN_10_EXP.c new file mode 100644 index 00000000..57f9eb95 --- /dev/null +++ b/src/float/FLT_MIN_10_EXP.c @@ -0,0 +1,16 @@ +#include <float.h> +#define FLT_MIN_10_EXP (-37) + +/** float minimum base-10 exponent **/ + +/*** +is the smallest negative integer for which POW(10, THIS()) +is a normalized TYPE(float). +***/ + +/* +VALUE_MIN(-37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_MIN_EXP.c b/src/float/FLT_MIN_EXP.c new file mode 100644 index 00000000..682c8d4f --- /dev/null +++ b/src/float/FLT_MIN_EXP.c @@ -0,0 +1,12 @@ +#include <float.h> +#define FLT_MIN_EXP (-125) + +/** float minimum exponent **/ + +/*** +is the smallest negative integer for which +POW(IDENTIFIER(FLT_RADIX), THIS() - 1) is a normalized TYPE(float). +***/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_RADIX.c b/src/float/FLT_RADIX.c new file mode 100644 index 00000000..47978707 --- /dev/null +++ b/src/float/FLT_RADIX.c @@ -0,0 +1,16 @@ +#include <float.h> +#define FLT_RADIX (2) + +/** radix of exponent representation **/ + +/*** +is a constant defining the radix used by the implementation for +exponent notation. It is suitable for use in LITERAL(#if) directives. +***/ + +/* +VALUE_MIN(2) +*/ +/* +STDC(1) +*/ diff --git a/src/float/FLT_ROUNDS.c b/src/float/FLT_ROUNDS.c new file mode 100644 index 00000000..8fefb48e --- /dev/null +++ b/src/float/FLT_ROUNDS.c @@ -0,0 +1,22 @@ +#include <float.h> + extern int fegetround(void); +#define FLT_ROUNDS fegetround() + +/** rounding direction **/ + +/*** +describes the rounding mode of floating-point addition used by the +implementation. It is not necessarily constant. +***/ + +/* +VALUE_SELECT(-1, indeterminable) +VALUE_SELECT(0, toward zero) +VALUE_SELECT(1, to nearest) +VALUE_SELECT(2, toward positive infinity) +VALUE_SELECT(3, toward negative infinity) +SEE_ALSO(FUNCTION(fegetround)) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_DIG.c b/src/float/LDBL_DIG.c new file mode 100644 index 00000000..f986ecc2 --- /dev/null +++ b/src/float/LDBL_DIG.c @@ -0,0 +1,16 @@ +#include <float.h> +#define LDBL_DIG (15) + +/** long double significant digits **/ + +/*** +is the number of significant digits in a decimal representation of a +TYPE(long double) that are guaranteed accuracy. +***/ + +/* +VALUE_MIN(10) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_EPSILON.c b/src/float/LDBL_EPSILON.c new file mode 100644 index 00000000..ebc089a4 --- /dev/null +++ b/src/float/LDBL_EPSILON.c @@ -0,0 +1,16 @@ +#include <float.h> +#define LDBL_EPSILON (2.220446E-16) + +/** long double epsilon **/ + +/*** +is the difference between LITERAL(1) and the next smallest number +representable as a TYPE(long double). +***/ + +/* +VALUE_MIN(1e-9) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MANT_DIG.c b/src/float/LDBL_MANT_DIG.c new file mode 100644 index 00000000..19c85a9e --- /dev/null +++ b/src/float/LDBL_MANT_DIG.c @@ -0,0 +1,13 @@ +#include <float.h> +#define LDBL_MANT_DIG (53) + +/** long double mantissa **/ + +/*** +is the number of digits, in base-IDENTIFIER(FLT_RADIX), in the +floating-point significand for TYPE(long double) variables. It is not +necessarily a constant value. +***/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MAX.c b/src/float/LDBL_MAX.c new file mode 100644 index 00000000..4ca1301a --- /dev/null +++ b/src/float/LDBL_MAX.c @@ -0,0 +1,15 @@ +#include <float.h> +#define LDBL_MAX (1.797693E+308) + +/** long double maximum value **/ + +/*** +is the maximum representable finite TYPE(long double) value. +***/ + +/* +VALUE_MIN(1e+37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MAX_10_EXP.c b/src/float/LDBL_MAX_10_EXP.c new file mode 100644 index 00000000..6ff02738 --- /dev/null +++ b/src/float/LDBL_MAX_10_EXP.c @@ -0,0 +1,16 @@ +#include <float.h> +#define LDBL_MAX_10_EXP (308) + +/** long double maximum base-10 exponent **/ + +/*** +is the largest integer for which POW(10, THIS()) is a finite +TYPE(long double). +***/ + +/* +VALUE_MIN(37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MAX_EXP.c b/src/float/LDBL_MAX_EXP.c new file mode 100644 index 00000000..e52d91e5 --- /dev/null +++ b/src/float/LDBL_MAX_EXP.c @@ -0,0 +1,12 @@ +#include <float.h> +#define LDBL_MAX_EXP (1024) + +/** long double maximum exponent **/ + +/*** +is the largest integer for which +POW(IDENTIFIER(FLT_RADIX), THIS() - 1) is a finite TYPE(long double). +***/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MIN.c b/src/float/LDBL_MIN.c new file mode 100644 index 00000000..0416fe71 --- /dev/null +++ b/src/float/LDBL_MIN.c @@ -0,0 +1,15 @@ +#include <float.h> +#define LDBL_MIN (2.225074E-308) + +/** long double minimum positive number **/ + +/*** +is the smallest normalized value of a TYPE(long double). +***/ + +/* +VALUE_MIN(1e-37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MIN_10_EXP.c b/src/float/LDBL_MIN_10_EXP.c new file mode 100644 index 00000000..6876716d --- /dev/null +++ b/src/float/LDBL_MIN_10_EXP.c @@ -0,0 +1,16 @@ +#include <float.h> +#define LDBL_MIN_10_EXP (-37) + +/** long double minimum base-10 exponent **/ + +/*** +is the smallest negative integer for which POW(10, THIS()) +is a normalized TYPE(long double). +***/ + +/* +VALUE_MIN(-37) +*/ +/* +STDC(1) +*/ diff --git a/src/float/LDBL_MIN_EXP.c b/src/float/LDBL_MIN_EXP.c new file mode 100644 index 00000000..ea65763e --- /dev/null +++ b/src/float/LDBL_MIN_EXP.c @@ -0,0 +1,12 @@ +#include <float.h> +#define LDBL_MIN_EXP (-1021) + +/** long double minimum exponent **/ + +/*** +is the smallest negative integer for which +POW(IDENTIFIER(FLT_RADIX), THIS() - 1) is a normalized TYPE(long double). +***/ +/* +STDC(1) +*/ diff --git a/src/inttypes/PRIX16.c b/src/inttypes/PRIX16.c new file mode 100644 index 00000000..43037496 --- /dev/null +++ b/src/inttypes/PRIX16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIX16 "hX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIX32.c b/src/inttypes/PRIX32.c new file mode 100644 index 00000000..4e6a4537 --- /dev/null +++ b/src/inttypes/PRIX32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIX32 "lX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIX64.c b/src/inttypes/PRIX64.c new file mode 100644 index 00000000..a3f89758 --- /dev/null +++ b/src/inttypes/PRIX64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIX64 "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIX8.c b/src/inttypes/PRIX8.c new file mode 100644 index 00000000..ab14eed0 --- /dev/null +++ b/src/inttypes/PRIX8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIX8 "hhX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXFAST16.c b/src/inttypes/PRIXFAST16.c new file mode 100644 index 00000000..fd25c10b --- /dev/null +++ b/src/inttypes/PRIXFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXFAST16 "hX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXFAST32.c b/src/inttypes/PRIXFAST32.c new file mode 100644 index 00000000..35089f43 --- /dev/null +++ b/src/inttypes/PRIXFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXFAST32 "lX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXFAST64.c b/src/inttypes/PRIXFAST64.c new file mode 100644 index 00000000..4020cf9d --- /dev/null +++ b/src/inttypes/PRIXFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXFAST64 "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXFAST8.c b/src/inttypes/PRIXFAST8.c new file mode 100644 index 00000000..de0844f1 --- /dev/null +++ b/src/inttypes/PRIXFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXFAST8 "hhX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXLEAST16.c b/src/inttypes/PRIXLEAST16.c new file mode 100644 index 00000000..be53a993 --- /dev/null +++ b/src/inttypes/PRIXLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXLEAST16 "hX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXLEAST32.c b/src/inttypes/PRIXLEAST32.c new file mode 100644 index 00000000..cea7217a --- /dev/null +++ b/src/inttypes/PRIXLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXLEAST32 "lX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXLEAST64.c b/src/inttypes/PRIXLEAST64.c new file mode 100644 index 00000000..0d5c7ace --- /dev/null +++ b/src/inttypes/PRIXLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXLEAST64 "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXLEAST8.c b/src/inttypes/PRIXLEAST8.c new file mode 100644 index 00000000..2cc09910 --- /dev/null +++ b/src/inttypes/PRIXLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXLEAST8 "hhX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXMAX.c b/src/inttypes/PRIXMAX.c new file mode 100644 index 00000000..8d5a3be1 --- /dev/null +++ b/src/inttypes/PRIXMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIXMAX "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIXPTR.c b/src/inttypes/PRIXPTR.c new file mode 100644 index 00000000..0662addf --- /dev/null +++ b/src/inttypes/PRIXPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define PRIXPTR "llX" +#else +#define PRIXPTR "lX" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRId16.c b/src/inttypes/PRId16.c new file mode 100644 index 00000000..68f20b10 --- /dev/null +++ b/src/inttypes/PRId16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRId16 "hd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRId32.c b/src/inttypes/PRId32.c new file mode 100644 index 00000000..d6523c32 --- /dev/null +++ b/src/inttypes/PRId32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRId32 "ld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRId64.c b/src/inttypes/PRId64.c new file mode 100644 index 00000000..5f3a1b21 --- /dev/null +++ b/src/inttypes/PRId64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRId64 "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRId8.c b/src/inttypes/PRId8.c new file mode 100644 index 00000000..161e822e --- /dev/null +++ b/src/inttypes/PRId8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRId8 "hhd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdFAST16.c b/src/inttypes/PRIdFAST16.c new file mode 100644 index 00000000..794ed0bb --- /dev/null +++ b/src/inttypes/PRIdFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdFAST16 "hd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdFAST32.c b/src/inttypes/PRIdFAST32.c new file mode 100644 index 00000000..29ccc501 --- /dev/null +++ b/src/inttypes/PRIdFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdFAST32 "ld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdFAST64.c b/src/inttypes/PRIdFAST64.c new file mode 100644 index 00000000..6e7b2682 --- /dev/null +++ b/src/inttypes/PRIdFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdFAST64 "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdFAST8.c b/src/inttypes/PRIdFAST8.c new file mode 100644 index 00000000..b13303ef --- /dev/null +++ b/src/inttypes/PRIdFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdFAST8 "hhd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdLEAST16.c b/src/inttypes/PRIdLEAST16.c new file mode 100644 index 00000000..ddfc428f --- /dev/null +++ b/src/inttypes/PRIdLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdLEAST16 "hd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdLEAST32.c b/src/inttypes/PRIdLEAST32.c new file mode 100644 index 00000000..a507ddea --- /dev/null +++ b/src/inttypes/PRIdLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdLEAST32 "ld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdLEAST64.c b/src/inttypes/PRIdLEAST64.c new file mode 100644 index 00000000..5f9847cf --- /dev/null +++ b/src/inttypes/PRIdLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdLEAST64 "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdLEAST8.c b/src/inttypes/PRIdLEAST8.c new file mode 100644 index 00000000..7de17746 --- /dev/null +++ b/src/inttypes/PRIdLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdLEAST8 "hhd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdMAX.c b/src/inttypes/PRIdMAX.c new file mode 100644 index 00000000..726e0b06 --- /dev/null +++ b/src/inttypes/PRIdMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIdMAX "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIdPTR.c b/src/inttypes/PRIdPTR.c new file mode 100644 index 00000000..cb7ae693 --- /dev/null +++ b/src/inttypes/PRIdPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define PRIdPTR "lld" +#else +#define PRIdPTR "ld" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIi16.c b/src/inttypes/PRIi16.c new file mode 100644 index 00000000..8d965845 --- /dev/null +++ b/src/inttypes/PRIi16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIi16 "hi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIi32.c b/src/inttypes/PRIi32.c new file mode 100644 index 00000000..cafacca4 --- /dev/null +++ b/src/inttypes/PRIi32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIi32 "li" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIi64.c b/src/inttypes/PRIi64.c new file mode 100644 index 00000000..8a803ccb --- /dev/null +++ b/src/inttypes/PRIi64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIi64 "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIi8.c b/src/inttypes/PRIi8.c new file mode 100644 index 00000000..68e7cf09 --- /dev/null +++ b/src/inttypes/PRIi8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIi8 "hhi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiFAST16.c b/src/inttypes/PRIiFAST16.c new file mode 100644 index 00000000..859a1b9b --- /dev/null +++ b/src/inttypes/PRIiFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiFAST16 "hi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiFAST32.c b/src/inttypes/PRIiFAST32.c new file mode 100644 index 00000000..133a3fff --- /dev/null +++ b/src/inttypes/PRIiFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiFAST32 "li" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiFAST64.c b/src/inttypes/PRIiFAST64.c new file mode 100644 index 00000000..e4787e14 --- /dev/null +++ b/src/inttypes/PRIiFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiFAST64 "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiFAST8.c b/src/inttypes/PRIiFAST8.c new file mode 100644 index 00000000..068c4a14 --- /dev/null +++ b/src/inttypes/PRIiFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiFAST8 "hhi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiLEAST16.c b/src/inttypes/PRIiLEAST16.c new file mode 100644 index 00000000..6f5a8953 --- /dev/null +++ b/src/inttypes/PRIiLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiLEAST16 "hi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiLEAST32.c b/src/inttypes/PRIiLEAST32.c new file mode 100644 index 00000000..213a3c38 --- /dev/null +++ b/src/inttypes/PRIiLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiLEAST32 "li" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiLEAST64.c b/src/inttypes/PRIiLEAST64.c new file mode 100644 index 00000000..60e0bacc --- /dev/null +++ b/src/inttypes/PRIiLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiLEAST64 "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiLEAST8.c b/src/inttypes/PRIiLEAST8.c new file mode 100644 index 00000000..f34186ed --- /dev/null +++ b/src/inttypes/PRIiLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiLEAST8 "hhi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiMAX.c b/src/inttypes/PRIiMAX.c new file mode 100644 index 00000000..d6ef5b6b --- /dev/null +++ b/src/inttypes/PRIiMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIiMAX "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIiPTR.c b/src/inttypes/PRIiPTR.c new file mode 100644 index 00000000..c13ae15f --- /dev/null +++ b/src/inttypes/PRIiPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define PRIiPTR "lli" +#else +#define PRIiPTR "li" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIo16.c b/src/inttypes/PRIo16.c new file mode 100644 index 00000000..316dbc4a --- /dev/null +++ b/src/inttypes/PRIo16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIo16 "ho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIo32.c b/src/inttypes/PRIo32.c new file mode 100644 index 00000000..9b3f375e --- /dev/null +++ b/src/inttypes/PRIo32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIo32 "lo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIo64.c b/src/inttypes/PRIo64.c new file mode 100644 index 00000000..b455e7d3 --- /dev/null +++ b/src/inttypes/PRIo64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIo64 "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIo8.c b/src/inttypes/PRIo8.c new file mode 100644 index 00000000..fc205050 --- /dev/null +++ b/src/inttypes/PRIo8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIo8 "hho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoFAST16.c b/src/inttypes/PRIoFAST16.c new file mode 100644 index 00000000..27c5deac --- /dev/null +++ b/src/inttypes/PRIoFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoFAST16 "ho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoFAST32.c b/src/inttypes/PRIoFAST32.c new file mode 100644 index 00000000..4a54eb4d --- /dev/null +++ b/src/inttypes/PRIoFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoFAST32 "lo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoFAST64.c b/src/inttypes/PRIoFAST64.c new file mode 100644 index 00000000..0655405c --- /dev/null +++ b/src/inttypes/PRIoFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoFAST64 "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoFAST8.c b/src/inttypes/PRIoFAST8.c new file mode 100644 index 00000000..1d285e5d --- /dev/null +++ b/src/inttypes/PRIoFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoFAST8 "hho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoLEAST16.c b/src/inttypes/PRIoLEAST16.c new file mode 100644 index 00000000..cbf8710c --- /dev/null +++ b/src/inttypes/PRIoLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoLEAST16 "ho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoLEAST32.c b/src/inttypes/PRIoLEAST32.c new file mode 100644 index 00000000..7716e34d --- /dev/null +++ b/src/inttypes/PRIoLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoLEAST32 "lo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoLEAST64.c b/src/inttypes/PRIoLEAST64.c new file mode 100644 index 00000000..2d04aa30 --- /dev/null +++ b/src/inttypes/PRIoLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoLEAST64 "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoLEAST8.c b/src/inttypes/PRIoLEAST8.c new file mode 100644 index 00000000..9d32aa6c --- /dev/null +++ b/src/inttypes/PRIoLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoLEAST8 "hho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoMAX.c b/src/inttypes/PRIoMAX.c new file mode 100644 index 00000000..10c50fb0 --- /dev/null +++ b/src/inttypes/PRIoMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIoMAX "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIoPTR.c b/src/inttypes/PRIoPTR.c new file mode 100644 index 00000000..c5d504d5 --- /dev/null +++ b/src/inttypes/PRIoPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define PRIoPTR "llo" +#else +#define PRIoPTR "lo" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIu16.c b/src/inttypes/PRIu16.c new file mode 100644 index 00000000..604ce7ce --- /dev/null +++ b/src/inttypes/PRIu16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIu16 "hu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIu32.c b/src/inttypes/PRIu32.c new file mode 100644 index 00000000..0c34611d --- /dev/null +++ b/src/inttypes/PRIu32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIu32 "lu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIu64.c b/src/inttypes/PRIu64.c new file mode 100644 index 00000000..8e600238 --- /dev/null +++ b/src/inttypes/PRIu64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIu64 "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIu8.c b/src/inttypes/PRIu8.c new file mode 100644 index 00000000..57dde7bc --- /dev/null +++ b/src/inttypes/PRIu8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIu8 "hhu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuFAST16.c b/src/inttypes/PRIuFAST16.c new file mode 100644 index 00000000..ca73dc01 --- /dev/null +++ b/src/inttypes/PRIuFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuFAST16 "hu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuFAST32.c b/src/inttypes/PRIuFAST32.c new file mode 100644 index 00000000..e616578e --- /dev/null +++ b/src/inttypes/PRIuFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuFAST32 "lu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuFAST64.c b/src/inttypes/PRIuFAST64.c new file mode 100644 index 00000000..256089cd --- /dev/null +++ b/src/inttypes/PRIuFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuFAST64 "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuFAST8.c b/src/inttypes/PRIuFAST8.c new file mode 100644 index 00000000..a6a2b291 --- /dev/null +++ b/src/inttypes/PRIuFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuFAST8 "hhu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuLEAST16.c b/src/inttypes/PRIuLEAST16.c new file mode 100644 index 00000000..35b5ca0e --- /dev/null +++ b/src/inttypes/PRIuLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuLEAST16 "hu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuLEAST32.c b/src/inttypes/PRIuLEAST32.c new file mode 100644 index 00000000..f8a8b5aa --- /dev/null +++ b/src/inttypes/PRIuLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuLEAST32 "lu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuLEAST64.c b/src/inttypes/PRIuLEAST64.c new file mode 100644 index 00000000..f9b3ba9a --- /dev/null +++ b/src/inttypes/PRIuLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuLEAST64 "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuLEAST8.c b/src/inttypes/PRIuLEAST8.c new file mode 100644 index 00000000..c88eaf46 --- /dev/null +++ b/src/inttypes/PRIuLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuLEAST8 "hhu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuMAX.c b/src/inttypes/PRIuMAX.c new file mode 100644 index 00000000..4f097cdc --- /dev/null +++ b/src/inttypes/PRIuMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIuMAX "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIuPTR.c b/src/inttypes/PRIuPTR.c new file mode 100644 index 00000000..23c8ab1f --- /dev/null +++ b/src/inttypes/PRIuPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define PRIuPTR "llu" +#else +#define PRIuPTR "lu" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIx16.c b/src/inttypes/PRIx16.c new file mode 100644 index 00000000..fe401ede --- /dev/null +++ b/src/inttypes/PRIx16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIx16 "hx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIx32.c b/src/inttypes/PRIx32.c new file mode 100644 index 00000000..a666bfb8 --- /dev/null +++ b/src/inttypes/PRIx32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIx32 "lx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIx64.c b/src/inttypes/PRIx64.c new file mode 100644 index 00000000..7eda1a13 --- /dev/null +++ b/src/inttypes/PRIx64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIx64 "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIx8.c b/src/inttypes/PRIx8.c new file mode 100644 index 00000000..af06ea27 --- /dev/null +++ b/src/inttypes/PRIx8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIx8 "hhx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxFAST16.c b/src/inttypes/PRIxFAST16.c new file mode 100644 index 00000000..f2769064 --- /dev/null +++ b/src/inttypes/PRIxFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxFAST16 "hx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxFAST32.c b/src/inttypes/PRIxFAST32.c new file mode 100644 index 00000000..1ef38020 --- /dev/null +++ b/src/inttypes/PRIxFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxFAST32 "lx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxFAST64.c b/src/inttypes/PRIxFAST64.c new file mode 100644 index 00000000..299de94a --- /dev/null +++ b/src/inttypes/PRIxFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxFAST64 "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxFAST8.c b/src/inttypes/PRIxFAST8.c new file mode 100644 index 00000000..d6430971 --- /dev/null +++ b/src/inttypes/PRIxFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxFAST8 "hhx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxLEAST16.c b/src/inttypes/PRIxLEAST16.c new file mode 100644 index 00000000..570c7d33 --- /dev/null +++ b/src/inttypes/PRIxLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxLEAST16 "hx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxLEAST32.c b/src/inttypes/PRIxLEAST32.c new file mode 100644 index 00000000..f6286296 --- /dev/null +++ b/src/inttypes/PRIxLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxLEAST32 "lx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxLEAST64.c b/src/inttypes/PRIxLEAST64.c new file mode 100644 index 00000000..cf0ccf8a --- /dev/null +++ b/src/inttypes/PRIxLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxLEAST64 "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxLEAST8.c b/src/inttypes/PRIxLEAST8.c new file mode 100644 index 00000000..fdff01e7 --- /dev/null +++ b/src/inttypes/PRIxLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxLEAST8 "hhx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxMAX.c b/src/inttypes/PRIxMAX.c new file mode 100644 index 00000000..e5b026b1 --- /dev/null +++ b/src/inttypes/PRIxMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define PRIxMAX "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/PRIxPTR.c b/src/inttypes/PRIxPTR.c new file mode 100644 index 00000000..1ff9a6d3 --- /dev/null +++ b/src/inttypes/PRIxPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define PRIxPTR "llx" +#else +#define PRIxPTR "lx" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNX16.c b/src/inttypes/SCNX16.c new file mode 100644 index 00000000..875d0f62 --- /dev/null +++ b/src/inttypes/SCNX16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNX16 "hX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNX32.c b/src/inttypes/SCNX32.c new file mode 100644 index 00000000..ae82ba02 --- /dev/null +++ b/src/inttypes/SCNX32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNX32 "lX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNX64.c b/src/inttypes/SCNX64.c new file mode 100644 index 00000000..b05e6885 --- /dev/null +++ b/src/inttypes/SCNX64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNX64 "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNX8.c b/src/inttypes/SCNX8.c new file mode 100644 index 00000000..4a3d0bca --- /dev/null +++ b/src/inttypes/SCNX8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNX8 "hhX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXFAST16.c b/src/inttypes/SCNXFAST16.c new file mode 100644 index 00000000..e4824a7b --- /dev/null +++ b/src/inttypes/SCNXFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXFAST16 "hX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXFAST32.c b/src/inttypes/SCNXFAST32.c new file mode 100644 index 00000000..98065c38 --- /dev/null +++ b/src/inttypes/SCNXFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXFAST32 "lX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXFAST64.c b/src/inttypes/SCNXFAST64.c new file mode 100644 index 00000000..3c74d976 --- /dev/null +++ b/src/inttypes/SCNXFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXFAST64 "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXFAST8.c b/src/inttypes/SCNXFAST8.c new file mode 100644 index 00000000..1509e276 --- /dev/null +++ b/src/inttypes/SCNXFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXFAST8 "hhX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXLEAST16.c b/src/inttypes/SCNXLEAST16.c new file mode 100644 index 00000000..0e02bbd2 --- /dev/null +++ b/src/inttypes/SCNXLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXLEAST16 "hX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXLEAST32.c b/src/inttypes/SCNXLEAST32.c new file mode 100644 index 00000000..30731e1c --- /dev/null +++ b/src/inttypes/SCNXLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXLEAST32 "lX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXLEAST64.c b/src/inttypes/SCNXLEAST64.c new file mode 100644 index 00000000..266e8aa0 --- /dev/null +++ b/src/inttypes/SCNXLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXLEAST64 "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXLEAST8.c b/src/inttypes/SCNXLEAST8.c new file mode 100644 index 00000000..59c86e16 --- /dev/null +++ b/src/inttypes/SCNXLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXLEAST8 "hhX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXMAX.c b/src/inttypes/SCNXMAX.c new file mode 100644 index 00000000..b5490147 --- /dev/null +++ b/src/inttypes/SCNXMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNXMAX "llX" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNXPTR.c b/src/inttypes/SCNXPTR.c new file mode 100644 index 00000000..7df00b29 --- /dev/null +++ b/src/inttypes/SCNXPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define SCNXPTR "llX" +#else +#define SCNXPTR "lX" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNd16.c b/src/inttypes/SCNd16.c new file mode 100644 index 00000000..f8e6abdd --- /dev/null +++ b/src/inttypes/SCNd16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNd16 "hd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNd32.c b/src/inttypes/SCNd32.c new file mode 100644 index 00000000..ede6aedf --- /dev/null +++ b/src/inttypes/SCNd32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNd32 "ld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNd64.c b/src/inttypes/SCNd64.c new file mode 100644 index 00000000..72782571 --- /dev/null +++ b/src/inttypes/SCNd64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNd64 "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNd8.c b/src/inttypes/SCNd8.c new file mode 100644 index 00000000..b009a790 --- /dev/null +++ b/src/inttypes/SCNd8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNd8 "hhd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdFAST16.c b/src/inttypes/SCNdFAST16.c new file mode 100644 index 00000000..4df0ab71 --- /dev/null +++ b/src/inttypes/SCNdFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdFAST16 "hd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdFAST32.c b/src/inttypes/SCNdFAST32.c new file mode 100644 index 00000000..4a4d6642 --- /dev/null +++ b/src/inttypes/SCNdFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdFAST32 "ld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdFAST64.c b/src/inttypes/SCNdFAST64.c new file mode 100644 index 00000000..b1c62250 --- /dev/null +++ b/src/inttypes/SCNdFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdFAST64 "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdFAST8.c b/src/inttypes/SCNdFAST8.c new file mode 100644 index 00000000..edf1e334 --- /dev/null +++ b/src/inttypes/SCNdFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdFAST8 "hhd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdLEAST16.c b/src/inttypes/SCNdLEAST16.c new file mode 100644 index 00000000..0cd349bd --- /dev/null +++ b/src/inttypes/SCNdLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdLEAST16 "hd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdLEAST32.c b/src/inttypes/SCNdLEAST32.c new file mode 100644 index 00000000..881b6c06 --- /dev/null +++ b/src/inttypes/SCNdLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdLEAST32 "ld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdLEAST64.c b/src/inttypes/SCNdLEAST64.c new file mode 100644 index 00000000..67cdad99 --- /dev/null +++ b/src/inttypes/SCNdLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdLEAST64 "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdLEAST8.c b/src/inttypes/SCNdLEAST8.c new file mode 100644 index 00000000..cfde7860 --- /dev/null +++ b/src/inttypes/SCNdLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdLEAST8 "hhd" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdMAX.c b/src/inttypes/SCNdMAX.c new file mode 100644 index 00000000..edeb1f6a --- /dev/null +++ b/src/inttypes/SCNdMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNdMAX "lld" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNdPTR.c b/src/inttypes/SCNdPTR.c new file mode 100644 index 00000000..c0c61d0a --- /dev/null +++ b/src/inttypes/SCNdPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define SCNdPTR "lld" +#else +#define SCNdPTR "ld" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNi16.c b/src/inttypes/SCNi16.c new file mode 100644 index 00000000..c262b47d --- /dev/null +++ b/src/inttypes/SCNi16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNi16 "hi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNi32.c b/src/inttypes/SCNi32.c new file mode 100644 index 00000000..bb3ecb30 --- /dev/null +++ b/src/inttypes/SCNi32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNi32 "li" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNi64.c b/src/inttypes/SCNi64.c new file mode 100644 index 00000000..f6d2e3ec --- /dev/null +++ b/src/inttypes/SCNi64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNi64 "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNi8.c b/src/inttypes/SCNi8.c new file mode 100644 index 00000000..f9a783e4 --- /dev/null +++ b/src/inttypes/SCNi8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNi8 "hhi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiFAST16.c b/src/inttypes/SCNiFAST16.c new file mode 100644 index 00000000..926936f1 --- /dev/null +++ b/src/inttypes/SCNiFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiFAST16 "hi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiFAST32.c b/src/inttypes/SCNiFAST32.c new file mode 100644 index 00000000..342cd571 --- /dev/null +++ b/src/inttypes/SCNiFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiFAST32 "li" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiFAST64.c b/src/inttypes/SCNiFAST64.c new file mode 100644 index 00000000..ef036928 --- /dev/null +++ b/src/inttypes/SCNiFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiFAST64 "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiFAST8.c b/src/inttypes/SCNiFAST8.c new file mode 100644 index 00000000..439ceeac --- /dev/null +++ b/src/inttypes/SCNiFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiFAST8 "hhi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiLEAST16.c b/src/inttypes/SCNiLEAST16.c new file mode 100644 index 00000000..fc6310ce --- /dev/null +++ b/src/inttypes/SCNiLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiLEAST16 "hi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiLEAST32.c b/src/inttypes/SCNiLEAST32.c new file mode 100644 index 00000000..7f1c9f44 --- /dev/null +++ b/src/inttypes/SCNiLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiLEAST32 "li" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiLEAST64.c b/src/inttypes/SCNiLEAST64.c new file mode 100644 index 00000000..ffcd8df6 --- /dev/null +++ b/src/inttypes/SCNiLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiLEAST64 "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiLEAST8.c b/src/inttypes/SCNiLEAST8.c new file mode 100644 index 00000000..099adc7c --- /dev/null +++ b/src/inttypes/SCNiLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiLEAST8 "hhi" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiMAX.c b/src/inttypes/SCNiMAX.c new file mode 100644 index 00000000..b6ef4cb9 --- /dev/null +++ b/src/inttypes/SCNiMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNiMAX "lli" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNiPTR.c b/src/inttypes/SCNiPTR.c new file mode 100644 index 00000000..50cb754a --- /dev/null +++ b/src/inttypes/SCNiPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define SCNiPTR "lli" +#else +#define SCNiPTR "li" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNo16.c b/src/inttypes/SCNo16.c new file mode 100644 index 00000000..173436ae --- /dev/null +++ b/src/inttypes/SCNo16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNo16 "ho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNo32.c b/src/inttypes/SCNo32.c new file mode 100644 index 00000000..bcb9fa2e --- /dev/null +++ b/src/inttypes/SCNo32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNo32 "lo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNo64.c b/src/inttypes/SCNo64.c new file mode 100644 index 00000000..6318248e --- /dev/null +++ b/src/inttypes/SCNo64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNo64 "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNo8.c b/src/inttypes/SCNo8.c new file mode 100644 index 00000000..3eaee589 --- /dev/null +++ b/src/inttypes/SCNo8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNo8 "hho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoFAST16.c b/src/inttypes/SCNoFAST16.c new file mode 100644 index 00000000..ee2b885f --- /dev/null +++ b/src/inttypes/SCNoFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoFAST16 "ho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoFAST32.c b/src/inttypes/SCNoFAST32.c new file mode 100644 index 00000000..5ab1d573 --- /dev/null +++ b/src/inttypes/SCNoFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoFAST32 "lo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoFAST64.c b/src/inttypes/SCNoFAST64.c new file mode 100644 index 00000000..0e400fcb --- /dev/null +++ b/src/inttypes/SCNoFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoFAST64 "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoFAST8.c b/src/inttypes/SCNoFAST8.c new file mode 100644 index 00000000..21a20cfb --- /dev/null +++ b/src/inttypes/SCNoFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoFAST8 "hho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoLEAST16.c b/src/inttypes/SCNoLEAST16.c new file mode 100644 index 00000000..c42d6b8a --- /dev/null +++ b/src/inttypes/SCNoLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoLEAST16 "ho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoLEAST32.c b/src/inttypes/SCNoLEAST32.c new file mode 100644 index 00000000..517981f1 --- /dev/null +++ b/src/inttypes/SCNoLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoLEAST32 "lo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoLEAST64.c b/src/inttypes/SCNoLEAST64.c new file mode 100644 index 00000000..a64e6315 --- /dev/null +++ b/src/inttypes/SCNoLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoLEAST64 "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoLEAST8.c b/src/inttypes/SCNoLEAST8.c new file mode 100644 index 00000000..3ddffcd5 --- /dev/null +++ b/src/inttypes/SCNoLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoLEAST8 "hho" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoMAX.c b/src/inttypes/SCNoMAX.c new file mode 100644 index 00000000..284b8328 --- /dev/null +++ b/src/inttypes/SCNoMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNoMAX "llo" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNoPTR.c b/src/inttypes/SCNoPTR.c new file mode 100644 index 00000000..b3d50767 --- /dev/null +++ b/src/inttypes/SCNoPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define SCNoPTR "llo" +#else +#define SCNoPTR "lo" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNu16.c b/src/inttypes/SCNu16.c new file mode 100644 index 00000000..7c9aa80d --- /dev/null +++ b/src/inttypes/SCNu16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNu16 "hu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNu32.c b/src/inttypes/SCNu32.c new file mode 100644 index 00000000..c79840ae --- /dev/null +++ b/src/inttypes/SCNu32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNu32 "lu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNu64.c b/src/inttypes/SCNu64.c new file mode 100644 index 00000000..b2047f71 --- /dev/null +++ b/src/inttypes/SCNu64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNu64 "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNu8.c b/src/inttypes/SCNu8.c new file mode 100644 index 00000000..faeabe4d --- /dev/null +++ b/src/inttypes/SCNu8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNu8 "hhu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuFAST16.c b/src/inttypes/SCNuFAST16.c new file mode 100644 index 00000000..bc3cf1f7 --- /dev/null +++ b/src/inttypes/SCNuFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuFAST16 "hu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuFAST32.c b/src/inttypes/SCNuFAST32.c new file mode 100644 index 00000000..ae577ebd --- /dev/null +++ b/src/inttypes/SCNuFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuFAST32 "lu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuFAST64.c b/src/inttypes/SCNuFAST64.c new file mode 100644 index 00000000..13d57290 --- /dev/null +++ b/src/inttypes/SCNuFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuFAST64 "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuFAST8.c b/src/inttypes/SCNuFAST8.c new file mode 100644 index 00000000..bb749288 --- /dev/null +++ b/src/inttypes/SCNuFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuFAST8 "hhu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuLEAST16.c b/src/inttypes/SCNuLEAST16.c new file mode 100644 index 00000000..cebb8217 --- /dev/null +++ b/src/inttypes/SCNuLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuLEAST16 "hu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuLEAST32.c b/src/inttypes/SCNuLEAST32.c new file mode 100644 index 00000000..5285c789 --- /dev/null +++ b/src/inttypes/SCNuLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuLEAST32 "lu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuLEAST64.c b/src/inttypes/SCNuLEAST64.c new file mode 100644 index 00000000..c0dd9c9c --- /dev/null +++ b/src/inttypes/SCNuLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuLEAST64 "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuLEAST8.c b/src/inttypes/SCNuLEAST8.c new file mode 100644 index 00000000..d09eeaae --- /dev/null +++ b/src/inttypes/SCNuLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuLEAST8 "hhu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuMAX.c b/src/inttypes/SCNuMAX.c new file mode 100644 index 00000000..54f76ab6 --- /dev/null +++ b/src/inttypes/SCNuMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNuMAX "llu" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNuPTR.c b/src/inttypes/SCNuPTR.c new file mode 100644 index 00000000..9bd73424 --- /dev/null +++ b/src/inttypes/SCNuPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define SCNuPTR "llu" +#else +#define SCNuPTR "lu" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNx16.c b/src/inttypes/SCNx16.c new file mode 100644 index 00000000..231c7d76 --- /dev/null +++ b/src/inttypes/SCNx16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNx16 "hx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNx32.c b/src/inttypes/SCNx32.c new file mode 100644 index 00000000..39d05ec9 --- /dev/null +++ b/src/inttypes/SCNx32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNx32 "lx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNx64.c b/src/inttypes/SCNx64.c new file mode 100644 index 00000000..bf42ec81 --- /dev/null +++ b/src/inttypes/SCNx64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNx64 "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNx8.c b/src/inttypes/SCNx8.c new file mode 100644 index 00000000..2a44f4bb --- /dev/null +++ b/src/inttypes/SCNx8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNx8 "hhx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxFAST16.c b/src/inttypes/SCNxFAST16.c new file mode 100644 index 00000000..82420fd7 --- /dev/null +++ b/src/inttypes/SCNxFAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxFAST16 "hx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxFAST32.c b/src/inttypes/SCNxFAST32.c new file mode 100644 index 00000000..399b4587 --- /dev/null +++ b/src/inttypes/SCNxFAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxFAST32 "lx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxFAST64.c b/src/inttypes/SCNxFAST64.c new file mode 100644 index 00000000..42df9ea6 --- /dev/null +++ b/src/inttypes/SCNxFAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxFAST64 "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxFAST8.c b/src/inttypes/SCNxFAST8.c new file mode 100644 index 00000000..d6b1dc83 --- /dev/null +++ b/src/inttypes/SCNxFAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxFAST8 "hhx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxLEAST16.c b/src/inttypes/SCNxLEAST16.c new file mode 100644 index 00000000..8e78c5ca --- /dev/null +++ b/src/inttypes/SCNxLEAST16.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxLEAST16 "hx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxLEAST32.c b/src/inttypes/SCNxLEAST32.c new file mode 100644 index 00000000..18d6bdc3 --- /dev/null +++ b/src/inttypes/SCNxLEAST32.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxLEAST32 "lx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxLEAST64.c b/src/inttypes/SCNxLEAST64.c new file mode 100644 index 00000000..ce2c46ed --- /dev/null +++ b/src/inttypes/SCNxLEAST64.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxLEAST64 "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxLEAST8.c b/src/inttypes/SCNxLEAST8.c new file mode 100644 index 00000000..a1a4ac5f --- /dev/null +++ b/src/inttypes/SCNxLEAST8.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxLEAST8 "hhx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxMAX.c b/src/inttypes/SCNxMAX.c new file mode 100644 index 00000000..c328e55f --- /dev/null +++ b/src/inttypes/SCNxMAX.c @@ -0,0 +1,6 @@ +#include <inttypes.h> +#define SCNxMAX "llx" + +/* +STDC(199901) +*/ diff --git a/src/inttypes/SCNxPTR.c b/src/inttypes/SCNxPTR.c new file mode 100644 index 00000000..920f73de --- /dev/null +++ b/src/inttypes/SCNxPTR.c @@ -0,0 +1,10 @@ +#include <inttypes.h> +#if WORD_BIT == 64 +#define SCNxPTR "llx" +#else +#define SCNxPTR "lx" +#endif + +/* +STDC(199901) +*/ diff --git a/src/inttypes/imaxabs.c b/src/inttypes/imaxabs.c new file mode 100644 index 00000000..4f820239 --- /dev/null +++ b/src/inttypes/imaxabs.c @@ -0,0 +1,27 @@ +#include <inttypes.h> + +intmax_t imaxabs(intmax_t j) +{ + /* returns the absolute value of j */ + /* if imaxabs(j) can't be representeted (i.e. imaxabs(INTMAX_MIN), behavior is undefined */ +/* + if (j == INTMAX_MIN) { + __ungol_libc_undefined("Cannot represent absolute value of %" PRIxMAX "\n", j); + } +*/ + if (j == INTMAX_MIN) { + /* undefined behavior */ + return INTMAX_MIN; + } + + if (j < 0) { + return -j; + } + + return j; +} + + +/* +STDC(199901) +*/ diff --git a/src/inttypes/imaxdiv.c b/src/inttypes/imaxdiv.c new file mode 100644 index 00000000..043cee45 --- /dev/null +++ b/src/inttypes/imaxdiv.c @@ -0,0 +1,19 @@ +#include <inttypes.h> + +imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t r = {0}; + if (denom == 0) { + /* undefined */ + return r; + } + r.quot = numer / denom; + r.rem = numer % denom; + /* if either cannot be represented, undefined */ + return r; +} + + +/* +STDC(199901) +*/ diff --git a/src/inttypes/imaxdiv_t.c b/src/inttypes/imaxdiv_t.c new file mode 100644 index 00000000..70b40c02 --- /dev/null +++ b/src/inttypes/imaxdiv_t.c @@ -0,0 +1,10 @@ +#include <inttypes.h> + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +/* +STDC(199901) +*/ diff --git a/src/inttypes/stdint.ref b/src/inttypes/stdint.ref new file mode 100644 index 00000000..82584103 --- /dev/null +++ b/src/inttypes/stdint.ref @@ -0,0 +1,6 @@ +#include <inttypes.h> +REFERENCE(<stdint.h>) + +/* +STDC(199901) +*/ diff --git a/src/inttypes/strtoimax.c b/src/inttypes/strtoimax.c new file mode 100644 index 00000000..5a68c47c --- /dev/null +++ b/src/inttypes/strtoimax.c @@ -0,0 +1,21 @@ +#include <inttypes.h> + +intmax_t strtoimax(const char * restrict nptr, char ** restrict endptr, int base) +{ + /* like strotoll */ + + /* if > INTMAX_MAX */ + /* errno = ERANGE; */ + /* return INTMAX_MAX */ + + /* if < INTMAX_MIN */ + /* errno = ERANGE; */ + /* return INTMAX_MIN; */ + + /* if no conversion */ + return 0; +} + +/* +STDC(199901) +*/ diff --git a/src/inttypes/strtoumax.c b/src/inttypes/strtoumax.c new file mode 100644 index 00000000..bc286cc0 --- /dev/null +++ b/src/inttypes/strtoumax.c @@ -0,0 +1,17 @@ +#include <inttypes.h> + +uintmax_t strtoumax(const char *restrict nptr, char ** restrict endptr, int base) +{ + /* like strotull */ + + /* if > UINTMAX_MAX */ + /* errno = ERANGE; */ + /* return UINTMAX_MAX */ + + /* if no conversion */ + return 0; +} + +/* +STDC(199901) +*/ diff --git a/src/inttypes/wcstoimax.c b/src/inttypes/wcstoimax.c new file mode 100644 index 00000000..12c9a850 --- /dev/null +++ b/src/inttypes/wcstoimax.c @@ -0,0 +1,21 @@ +#include <inttypes.h> + +intmax_t wcstoimax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) +{ + /* like wcstoll */ + + /* if > INTMAX_MAX */ + /* errno = ERANGE; */ + /* return INTMAX_MAX */ + + /* if < INTMAX_MIN */ + /* errno = ERANGE; */ + /* return INTMAX_MIN; */ + + /* if no conversion */ + return 0; +} + +/* +STDC(199901) +*/ diff --git a/src/inttypes/wcstoumax.c b/src/inttypes/wcstoumax.c new file mode 100644 index 00000000..8516da08 --- /dev/null +++ b/src/inttypes/wcstoumax.c @@ -0,0 +1,17 @@ +#include <inttypes.h> + +uintmax_t wcstoumax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) +{ + /* like wcstoll */ + + /* if > UINTMAX_MAX */ + /* errno = ERANGE; */ + /* return UINTMAX_MAX */ + + /* if no conversion */ + return 0; +} + +/* +STDC(199901) +*/ diff --git a/src/iso646/and.c b/src/iso646/and.c new file mode 100644 index 00000000..132a2bc5 --- /dev/null +++ b/src/iso646/and.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define and && + +/* +STDC(199409) +*/ diff --git a/src/iso646/and_eq.c b/src/iso646/and_eq.c new file mode 100644 index 00000000..59c40bfd --- /dev/null +++ b/src/iso646/and_eq.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define and_eq &= + +/* +STDC(199409) +*/ diff --git a/src/iso646/bitand.c b/src/iso646/bitand.c new file mode 100644 index 00000000..76fa23aa --- /dev/null +++ b/src/iso646/bitand.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define bitand & + +/* +STDC(199409) +*/ diff --git a/src/iso646/bitor.c b/src/iso646/bitor.c new file mode 100644 index 00000000..c915db36 --- /dev/null +++ b/src/iso646/bitor.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define bitor | + +/* +STDC(199409) +*/ diff --git a/src/iso646/compl.c b/src/iso646/compl.c new file mode 100644 index 00000000..a94d5780 --- /dev/null +++ b/src/iso646/compl.c @@ -0,0 +1,16 @@ +#include <iso646.h> +#define compl ~ + +/** alternate spelling of ~ **/ + +/*** +is an alternate spelling of the bitwise complement operator (OPERATOR(~)). +***/ + +/* +VALUE_FIXED(~) +*/ + +/* +STDC(199409) +*/ diff --git a/src/iso646/not.c b/src/iso646/not.c new file mode 100644 index 00000000..f0baeb04 --- /dev/null +++ b/src/iso646/not.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define not ! + +/* +STDC(199409) +*/ diff --git a/src/iso646/not_eq.c b/src/iso646/not_eq.c new file mode 100644 index 00000000..3576acc6 --- /dev/null +++ b/src/iso646/not_eq.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define not_eq != + +/* +STDC(199409) +*/ diff --git a/src/iso646/or.c b/src/iso646/or.c new file mode 100644 index 00000000..4e05b37f --- /dev/null +++ b/src/iso646/or.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define or || + +/* +STDC(199409) +*/ diff --git a/src/iso646/or_eq.c b/src/iso646/or_eq.c new file mode 100644 index 00000000..28a5a672 --- /dev/null +++ b/src/iso646/or_eq.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define or_eq |= + +/* +STDC(199409) +*/ diff --git a/src/iso646/xor.c b/src/iso646/xor.c new file mode 100644 index 00000000..6aa1a1be --- /dev/null +++ b/src/iso646/xor.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define xor ^ + +/* +STDC(199409) +*/ diff --git a/src/iso646/xor_eq.c b/src/iso646/xor_eq.c new file mode 100644 index 00000000..4c6dd410 --- /dev/null +++ b/src/iso646/xor_eq.c @@ -0,0 +1,6 @@ +#include <iso646.h> +#define xor_eq ^= + +/* +STDC(199409) +*/ diff --git a/src/limits/CHAR_BIT.c b/src/limits/CHAR_BIT.c new file mode 100644 index 00000000..29445ce9 --- /dev/null +++ b/src/limits/CHAR_BIT.c @@ -0,0 +1,16 @@ +#include <limits.h> +#define CHAR_BIT (8) + +/** bits per byte **/ + +/*** +is the number of bits in a TYPE(char). +***/ + +/* +VALUE_MIN(8) +P_OSIX(VALUE_FIXED(8)) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/CHAR_MAX.c b/src/limits/CHAR_MAX.c new file mode 100644 index 00000000..e746e32e --- /dev/null +++ b/src/limits/CHAR_MAX.c @@ -0,0 +1,21 @@ +#include <limits.h> +#ifdef __CHAR_IS_SIGNED +#define CHAR_MAX (127) +#else +#define CHAR_MAX (255) +#endif + +/** char maximum **/ + +/*** +is the maximum value representable as a TYPE(char). +***/ + +/* +VALUE_SELECT(CONSTANT(UCHAR_MAX), on systems where TYPE(char) is default TYPE(unsigned)) +VALUE_SELECT(CONSTANT(SCHAR_MAX), on systems where TYPE(char) is default TYPE(signed)) +SEE_ALSO(CONSTANT(CHAR_MIN)) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/CHAR_MIN.c b/src/limits/CHAR_MIN.c new file mode 100644 index 00000000..8db46640 --- /dev/null +++ b/src/limits/CHAR_MIN.c @@ -0,0 +1,20 @@ +#include <limits.h> +#ifdef __CHAR_IS_SIGNED +#define CHAR_MIN (-128) +#else +#define CHAR_MIN (0) +#endif + +/** char minimum **/ + +/*** +is the minimum value representable as a TYPE(char). +***/ + +/* +VALUE_SELECT(LITERAL(0), on systems where TYPE(char) is default TYPE(unsigned)) +VALUE_SELECT(CONSTANT(SCHAR_MIN), on systems where TYPE(char) is default TYPE(signed)) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/INT_MAX.c b/src/limits/INT_MAX.c new file mode 100644 index 00000000..d500ee79 --- /dev/null +++ b/src/limits/INT_MAX.c @@ -0,0 +1,22 @@ +#include <limits.h> +#if defined __LP32__ +#define INT_MAX (32767) +#elif defined __ILP32__ || defined __LLP64__ || defined __LP64__ +#define INT_MAX (2147483647) +#elif defined __ILP64__ +#define INT_MAX (9223372036854775807) +#endif + +/** int maximum **/ + +/*** +is the maximum value representable as a TYPE(int). +***/ + +/* +VALUE_MIN(32767) +POSIX_SPECIFIC (issue >= 5): +2147483647 +*/ +/* +STDC(1) +*/ diff --git a/src/limits/INT_MIN.c b/src/limits/INT_MIN.c new file mode 100644 index 00000000..acbb1fdf --- /dev/null +++ b/src/limits/INT_MIN.c @@ -0,0 +1,16 @@ +#include <limits.h> +#define INT_MIN (-INT_MAX -1) + +/** int minimum **/ + +/*** +is the minimum value representable as a TYPE(int). +***/ + +/* +VALUE_MIN(-32767) +POSIX_SPECIFIC(>= issue 5): MIN: -2147483647 +*/ +/* +STDC(1) +*/ diff --git a/src/limits/LLONG_MAX.c b/src/limits/LLONG_MAX.c new file mode 100644 index 00000000..2052034d --- /dev/null +++ b/src/limits/LLONG_MAX.c @@ -0,0 +1,10 @@ +#include <limits.h> + +#define LLONG_MAX (9223372036854775807LL) + +/* MIN: 9223372036854775807 */ +/** maximum value of a type(long long int) **/ + +/* +STDC(199901) +*/ diff --git a/src/limits/LLONG_MIN.c b/src/limits/LLONG_MIN.c new file mode 100644 index 00000000..a28952fe --- /dev/null +++ b/src/limits/LLONG_MIN.c @@ -0,0 +1,9 @@ +#include <limits.h> +#define LLONG_MIN (-9223372036854775808LL) + +/* MIN: -9223372036854775807 */ +/** minimum value of a type(long long int) **/ + +/* +STDC(199901) +*/ diff --git a/src/limits/LONG_MAX.c b/src/limits/LONG_MAX.c new file mode 100644 index 00000000..2612cd1f --- /dev/null +++ b/src/limits/LONG_MAX.c @@ -0,0 +1,19 @@ +#include <limits.h> +#if defined __LP32__ || defined __ILP32__ || defined __LLP64__ +#define LONG_MAX (2147483647L) +#elif defined __ILP64__ || defined __LP64__ +#define LONG_MAX (9223372036854775807L) +#endif + +/** long maximum **/ + +/*** +is the maximum value representable as a TYPE(long int). +***/ + +/* +VALUE_MIN(2147483647) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/LONG_MIN.c b/src/limits/LONG_MIN.c new file mode 100644 index 00000000..eb3d713c --- /dev/null +++ b/src/limits/LONG_MIN.c @@ -0,0 +1,15 @@ +#include <limits.h> +#define LONG_MIN (-LONG_MAX - 1L) + +/** long minimum **/ + +/*** +is the minimum value representable as a TYPE(long int). +***/ + +/* +VALUE_MIN(-2147483647) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/MB_LEN_MAX.c b/src/limits/MB_LEN_MAX.c new file mode 100644 index 00000000..ef9cf495 --- /dev/null +++ b/src/limits/MB_LEN_MAX.c @@ -0,0 +1,16 @@ +#include <limits.h> +#define MB_LEN_MAX (4) + +/** multibyte character length **/ + +/*** +is the maximum number of bytes in a multibyte character for any +supported locale. +***/ + +/* +VALUE_MIN(1) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/SCHAR_MAX.c b/src/limits/SCHAR_MAX.c new file mode 100644 index 00000000..667b025e --- /dev/null +++ b/src/limits/SCHAR_MAX.c @@ -0,0 +1,16 @@ +#include <limits.h> +#define SCHAR_MAX (127) + +/** signed char maximum **/ + +/*** +is the maximum value representable as a TYPE(signed char). +***/ + +/* +VALUE_MIN(127) +POSIX_SPECIFIC(V_ALUE_FIXED(127) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/SCHAR_MIN.c b/src/limits/SCHAR_MIN.c new file mode 100644 index 00000000..2b82cf8b --- /dev/null +++ b/src/limits/SCHAR_MIN.c @@ -0,0 +1,16 @@ +#include <limits.h> +#define SCHAR_MIN (-128) + +/** signed char minimum **/ + +/*** +is the minimum value representable as a TYPE(signed char). +***/ + +/* +VALUE_MIN(-127) +POSIX_SPECIFIC(V_ALUE_FIXED(-128) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/SHRT_MAX.c b/src/limits/SHRT_MAX.c new file mode 100644 index 00000000..66e67acf --- /dev/null +++ b/src/limits/SHRT_MAX.c @@ -0,0 +1,15 @@ +#include <limits.h> +#define SHRT_MAX (32767) + +/** short maximum **/ + +/*** +is the maximum value representable as a TYPE(short int). +***/ + +/* +VALUE_MIN(32767) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/SHRT_MIN.c b/src/limits/SHRT_MIN.c new file mode 100644 index 00000000..e0c52b9b --- /dev/null +++ b/src/limits/SHRT_MIN.c @@ -0,0 +1,15 @@ +#include <limits.h> +#define SHRT_MIN (-32768) + +/** short minimum **/ + +/*** +is the minimum value representable as a TYPE(short int). +***/ + +/* +VALUE_MIN(-32767) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/UCHAR_MAX.c b/src/limits/UCHAR_MAX.c new file mode 100644 index 00000000..1b2aac68 --- /dev/null +++ b/src/limits/UCHAR_MAX.c @@ -0,0 +1,16 @@ +#include <limits.h> +#define UCHAR_MAX (255) + +/** usigned char maximum **/ + +/*** +is the maximum value representable as a TYPE(unsigned char). +***/ + +/* +VALUE_MIN(255) +POSIX_SPECIFIC(V_ALUE_FIXED(255) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/UINT_MAX.c b/src/limits/UINT_MAX.c new file mode 100644 index 00000000..1fa8b4ee --- /dev/null +++ b/src/limits/UINT_MAX.c @@ -0,0 +1,22 @@ +#include <limits.h> +#if defined __LP32__ +#define UINT_MAX (65535U) +#elif defined __ILP32__ || defined __LLP64__ || defined __LP64__ +#define UINT_MAX (4294967295U) +#elif defined __ILP64__ +#define UINT_MAX (18446744073709551616U) +#endif + +/** unsigned int maximum **/ + +/*** +is the maximum value representable as a TYPE(unsigned int). +***/ + +/* +VALUE_MIN(65535) +POSIX_SPECIFIC(issue >= 5): MIN: 4294967295 +*/ +/* +STDC(1) +*/ diff --git a/src/limits/ULLONG_MAX.c b/src/limits/ULLONG_MAX.c new file mode 100644 index 00000000..3aac6f79 --- /dev/null +++ b/src/limits/ULLONG_MAX.c @@ -0,0 +1,8 @@ +#include <limits.h> +#define ULLONG_MAX (18446744073709551615ULL) + +/* MIN: 18446744073709551615 */ + +/* +STDC(199901) +*/ diff --git a/src/limits/ULONG_MAX.c b/src/limits/ULONG_MAX.c new file mode 100644 index 00000000..4243c6d9 --- /dev/null +++ b/src/limits/ULONG_MAX.c @@ -0,0 +1,19 @@ +#include <limits.h> +#if defined __LP32__ || defined __ILP32__ || defined __LLP64__ +#define ULONG_MAX (4294967295UL) +#elif defined __ILP64__ || defined __LP64__ +#define ULONG_MAX (18446744073709551615UL) +#endif + +/** unsigned long maximum **/ + +/*** +is the maximum value representable as a TYPE(unsigned long int). +***/ + +/* +VALUE_MIN(4294967295) +*/ +/* +STDC(1) +*/ diff --git a/src/limits/USHRT_MAX.c b/src/limits/USHRT_MAX.c new file mode 100644 index 00000000..9f326c5c --- /dev/null +++ b/src/limits/USHRT_MAX.c @@ -0,0 +1,15 @@ +#include <limits.h> +#define USHRT_MAX (65535) + +/** unsigned short maximum **/ + +/*** +is the maximum value representable as a TYPE(unsigned short int). +***/ + +/* +VALUE_MIN(65535) +*/ +/* +STDC(1) +*/ diff --git a/src/locale/LC_ALL.c b/src/locale/LC_ALL.c new file mode 100644 index 00000000..164a18ae --- /dev/null +++ b/src/locale/LC_ALL.c @@ -0,0 +1,12 @@ +#include <locale.h> +#define LC_ALL (0) + +/** all locale categories **/ + +/*** +is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate +on all categories of the current locale. +***/ +/* +STDC(1) +*/ diff --git a/src/locale/LC_COLLATE.c b/src/locale/LC_COLLATE.c new file mode 100644 index 00000000..2708525c --- /dev/null +++ b/src/locale/LC_COLLATE.c @@ -0,0 +1,12 @@ +#include <locale.h> +#define LC_COLLATE (1) + +/** locale collation category **/ + +/*** +is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate +on the portion of the locale that affects sorting and collating strings. +***/ +/* +STDC(1) +*/ diff --git a/src/locale/LC_CTYPE.c b/src/locale/LC_CTYPE.c new file mode 100644 index 00000000..9095cf60 --- /dev/null +++ b/src/locale/LC_CTYPE.c @@ -0,0 +1,13 @@ +#include <locale.h> +#define LC_CTYPE (2) + +/** locale character handling category **/ + +/*** +is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate +on the portion of the locale that affects classifying and transforming +individual characters. +***/ +/* +STDC(1) +*/ diff --git a/src/locale/LC_MONETARY.c b/src/locale/LC_MONETARY.c new file mode 100644 index 00000000..cdc94832 --- /dev/null +++ b/src/locale/LC_MONETARY.c @@ -0,0 +1,12 @@ +#include <locale.h> +#define LC_MONETARY (3) + +/** locale monetary formatting category **/ + +/*** +is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate +on the portion of the locale that affects formatting monetary values. +***/ +/* +STDC(1) +*/ diff --git a/src/locale/LC_NUMERIC.c b/src/locale/LC_NUMERIC.c new file mode 100644 index 00000000..80459086 --- /dev/null +++ b/src/locale/LC_NUMERIC.c @@ -0,0 +1,13 @@ +#include <locale.h> +#define LC_NUMERIC (4) + +/** locale number formatting category **/ + +/*** +is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate +on the portion of the locale that affects formatting numeric values, except +for monetary values. +***/ +/* +STDC(1) +*/ diff --git a/src/locale/LC_TIME.c b/src/locale/LC_TIME.c new file mode 100644 index 00000000..e3e70662 --- /dev/null +++ b/src/locale/LC_TIME.c @@ -0,0 +1,12 @@ +#include <locale.h> +#define LC_TIME (5) + +/** locale time formatting category **/ + +/*** +is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate +on the portion of the locale that affects formatting date and time values. +***/ +/* +STDC(1) +*/ diff --git a/src/locale/NULL.ref b/src/locale/NULL.ref new file mode 100644 index 00000000..e1d480f2 --- /dev/null +++ b/src/locale/NULL.ref @@ -0,0 +1,3 @@ +#include <locale.h> +REFERENCE(stddef/NULL.c) +STDC(1) diff --git a/src/locale/localeconv.c b/src/locale/localeconv.c new file mode 100644 index 00000000..f767153c --- /dev/null +++ b/src/locale/localeconv.c @@ -0,0 +1,63 @@ +#include <locale.h> +#include "string.h" +#include "limits.h" + +/** return locale-specific information **/ +struct lconv * localeconv(void) +{ + static struct lconv lc; + + char *monetary = setlocale(LC_MONETARY, NULL); + char *numeric = setlocale(LC_NUMERIC, NULL); + + if (!strcmp(monetary, "C") || !strcmp(monetary, "POSIX")) { + lc.int_curr_symbol = ""; + lc.currency_symbol = ""; + lc.mon_decimal_point = ""; + lc.grouping = ""; + lc.mon_thousands_sep = ""; + lc.mon_grouping = ""; + lc.positive_sign = ""; + lc.negative_sign = ""; + lc.int_frac_digits = CHAR_MAX; + lc.frac_digits = CHAR_MAX; + lc.p_cs_precedes = CHAR_MAX; + lc.p_sep_by_space = CHAR_MAX; + lc.n_cs_precedes = CHAR_MAX; + lc.n_sep_by_space = CHAR_MAX; + lc.p_sign_posn = CHAR_MAX; + lc.n_sign_posn = CHAR_MAX; + + #if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199909L) + lc.int_p_cs_precedes = CHAR_MAX; + lc.int_p_sep_by_space = CHAR_MAX; + lc.int_n_cs_precedes = CHAR_MAX; + lc.int_n_sep_by_space = CHAR_MAX; + lc.int_p_sign_posn = CHAR_MAX; + lc.int_n_sign_posn = CHAR_MAX; + #endif + } + + if (!strcmp(numeric, "C") || !strcmp(numeric, "POSIX")) { + lc.decimal_point = ""; + lc.thousands_sep = ""; + } + + /* + RETURN_SUCCESS(a pointer to a filled-in STRUCTDEF(lconv) for the current locale); + */ + return &lc; +} + +/*** +fills in a STRUCTDEF(lconv) in the current locale for +use in formatting numbers and monetary values. +***/ + +/* +LC_MONETARY +LC_NUMERIC +*/ +/* +STDC(1) +*/ diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c new file mode 100644 index 00000000..0f64b35e --- /dev/null +++ b/src/locale/setlocale.c @@ -0,0 +1,107 @@ +#include <locale.h> +#include "string.h" +#include "stdlib.h" + +char * setlocale(int category, const char *locale) +{ + static struct { + char *lc_collate; + char *lc_ctype; + char *lc_messages; + char *lc_monetary; + char *lc_numeric; + char *lc_time; + } current = { 0 }; + + char *desired = NULL; + + switch (category) { + case LC_COLLATE: desired = current.lc_collate; break; + case LC_CTYPE: desired = current.lc_ctype; break; + case LC_MONETARY: desired = current.lc_monetary; break; + case LC_NUMERIC: desired = current.lc_numeric; break; + case LC_TIME: desired = current.lc_time; break; + #ifdef LC_MESSAGES + case LC_MESSAGES: desired = current.lc_messages; break; + #endif + default: break; + } + + if (locale == NULL) { + if (category == LC_ALL) { + /* build a string if locale is not heterogenous */ + } + return desired; + } + + if (category == LC_ALL) { + /* TODO: make sure all these can be honored */ + #ifdef LC_MESSAGES + setlocale(LC_MESSAGES, locale); + #endif + setlocale(LC_COLLATE, locale); + setlocale(LC_CTYPE, locale); + setlocale(LC_MONETARY, locale); + setlocale(LC_NUMERIC, locale); + return setlocale(LC_TIME, locale); + } + + if (desired) { + free(desired); + } + + if (!strcmp(locale, "")) { + desired = getenv(""); + } else { + desired = (char*)locale; + } + + return desired; +} + +/** get or set program locale **/ + +/*** +sets or retrieves the current global locale of the +program. The program locale has global effects of various operations, based +on ARGUMENT(category): + +FLAG(CONSTANT(LC_COLLATE), + `Affects regular expression, and string collation.') +FLAG(CONSTANT(LC_CTYPE), + `Affects regular expressions, character classification, and character conversion.') +FLAG(CONSTANT(LC_MESSAGES), + `On POSIX systems, affects how message catalogs are found and the format + of affirmative and negative responses. The format of strings written + or returned by library functions may also be affected.') +FLAG(CONSTANT(LC_MONETARY), + `Affects functions that convert monetary values.') +FLAG(CONSTANT(LC_NUMERIC), + `Affects functions that convert non-monetary numeric valus.') +FLAG(CONSTANT(LC_TIME), + `Affects functions that convert time.') + +Specifying CONSTANT(LC_ALL) for ARGUMENT(category) will change the current global locale +for all of the above categories. + +Specifying CONSTANT(NULL) for ARGUMENT(locale) will not change anything, and will simply +return the current globale locale for ARGUMENT(category). + +Specifying empty() for ARGUMENT(locale) will set ARGUMENT(category) to an +implementation-defined native environment. + +All conformant systems support the locale(C), which is a minimal locale required +to support std(C). + +All POSIX systems support the locale(POSIX), which is a minimal locale required +to support std(POSIX). +***/ + +/* +RETURN(CONSTANT(NULL), the request could not be honored) +RETURN(NONNULL, the current locale name for ARGUMENT(category)) +IMPLEMENTATION(The native environment) +*/ +/* +STDC(1) +*/ diff --git a/src/locale/struct_lconv.c b/src/locale/struct_lconv.c new file mode 100644 index 00000000..6f71fa20 --- /dev/null +++ b/src/locale/struct_lconv.c @@ -0,0 +1,65 @@ +#include <locale.h> +struct lconv { + /** The character that separates the whole and decimal portions of non-monetary values **/ + char *decimal_point; /* "." */ + /** The character that separates groups of digits in the whole portion of non-monetary values **/ + char *thousands_sep; /* "" */ + /** A string indicating how to group digits of monetary values */ + char *grouping; /* "" */ + /** The three character ISO 4217 currency symbol of the current locale, followed by a fourth separating character **/ + char *int_curr_symbol; /* "" */ + /** The locale currency symbol in the current locale **/ + char *currency_symbol; /* "" */ + /** The character used for decimal points in monetary values **/ + char *mon_decimal_point; /* "" */ + /** The character separating digit groups in monetary values **/ + char *mon_thousands_sep; /* "" */ + /** A string indicating how to group digits in monetary values **/ + char *mon_grouping; /* "" */ + /** A string to indicate positive monetary values **/ + char *positive_sign; /* "" */ + /** A string to indicate negative monetary values **/ + char *negative_sign; /* "" */ + /** The number of digits after the decimal point in international monetary values **/ + char int_frac_digits; /* CHAR_MAX */ + /** The number of digits after the decimal point in monetary values **/ + char frac_digits; /* CHAR_MAX */ + /** Whether field(currency_symbol) precedes (1) or follows (0) positive monetary values **/ + char p_cs_precedes; /* CHAR_MAX */ + /** Whether field(currency_symbol) is (1) or is not (0) separated from positive monetary values by a space **/ + char p_sep_by_space; /* CHAR_MAX */ + /** Whether field(currency_symbol) precedes (1) or follows (0) negative monetary values **/ + char n_cs_precedes; /* CHAR_MAX */ + /** Whether field(currency_symbol) is (1) or is not(0) separated from negative monetary values by a space **/ + char n_sep_by_space; /* CHAR_MAX */ + /** The position of field(positive_sign) for positive monetary values **/ + char p_sign_posn; /* CHAR_MAX */ + /** The position of field(positive_sign) for negative monetary values **/ + char n_sign_posn; /* CHAR_MAX */ + #if __STDC_VERSION__ >= 199901L + /** Whether field(currency_symbol) precedes (1) or follows (0) positive international monetary values **/ + char int_p_cs_precedes; /* CHAR_MAX */ + /** Whether field(currency_symbol) is (1) or is not (0) separated from positive international monetary values by a space **/ + char int_p_sep_by_space; /* CHAR_MAX */ + /** Whether field(currency_symbol) precedes (1) or follows (0) negative international monetary values **/ + char int_n_cs_precedes; /* CHAR_MAX */ + /** Whether field(currency_symbol) is (1) or is not(0) separated from negative international monetary values by a space **/ + char int_n_sep_by_space; /* CHAR_MAX */ + /** The position of field(positive_sign) for positive international monetary values **/ + char int_p_sign_posn; /* CHAR_MAX */ + /** The position of field(positive_sign) for negative international monetary values **/ + char int_n_sign_posn; /* CHAR_MAX */ + #else + char __int_p_cs_precedes; + char __int_p_sep_by_space; + char __int_n_cs_precedes; + char __int_n_sep_by_space; + char __int_p_sign_posn; + char __int_n_sign_posn; + #endif +}; + +/* values specified in comments are for the "C" locale */ +/* +STDC(1) +*/ diff --git a/src/math/FP_FAST_FMA.c b/src/math/FP_FAST_FMA.c new file mode 100644 index 00000000..868c9455 --- /dev/null +++ b/src/math/FP_FAST_FMA.c @@ -0,0 +1,12 @@ +#include <math.h> + +#if 0 /* if fma is generally as fast or faster than multiply and add */ +#define FP_FAST_FMA +#else +#undef FP_FAST_FMA +#endif + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_FAST_FMAF.c b/src/math/FP_FAST_FMAF.c new file mode 100644 index 00000000..7b7b88a4 --- /dev/null +++ b/src/math/FP_FAST_FMAF.c @@ -0,0 +1,12 @@ +#include <math.h> + +#if 0 /* if fmaf is generally as fast or faster than multiply and add */ +#define FP_FAST_FMAF +#else +#undef FP_FAST_FMAF +#endif + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_FAST_FMAL.c b/src/math/FP_FAST_FMAL.c new file mode 100644 index 00000000..1437ad56 --- /dev/null +++ b/src/math/FP_FAST_FMAL.c @@ -0,0 +1,12 @@ +#include <math.h> + +#if 0 /* if fmal is generally as fast or faster than multiply and add */ +#define FP_FAST_FMAL +#else +#undef FP_FAST_FMAL +#endif + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_ILOGB0.c b/src/math/FP_ILOGB0.c new file mode 100644 index 00000000..1c3f0e28 --- /dev/null +++ b/src/math/FP_ILOGB0.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_ILOGB0 INT_MIN + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_ILOGBNAN.c b/src/math/FP_ILOGBNAN.c new file mode 100644 index 00000000..65aa04f1 --- /dev/null +++ b/src/math/FP_ILOGBNAN.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_ILOGBNAN INT_MAX + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_INFINITE.c b/src/math/FP_INFINITE.c new file mode 100644 index 00000000..e5aadaf8 --- /dev/null +++ b/src/math/FP_INFINITE.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_INFINITE 0 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_NAN.c b/src/math/FP_NAN.c new file mode 100644 index 00000000..804765cd --- /dev/null +++ b/src/math/FP_NAN.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_NAN 1 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_NORMAL.c b/src/math/FP_NORMAL.c new file mode 100644 index 00000000..171ca6bf --- /dev/null +++ b/src/math/FP_NORMAL.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_NORMAL 2 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_SUBNORMAL.c b/src/math/FP_SUBNORMAL.c new file mode 100644 index 00000000..500ecd14 --- /dev/null +++ b/src/math/FP_SUBNORMAL.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_SUBNORMAL 3 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/FP_ZERO.c b/src/math/FP_ZERO.c new file mode 100644 index 00000000..54e5d323 --- /dev/null +++ b/src/math/FP_ZERO.c @@ -0,0 +1,7 @@ +#include <math.h> +#define FP_ZERO 4 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/HUGE_VAL.c b/src/math/HUGE_VAL.c new file mode 100644 index 00000000..f72afacf --- /dev/null +++ b/src/math/HUGE_VAL.c @@ -0,0 +1,13 @@ +#include <math.h> +#define HUGE_VAL (1.0) /* TODO: massive positive double */ + +/** a huge value **/ + +/*** +is a large positive TYPE(double), not necessarily representable as a +TYPE(float). It is used as a sentinel value by several functions in the +standard library. +***/ +/* +STDC(1) +*/ diff --git a/src/math/HUGE_VALF.c b/src/math/HUGE_VALF.c new file mode 100644 index 00000000..41ea0f3e --- /dev/null +++ b/src/math/HUGE_VALF.c @@ -0,0 +1,7 @@ +#include <math.h> +#define HUGE_VALF /* TODO: massive positive float */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/HUGE_VALL.c b/src/math/HUGE_VALL.c new file mode 100644 index 00000000..7745a373 --- /dev/null +++ b/src/math/HUGE_VALL.c @@ -0,0 +1,7 @@ +#include <math.h> +#define HUGE_VALL /* TODO: massive positive long double */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/INFINITY.c b/src/math/INFINITY.c new file mode 100644 index 00000000..64e3ac95 --- /dev/null +++ b/src/math/INFINITY.c @@ -0,0 +1,7 @@ +#include <math.h> +#define INFINITY /* TODO: positive or unsigned float infinity */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/MATH_ERREXCEPT.c b/src/math/MATH_ERREXCEPT.c new file mode 100644 index 00000000..1ad3a6d6 --- /dev/null +++ b/src/math/MATH_ERREXCEPT.c @@ -0,0 +1,7 @@ +#include <math.h> +#define MATH_ERREXCEPT 2 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/MATH_ERRNO.c b/src/math/MATH_ERRNO.c new file mode 100644 index 00000000..07cb5815 --- /dev/null +++ b/src/math/MATH_ERRNO.c @@ -0,0 +1,7 @@ +#include <math.h> +#define MATH_ERRNO 1 + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/NAN.c b/src/math/NAN.c new file mode 100644 index 00000000..6c5d778f --- /dev/null +++ b/src/math/NAN.c @@ -0,0 +1,7 @@ +#include <math.h> +#define NAN /* TODO: float quiet NaN */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/acos.c b/src/math/acos.c new file mode 100644 index 00000000..a610fe2e --- /dev/null +++ b/src/math/acos.c @@ -0,0 +1,35 @@ +# define TGSOURCE "std/9899-1990/math/acos.c" +#include <math.h> +#include "errno.h" +#include "nonstd/tgmath.h" + +/** arc cosine **/ +TYPE TGFN(acos)(TYPE x) +{ + if (x < -1 || x > 1) { + errno = EDOM; /* ARGUMENT(x) not in the range [-1, +1] */ + return TGHUGE; + } + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(a value in range `[0, PI()]'); */ + return (TYPE)0.0; +} + +/*** +compute the principal value of the arc cosine of ARGUMENT(x), which must be in +the range [-1, +1]. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/acosh.c b/src/math/acosh.c new file mode 100644 index 00000000..3e64e9d1 --- /dev/null +++ b/src/math/acosh.c @@ -0,0 +1,13 @@ +# define TGSOURCE "acosh.c" +#include "nontstd/tgmath.h" +#include <math.h> + +TYPE TGFN(acosh)(TYPE x) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/asin.c b/src/math/asin.c new file mode 100644 index 00000000..4c1599fe --- /dev/null +++ b/src/math/asin.c @@ -0,0 +1,35 @@ +# define TGSOURCE "asin.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** arc sine **/ +TYPE TGFN(asin)(TYPE x) +{ + if (x < -1.0 || x > 1.0) { + errno = EDOM; /* ARGUMENT(x) is not in the range [-1, +1] */ + return TGHUGE; + } + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(a value in range `[-PI()/2, +PI()/2]'); */ + return (TYPE)0.0; +} + +/*** +compute the principal value of the arc sine of ARGUMENT(x), which must be in +the range [-1, +1]. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/asinh.c b/src/math/asinh.c new file mode 100644 index 00000000..e4086844 --- /dev/null +++ b/src/math/asinh.c @@ -0,0 +1,13 @@ +# define TGSOURCE "asinh.c" +#include "nontsd/tgmath.h" +#include <math.h> + +TYPE TGFN(asinh)(TYPE x) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/atan.c b/src/math/atan.c new file mode 100644 index 00000000..5b4b0330 --- /dev/null +++ b/src/math/atan.c @@ -0,0 +1,48 @@ +# define TGSOURCE "atan.c" +#include <math.h> +#include "errno.h" +#include "nonstd/tgmath.h" + +/** arc tangent **/ +TYPE TGFN(atan)(TYPE x) +{ + int MAXLOOPS = 10; + TYPE arctan = 0.0; + TYPE power = 1.0; + int i; + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* TODO: correct input domain */ + /* TODO: tweak number of loops */ + + /* arctan x = x - x^3/3 + x^5/5 - x^7/7 ... */ + for (i = 1; i < MAXLOOPS; i++) { + power *= x; + + if (i % 4 == 1) { + arctan += power / i; + } else if (i % 4 == 3) { + arctan -= power / i; + } + } + + /* RETURN_SUCCESS(a value in the range `[-PI()/2, +PI()/2]'); */ + return arctan; +} + +/*** +compute the principal value of the arc tangent of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/atan2.c b/src/math/atan2.c new file mode 100644 index 00000000..be5b9dd6 --- /dev/null +++ b/src/math/atan2.c @@ -0,0 +1,41 @@ +# define TGSOURCE "atan2.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" +#include "nonstd/assert.h" + +/** arc tangent **/ +TYPE TGFN(atan2)(TYPE y, TYPE x) +{ + ASSERT_NONZERO(x); + + if (y == 0 && x == 0) { + errno = EDOM; /* ARGUMENT(y) and ARGUMENT(x) are both LITERAL(0)) */ + return TGHUGE; + } + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + TYPE ret = TGFN(tan)(y / x); + /* FIXME: quadrant */ + /* RETURN_SUCCESS(a value in range `[-PI(), +PI()]'); */ + return ret; +} + +/*** +functions compute the principal value of the arc tangent of +ARGUMENT(y)/ARGUMENT(x), using the signs of both to place the return value in +the correct quadrant. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/atanh.c b/src/math/atanh.c new file mode 100644 index 00000000..2f5f62f1 --- /dev/null +++ b/src/math/atanh.c @@ -0,0 +1,13 @@ +# define TGSOURCE "atanh.c" +#include "nontstd/tgmath.h" +#include <math.h> + +TYPE TGFN(atanh)(TYPE x) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/cbrt.c b/src/math/cbrt.c new file mode 100644 index 00000000..596cabd2 --- /dev/null +++ b/src/math/cbrt.c @@ -0,0 +1,13 @@ +# define TGSOURCE "cbrt.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(cbrt)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/ceil.c b/src/math/ceil.c new file mode 100644 index 00000000..e9f950c8 --- /dev/null +++ b/src/math/ceil.c @@ -0,0 +1,30 @@ +# define TGSOURCE "ceil.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** round up to nearest integer **/ +TYPE TGFN(ceil)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(CEIL(ARGUMENT(x))); */ + return x; +} + +/*** +compute the smallest integral value that is not less +than ARGUMENT(x), returning it as the same floating-point type as ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/copysign.c b/src/math/copysign.c new file mode 100644 index 00000000..d070036b --- /dev/null +++ b/src/math/copysign.c @@ -0,0 +1,13 @@ +# define TGSOURCE "copysign.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(copysign)(TYPE x, TYPE y) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/cos.c b/src/math/cos.c new file mode 100644 index 00000000..0690b6ee --- /dev/null +++ b/src/math/cos.c @@ -0,0 +1,51 @@ +# define TGSOURCE "cos.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** cosine **/ +TYPE TGFN(cos)(TYPE x) +{ + int MAXLOOPS = 10; + int factorial = 1; + int i; + TYPE cosine = 1.0; + TYPE power = 1.0; + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* TODO: make sure x is in the right domain */ + /* TODO: tweak number of loops */ + + /* cos x = 1 - x^2/2! + x^4/4! -x^6/6! ... */ + for (i = 1; i < MAXLOOPS; i++) { + power = power * x; + factorial = factorial * i; + + if (i % 4 == 0) { + cosine += power / factorial; + } else if (i % 4 == 2) { + cosine -= power / factorial; + } + } + + /* RETURN_SUCCESS(the cosine of ARGUMENT(x)); */ + return cosine; +} + +/*** +compute cosine of ARGUMENT(x), in radians. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ + diff --git a/src/math/cosh.c b/src/math/cosh.c new file mode 100644 index 00000000..75301cf1 --- /dev/null +++ b/src/math/cosh.c @@ -0,0 +1,29 @@ +# define TGSOURCE "cosh.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** hyperbolic cosine **/ +TYPE TGFN(cosh)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The magnitude of ARGUMENT(x) is too large */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the hyperbolic cosine of ARGUMENT(x)); */ + return x; +} + +/*** +compute the hyperbolic cosine of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/double_t.c b/src/math/double_t.c new file mode 100644 index 00000000..47b1fb36 --- /dev/null +++ b/src/math/double_t.c @@ -0,0 +1,16 @@ +#include <math.h> + +#if FLT_EVAL_METHOD == 0 +typedef double double_t; +#elif FLT_EVAL_METHOD == 1 +typedef double double_t; +#elif FLT_EVAL_METHOD == 2 +typedef long double double_t; +#else + /* implementation defined */ +#endif + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/erf.c b/src/math/erf.c new file mode 100644 index 00000000..63525700 --- /dev/null +++ b/src/math/erf.c @@ -0,0 +1,13 @@ +# define TGSOURCE "erf.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(erf)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/erfc.c b/src/math/erfc.c new file mode 100644 index 00000000..3aef20d3 --- /dev/null +++ b/src/math/erfc.c @@ -0,0 +1,13 @@ +# define TGSOURCE "erfc.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(erfc)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/exp.c b/src/math/exp.c new file mode 100644 index 00000000..b63ecf4f --- /dev/null +++ b/src/math/exp.c @@ -0,0 +1,44 @@ +# define TGSOURCE "exp.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** exponential function **/ +TYPE TGFN(exp)(TYPE x) +{ + int MAXLOOPS = 10; + int i; + int factorial = 1; + TYPE exponent = 1.0; + TYPE power = 1.0; + + if (0) { + errno = ERANGE; /* The magnitude of ARGUMENT(x) is too large */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* TODO: tweak max loops */ + + /* exp x = 1 + x + x^2/2! + x^3/3! + x^4/4! ... */ + for (i = 1; i < MAXLOOPS; i++) { + power *= x; + factorial *= i; + exponent += power / factorial; + } + + /* RETURN_SUCCESS(the exponential function of ARGUMENT(x)); */ + return exponent; +} + +/*** +compute the exponential function of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/exp2.c b/src/math/exp2.c new file mode 100644 index 00000000..7f67294d --- /dev/null +++ b/src/math/exp2.c @@ -0,0 +1,13 @@ +# define TGSOURCE "exp2.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(exp2)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/expm1.c b/src/math/expm1.c new file mode 100644 index 00000000..f50c43a4 --- /dev/null +++ b/src/math/expm1.c @@ -0,0 +1,13 @@ +# define TGSOURCE "expm1.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(exmp1)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/fabs.c b/src/math/fabs.c new file mode 100644 index 00000000..abd71bb7 --- /dev/null +++ b/src/math/fabs.c @@ -0,0 +1,29 @@ +# define TGSOURCE "fabs.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** absolute value **/ +TYPE TGFN(fabs)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(ABS(ARGUMENT(x))); */ + return x < 0.0 ? -x : x; +} + +/*** +compute the absolute value of a floating-point number ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/fdim.c b/src/math/fdim.c new file mode 100644 index 00000000..922c5040 --- /dev/null +++ b/src/math/fdim.c @@ -0,0 +1,13 @@ +# define TGSOURCE "fdim.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(fdim)(TYPE x, TYPE y) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/float_t.c b/src/math/float_t.c new file mode 100644 index 00000000..251f5b2e --- /dev/null +++ b/src/math/float_t.c @@ -0,0 +1,16 @@ +#include <math.h> + +#if FLT_EVAL_METHOD == 0 +typedef float float_t; +#elif FLT_EVAL_METHOD == 1 +typedef double float_t; +#elif FLT_EVAL_METHOD == 2 +typedef long double float_t; +#else + /* implementation defined */ +#endif + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/floor.c b/src/math/floor.c new file mode 100644 index 00000000..2b2e07ab --- /dev/null +++ b/src/math/floor.c @@ -0,0 +1,30 @@ +# define TGSOURCE "floor.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** round down to nearest integer **/ +TYPE TGFN(floor)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(FLOOR(ARGUMENT(x))); */ + return x; +} + +/*** +compute the largest integral value that is not greater +than ARGUMENT(x), returning it as the same floating-point type as ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/fma.c b/src/math/fma.c new file mode 100644 index 00000000..e2827918 --- /dev/null +++ b/src/math/fma.c @@ -0,0 +1,13 @@ +# define TGSOURCE "fma.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(fma)(TYPE x, TYPE y, TYPE z) +{ + return x - y - z; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/fmax.c b/src/math/fmax.c new file mode 100644 index 00000000..6b056b2b --- /dev/null +++ b/src/math/fmax.c @@ -0,0 +1,13 @@ +# define TGSOURCE "fmax.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(fmax)(TYPE x, TYPE y) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/fmin.c b/src/math/fmin.c new file mode 100644 index 00000000..56966432 --- /dev/null +++ b/src/math/fmin.c @@ -0,0 +1,13 @@ +# define TGSOURCE "fmin.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(fmin)(TYPE x, TYPE y) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/fmod.c b/src/math/fmod.c new file mode 100644 index 00000000..98091880 --- /dev/null +++ b/src/math/fmod.c @@ -0,0 +1,35 @@ +# define TGSOURCE "fmod.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** floating-point remainder **/ +TYPE TGFN(fmod)(TYPE x, TYPE y) +{ + if (y == 0) { + return 0; + } + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(ARGUMENT(x) - VAR(i) * ARGUMENT(y)); */ + return x - x / y; +} + +/*** +compute the floating-point remainder of ARGUMENT(x)/ARGUMENT(y). +FIXME: I am not sure I understand this. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +IMPLEMENTATION(Whether ARGUMENT(y) being LITERAL(0) results in a domain error or THIS() returning LITERAL(0)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/fpclassify.c b/src/math/fpclassify.c new file mode 100644 index 00000000..da9b24af --- /dev/null +++ b/src/math/fpclassify.c @@ -0,0 +1,12 @@ +#include <math.h> + int __fpclassifyf(float x); + int __fpclassifyd(double x); + int __fpclassifyl(long double x); + +#define fpclassify(x) ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) : \ + (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) : __fpclassifyl(x)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/frexp.c b/src/math/frexp.c new file mode 100644 index 00000000..70c87eb1 --- /dev/null +++ b/src/math/frexp.c @@ -0,0 +1,39 @@ +# define TGSOURCE "frexp.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** extract mantissa and exponent **/ +TYPE TGFN(frexp)(TYPE value, int *exp) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN(a value in range [1/2``,'' 1``)'', TODO: explain this); */ + /* RETURN(LITERAL(0), ARGUMENT(x) is LITERAL(0)); */ + (void)exp; + return value; +} + +/*** +break floating-point numbers into a normalized fraction and an integral power +of 2. + +The normalized fraction is a value in the range [1/2, 1) or 0. + +The integral exponent of 2 is stored in the TYPE(int) pointed to by +ARGUMENT(exp). + +Multiplying the normalized fraction by 2 to the power ARGUMENT(*exp). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/hypot.c b/src/math/hypot.c new file mode 100644 index 00000000..8a792143 --- /dev/null +++ b/src/math/hypot.c @@ -0,0 +1,13 @@ +# define TGSOURCE "hypot.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(hypot)(TYPE x, TYPE y) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/ilogb.c b/src/math/ilogb.c new file mode 100644 index 00000000..ef9c0595 --- /dev/null +++ b/src/math/ilogb.c @@ -0,0 +1,13 @@ +# define TGSOURCE "ilogb.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(ilogb)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isfinite.c b/src/math/isfinite.c new file mode 100644 index 00000000..5fbf3582 --- /dev/null +++ b/src/math/isfinite.c @@ -0,0 +1,12 @@ +#include <math.h> + int __isfinitef(float x); + int __isfinited(double x); + int __isfinitel(long double x); + +#define isfinite(x) ((sizeof (x) == sizeof (float)) ? __isfinitef(x) : \ + (sizeof (x) == sizeof (double)) ? __isfinited(x) : __isfinitel(x)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isgreater.c b/src/math/isgreater.c new file mode 100644 index 00000000..672dbe6a --- /dev/null +++ b/src/math/isgreater.c @@ -0,0 +1,7 @@ +#include <math.h> +#define isgreater(x,y) ((x) > (y)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isgreaterequal.c b/src/math/isgreaterequal.c new file mode 100644 index 00000000..de0eaaf2 --- /dev/null +++ b/src/math/isgreaterequal.c @@ -0,0 +1,7 @@ +#include <math.h> +#define isgreaterequal(x,y) ((x) >= (y)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isinf.c b/src/math/isinf.c new file mode 100644 index 00000000..031d870a --- /dev/null +++ b/src/math/isinf.c @@ -0,0 +1,12 @@ +#include <math.h> + int __isinff(float x); + int __isinfd(double x); + int __isinfl(long double x); + +#define isinf(x) ((sizeof (x) == sizeof (float)) ? __isinff(x) : \ + (sizeof (x) == sizeof (double)) ? __isinfd(x) : __isinfl(x)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isless.c b/src/math/isless.c new file mode 100644 index 00000000..9685e84a --- /dev/null +++ b/src/math/isless.c @@ -0,0 +1,7 @@ +#include <math.h> +#define isless(x,y) ((x) < (y)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/islessequal.c b/src/math/islessequal.c new file mode 100644 index 00000000..97ded436 --- /dev/null +++ b/src/math/islessequal.c @@ -0,0 +1,7 @@ +#include <math.h> +#define islessequal(x,y) ((x) <= (y)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/islessgreater.c b/src/math/islessgreater.c new file mode 100644 index 00000000..a2566474 --- /dev/null +++ b/src/math/islessgreater.c @@ -0,0 +1,7 @@ +#include <math.h> +#define islessgreater(x,y) ((x) < (y) || (x) > (y)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isnan.c b/src/math/isnan.c new file mode 100644 index 00000000..2ae4b4d2 --- /dev/null +++ b/src/math/isnan.c @@ -0,0 +1,12 @@ +#include <math.h> + int __isnanf(float x); + int __isnand(double x); + int __isnanl(long double x); + +#define isnan(x) ((sizeof (x) == sizeof (float)) ? __isnanf(x) : \ + (sizeof (x) == sizeof (double)) ? __isnand(x) : __isnanl(x)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isnormal.c b/src/math/isnormal.c new file mode 100644 index 00000000..f4d9e175 --- /dev/null +++ b/src/math/isnormal.c @@ -0,0 +1,12 @@ +#include <math.h> + int __isnormalf(float x); + int __isnormald(double x); + int __isnormall(long double x); + +#define isnormal(x) ((sizeof (x) == sizeof (float)) ? __isnormalf(x) : \ + (sizeof (x) == sizeof (double)) ? __isnormald(x) : __isnormall(x)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/isunordered.c b/src/math/isunordered.c new file mode 100644 index 00000000..ac8cbfff --- /dev/null +++ b/src/math/isunordered.c @@ -0,0 +1,7 @@ +#include <math.h> +#define isunordered(x,y) /* TODO */ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/ldexp.c b/src/math/ldexp.c new file mode 100644 index 00000000..f32c1d76 --- /dev/null +++ b/src/math/ldexp.c @@ -0,0 +1,30 @@ +# define TGSOURCE "ldexp.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** multiply by a power of 2 **/ +TYPE TGFN(ldexp)(TYPE x, int exp) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(ARGUMENT(x) * POW(2,ARGUMENT(exp))); */ + return x * TGFN(pow)(2, exp); +} + +/*** +multiply the floating-point number specifed by ARGUMENT(x) +by 2 raised to the power ARGUMENT(exp). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/lgamma.c b/src/math/lgamma.c new file mode 100644 index 00000000..381dc442 --- /dev/null +++ b/src/math/lgamma.c @@ -0,0 +1,13 @@ +# define TGSOURCE "lgamma.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(lgamma)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/llrint.c b/src/math/llrint.c new file mode 100644 index 00000000..f0b9e9bf --- /dev/null +++ b/src/math/llrint.c @@ -0,0 +1,13 @@ +# define TGSOURCE "llrint.c" +#include "nonstd/tgmath.h" +#include <math.h> + +long long int TGFN(llrint)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/llround.c b/src/math/llround.c new file mode 100644 index 00000000..f259cfbb --- /dev/null +++ b/src/math/llround.c @@ -0,0 +1,13 @@ +# define TGSOURCE "llround.c" +#include "nontsd/tgmath.h" +#include <math.h> + +long long int TGFN(llround)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/log.c b/src/math/log.c new file mode 100644 index 00000000..a75fdafa --- /dev/null +++ b/src/math/log.c @@ -0,0 +1,34 @@ +# define TGSOURCE "log.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** natural logarithm **/ +TYPE TGFN(log)(TYPE x) +{ + if (x < 0) { + errno = EDOM; /* ARGUMENT(x) is negative */ + return TGHUGE; + } + + if (x == 0) { + errno = ERANGE; /* ARGUMENT(x) is LITERAL(0) */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the natural logarithm of ARGUMENT(x)); */ + return x; +} + +/*** +compute the natural logarithm of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/log10.c b/src/math/log10.c new file mode 100644 index 00000000..5000910b --- /dev/null +++ b/src/math/log10.c @@ -0,0 +1,34 @@ +# define TGSOURCE "log10.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** base-10 logarithm **/ +TYPE TGFN(log10)(TYPE x) +{ + if (x < 0) { + errno = EDOM; /* ARGUMENT(x) is negative */ + return TGHUGE; + } + + if (x == 0) { + errno = ERANGE; /* ARGUMENT(x) is LITERAL(0) */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the base-10 logarithm of ARGUMENT(x)); */ + return x; +} + +/*** +compute the base-ten logarithm of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/log1p.c b/src/math/log1p.c new file mode 100644 index 00000000..1ed70439 --- /dev/null +++ b/src/math/log1p.c @@ -0,0 +1,13 @@ +# define TGSOURCE "log1p.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(log1p)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/log2.c b/src/math/log2.c new file mode 100644 index 00000000..16a0363c --- /dev/null +++ b/src/math/log2.c @@ -0,0 +1,13 @@ +#define TGSOURCE "log2.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(log2)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/logb.c b/src/math/logb.c new file mode 100644 index 00000000..c14582df --- /dev/null +++ b/src/math/logb.c @@ -0,0 +1,13 @@ +# define TGSOURCE "logb.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(logb)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/lrint.c b/src/math/lrint.c new file mode 100644 index 00000000..2ee0b986 --- /dev/null +++ b/src/math/lrint.c @@ -0,0 +1,13 @@ +# define TGSOURCE "lrint.c" +#include "nonstd/tgmath.h" +#include <math.h> + +long int TGFN(lrint)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/lround.c b/src/math/lround.c new file mode 100644 index 00000000..e27c1225 --- /dev/null +++ b/src/math/lround.c @@ -0,0 +1,13 @@ +# define TGSOURCE "lround.c" +#include "nontstd/tgmath.h" +#include <math.h> + +long int TGFN(lround)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/math_errhandling.c b/src/math/math_errhandling.c new file mode 100644 index 00000000..2c34327c --- /dev/null +++ b/src/math/math_errhandling.c @@ -0,0 +1,7 @@ +#include <math.h> +#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/modf.c b/src/math/modf.c new file mode 100644 index 00000000..73c5d3f3 --- /dev/null +++ b/src/math/modf.c @@ -0,0 +1,33 @@ +# define TGSOURCE "modf.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** decompose floating-point numbers **/ +TYPE TGFN(modf)(TYPE value, TYPE *iptr) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the signed fractional part of ARGUMENT(value)); */ + (void)iptr; + return value; +} + +/*** +break ARGUMENT(value) into integral and fractional parts. +Each part has the same sign as ARGUMENT(value). The integral part is converted to +the same floating-point type as ARGUMENT(value) and stored in the object pointed to +by ARGUMENT(iptr). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/nan.c b/src/math/nan.c new file mode 100644 index 00000000..ac96ca3d --- /dev/null +++ b/src/math/nan.c @@ -0,0 +1,13 @@ +# define TGSOURCE "nan.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(nan)(const char *tagp) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/nearbyint.c b/src/math/nearbyint.c new file mode 100644 index 00000000..1b3a5c72 --- /dev/null +++ b/src/math/nearbyint.c @@ -0,0 +1,13 @@ +# define TGSOURCE "nearbyint.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(nearbyint)(TYPE x) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/nextafter.c b/src/math/nextafter.c new file mode 100644 index 00000000..315b184c --- /dev/null +++ b/src/math/nextafter.c @@ -0,0 +1,13 @@ +# define TGSOURCE "nextafter.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(nextafter)(TYPE x, TYPE y) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/nexttoward.c b/src/math/nexttoward.c new file mode 100644 index 00000000..6825d89b --- /dev/null +++ b/src/math/nexttoward.c @@ -0,0 +1,13 @@ +# define TGSOURCE "nexttoward.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(nexttoward)(TYPE x, TYPE y) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/pow.c b/src/math/pow.c new file mode 100644 index 00000000..4fb3aa2a --- /dev/null +++ b/src/math/pow.c @@ -0,0 +1,39 @@ +# define TGSOURCE "pow.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** exponentiation **/ +TYPE TGFN(pow)(TYPE x, TYPE y) +{ + if (x < 0 /* && !isintegral(y) */) { + errno = EDOM; /* ARGUMENT(x) is negative and ARGUMENT(y) is not an integer */ + return TGHUGE; + } + + if (x == 0 && y <= 0) { + errno = EDOM; /* ARGUMENT(x) is LITERAL(0) and ARGUMENT(y) is less than or equal to LITERAL(0) */ + return TGHUGE; + } + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(POW(ARGUMENT(x), ARGUMENT(y))); */ + return x * y; +} + +/*** +compute ARGUMENT(x) raised to the power ARGUMENT(y). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/remquo.c b/src/math/remquo.c new file mode 100644 index 00000000..3aec6382 --- /dev/null +++ b/src/math/remquo.c @@ -0,0 +1,13 @@ +# define TGSOURCE "remquo.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(remquo)(TYPE x, TYPE y, int *quo) +{ + return x - y; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/rint.c b/src/math/rint.c new file mode 100644 index 00000000..f6ba653f --- /dev/null +++ b/src/math/rint.c @@ -0,0 +1,13 @@ +# define TGSOURCE "rint.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(rint)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/round.c b/src/math/round.c new file mode 100644 index 00000000..504bcead --- /dev/null +++ b/src/math/round.c @@ -0,0 +1,13 @@ +# define TGSOURCE "round.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(round)(TYPE x) +{ + return x; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/scalbln.c b/src/math/scalbln.c new file mode 100644 index 00000000..1c564393 --- /dev/null +++ b/src/math/scalbln.c @@ -0,0 +1,23 @@ +# define TGSOURCE "scalbln.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(scalbln)(TYPE x, long int n) +{ + return x - n; +} + +/* c99 +Description +2 +The scalbn and scalbln functions compute x × FLT_RADIX n efficiently, not +normally by computing FLT_RADIX n explicitly. A range error may occur. +Returns +3 +The scalbn and scalbln functions return x × FLT_RADIX n . +*/ + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/scalbn.c b/src/math/scalbn.c new file mode 100644 index 00000000..3bbaa431 --- /dev/null +++ b/src/math/scalbn.c @@ -0,0 +1,13 @@ +# define TGSOURCE "scalbn.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(scalbn)(TYPE x, int n) +{ + return x - n; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/signbit.c b/src/math/signbit.c new file mode 100644 index 00000000..7b5ba8a2 --- /dev/null +++ b/src/math/signbit.c @@ -0,0 +1,12 @@ +#include <math.h> + int __signbitf(float x); + int __signbitd(double x); + int __signbitl(long double x); + +#define signbit(x) ((sizeof (x) == sizeof (float)) ? __signbitf(x) : \ + (sizeof (x) == sizeof (double)) ? __signbitd(x) : __signbitl(x)) + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/sin.c b/src/math/sin.c new file mode 100644 index 00000000..c5d127f0 --- /dev/null +++ b/src/math/sin.c @@ -0,0 +1,51 @@ +# define TGSOURCE "sin.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** sine **/ +TYPE TGFN(sin)(TYPE x) +{ + int MAXLOOPS = 10; + int factorial = 1; + int i; + TYPE sine = 0.0; + TYPE power = 1.0; + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* TODO: make sure x is in the input domain */ + /* TODO: tweak the max number of loops */ + + /* RETURN_SUCCESS(the sine of ARGUMENT(x)); */ + + /* sin x = x - x^3/3! + x^5/5! - x^7/7! ... */ + for (i = 1; i < MAXLOOPS; i++) { + power = power * x; + factorial = factorial * i; + + if (i % 4 == 1) { + sine += power / factorial; + } else if (i % 4 == 3) { + sine -= power / factorial; + } + } + + return sine; +} + +/*** +compute sine of ARGUMENT(x), in radians. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/sinh.c b/src/math/sinh.c new file mode 100644 index 00000000..26363703 --- /dev/null +++ b/src/math/sinh.c @@ -0,0 +1,29 @@ +# define TGSOURCE "sinh.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** hyperbolic sine **/ +TYPE TGFN(sinh)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The magnitude of ARGUMENT(x) is too large */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the hyperbolic sine of ARGUMENT(x)); */ + return x; +} + +/*** +compute hyperbolic sine of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/sqrt.c b/src/math/sqrt.c new file mode 100644 index 00000000..dd9d4433 --- /dev/null +++ b/src/math/sqrt.c @@ -0,0 +1,34 @@ +# define TGSOURCE "sqrt.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** square root **/ +TYPE TGFN(sqrt)(TYPE x) +{ + if (x < 0) { + errno = EDOM; /* ARGUMENT(x) is negative */ + return TGHUGE; + } + + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(SQRT(ARGUMENT(x))); */ + return x; +} + +/*** +compute the principal square root of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/tan.c b/src/math/tan.c new file mode 100644 index 00000000..16d83d78 --- /dev/null +++ b/src/math/tan.c @@ -0,0 +1,29 @@ +# define TGSOURCE "tan.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** tangent **/ +TYPE TGFN(tan)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the tangent of ARGUMENT(x)); */ + return TGFN(sin)(x) / TGFN(cos)(x); +} + +/*** +compute the tanget of ARGUMENT(x), in radians. +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/tanh.c b/src/math/tanh.c new file mode 100644 index 00000000..d2c09fe2 --- /dev/null +++ b/src/math/tanh.c @@ -0,0 +1,29 @@ +# define TGSOURCE "tanh.c" +#include <math.h> +#include "nonstd/tgmath.h" +#include "errno.h" + +/** hyperbolic tangent **/ +TYPE TGFN(tanh)(TYPE x) +{ + if (0) { + errno = ERANGE; /* The result cannot be represented */ + /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */ + return TGHUGE; + } + + /* RETURN_SUCCESS(the hyperbolic tangent of ARGUMENT(x)); */ + return x; +} + +/*** +compute the hyperbolic tangent of ARGUMENT(x). +***/ + +/* +IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL)) +LINK(m) +*/ +/* +STDC(1) +*/ diff --git a/src/math/tgamma.c b/src/math/tgamma.c new file mode 100644 index 00000000..b7c7094c --- /dev/null +++ b/src/math/tgamma.c @@ -0,0 +1,13 @@ +# define TGSOURCE "tgamma.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(tgamma)(TYPE x) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/math/trunc.c b/src/math/trunc.c new file mode 100644 index 00000000..d047d7f8 --- /dev/null +++ b/src/math/trunc.c @@ -0,0 +1,13 @@ +# define TGSOURCE "trunc.c" +#include "nonstd/tgmath.h" +#include <math.h> + +TYPE TGFN(trunc)(TYPE x) +{ + return 0.0; +} + +/* +STDC(199901) +LINK(m) +*/ diff --git a/src/nonstd/ASSERT_NONNULL.c b/src/nonstd/ASSERT_NONNULL.c new file mode 100644 index 00000000..e65020fd --- /dev/null +++ b/src/nonstd/ASSERT_NONNULL.c @@ -0,0 +1,14 @@ +#include <nonstd/assert.h> + +#ifndef NDEBUG +#define ASSERT_NONNULL(_ptr) do { \ + if (!_ptr) { \ + struct __constraint_info _ci = {0}; \ + _ci.func = __func__; \ + __libc.stdlib.constraint_handler("Undefined behavior: " \ + "Parameter " #_ptr " can not be NULL", &_ci, EFAULT); \ + } \ + } while (0) +#else +#define ASSERT_NONNULL(x) +#endif diff --git a/src/nonstd/ASSERT_NONZERO.c b/src/nonstd/ASSERT_NONZERO.c new file mode 100644 index 00000000..24a3f9a9 --- /dev/null +++ b/src/nonstd/ASSERT_NONZERO.c @@ -0,0 +1,14 @@ +#include <nonstd/assert.h> + +#ifndef NDEBUG +#define ASSERT_NONZERO(_n) do { \ + if (!_n) { \ + struct __constraint_info _ci = {0}; \ + _ci.func = __func__; \ + __libc.stdlib.constraint_handler("Undefined behavior: " \ + "Parameter " #_n " can not be 0", &_ci, ERANGE); \ + } \ + } while (0) +#else +#define ASSERT_NONZERO(n) +#endif diff --git a/src/nonstd/ASSERT_NOOVERLAP.c b/src/nonstd/ASSERT_NOOVERLAP.c new file mode 100644 index 00000000..5157c6d3 --- /dev/null +++ b/src/nonstd/ASSERT_NOOVERLAP.c @@ -0,0 +1,9 @@ +#include <nonstd/assert.h> + +#ifndef NDEBUG +#define ASSERT_NOOVERLAP(x, y, s) do { \ + /* TODO */ \ + } while (0) +#else +#define ASSERT_NOOVERLAP(x, y, s) +#endif diff --git a/src/nonstd/ASSERT_REPRESENTABLE.c b/src/nonstd/ASSERT_REPRESENTABLE.c new file mode 100644 index 00000000..0067d9b4 --- /dev/null +++ b/src/nonstd/ASSERT_REPRESENTABLE.c @@ -0,0 +1,21 @@ +#include <nonstd/assert.h> + +#ifndef NDEBUG +#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel) do { \ + if (_sentinel && (_n != _sentinel && (_n < _min || _n > _max))) { \ + struct __constraint_info _ci = {0}; \ + _ci.func = __func__; \ + __libc.stdlib.constraint_handler("Undefined behavior: " \ + "Paramater " #_n " must be representable as a " #_type \ + "or be equal to " #_sentinel, &_ci, ERANGE); \ + } else if (_n < _min || _n > _max) { \ + struct __constraint_info _ci = {0}; \ + _ci.func = __func__; \ + __libc.stdlib.constraint_handler("Undefined behavior: " \ + "Parameter " #_n " must be representable as a " #_type, \ + &_ci, ERANGE); \ + } \ + } while (0) +#else +#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel) +#endif diff --git a/src/nonstd/BUFSIZ.ref b/src/nonstd/BUFSIZ.ref new file mode 100644 index 00000000..660ed705 --- /dev/null +++ b/src/nonstd/BUFSIZ.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(stdio/BUFSIZ.c) diff --git a/src/nonstd/LIBC_INTERNAL.c b/src/nonstd/LIBC_INTERNAL.c new file mode 100644 index 00000000..f3c0086a --- /dev/null +++ b/src/nonstd/LIBC_INTERNAL.c @@ -0,0 +1,17 @@ +#include <nonstd/internal.h> + +typedef enum { + ERRNO, + THREAD_LOCALE, + GLOBAL_LOCALE, + SYSCALL_LOOKUP, + PRINTF, + SCANF, + FOPEN, + CTYPE, + TOLOWER, + TOUPPER, + FILE_TAIL, + ATEXIT, + RAND, +} LIBC_INTERNAL; diff --git a/src/nonstd/NULL.ref b/src/nonstd/NULL.ref new file mode 100644 index 00000000..9218f06c --- /dev/null +++ b/src/nonstd/NULL.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(stddef/NULL.c) diff --git a/src/nonstd/SYSCALL.c b/src/nonstd/SYSCALL.c new file mode 100644 index 00000000..4c04ab1b --- /dev/null +++ b/src/nonstd/SYSCALL.c @@ -0,0 +1,11 @@ +#include <nonstd/syscall.h> + +#define SYSCALL(_name, _type, ...) + static int _scno = -2; \ + if (_scno == -2) { _scno = ((syscall_lookup_t)__libc(SYSCALL_LOOKUP))(_name); } \ + _type _ret = __syscall(_scno, __VA_ARGS__); \ + if (_ret < 0) { \ + errno = -_ret; \ + return -1; \ + } \ + return _ret diff --git a/src/nonstd/SYSCALL0.c b/src/nonstd/SYSCALL0.c new file mode 100644 index 00000000..c52a944d --- /dev/null +++ b/src/nonstd/SYSCALL0.c @@ -0,0 +1,11 @@ +#include <nonstd/syscall.h> + +#define SYSCALL0(_name, _type) + static int _scno = -2; \ + if (_scno == -2) { _scno = ((sycall_lookup_t)__libc(LOOKUP))(_name); } \ + _type _ret = __syscall(_scno); \ + if (_ret < 0) { \ + errno = -_ret; \ + return -1; \ + } \ + return _ret diff --git a/src/nonstd/SYSCALL_NOFAIL.c b/src/nonstd/SYSCALL_NOFAIL.c new file mode 100644 index 00000000..715fde95 --- /dev/null +++ b/src/nonstd/SYSCALL_NOFAIL.c @@ -0,0 +1,6 @@ +#include <nonstd/syscall.h> + +#define SYSCALL_NOFAIL(_name) + static int _scno = -2; \ + if (_scno == -2) { _scno = __libc(SYSCALL_LOOKUP)(_name); } \ + return __libc(SYSCALL)(_scno) diff --git a/src/nonstd/SYSCALL_NUMBER.c b/src/nonstd/SYSCALL_NUMBER.c new file mode 100644 index 00000000..f37e4a21 --- /dev/null +++ b/src/nonstd/SYSCALL_NUMBER.c @@ -0,0 +1,8 @@ +#include <nonstd/syscall.h> + +#define SYSCALL_NUMBER(_var, _name, _notfound) long _var = _notfound + + static int _var = -2; do { \ + if (_var == -2) { (_var) = __libc(SYSCALL_LOOKUP)(_name); } \ + if (_var == -1) { errno = ENOSYS; return (_notfound); } \ + } while (0) diff --git a/src/nonstd/__libc.c b/src/nonstd/__libc.c new file mode 100644 index 00000000..2d246203 --- /dev/null +++ b/src/nonstd/__libc.c @@ -0,0 +1,44 @@ +#include <nonstd/internal.h> +#include "locale.h" +#include "nonstd/locale.h" + +#include "_printf.h" +#include "_syscall.h" + +void *__libc(LIBC_INTERNAL variable) +{ + extern void *__libc_per_thread(LIBC_INTERNAL __variable); + + void *r = (void*)0; + + static struct __locale_t locale; + + switch (variable) { + case ERRNO: + return __libc_per_thread(ERRNO); + + case THREAD_LOCALE: + r = __libc_per_thread(THREAD_LOCALE); + if (r) { + break; + } + /* fallthru */ + + case GLOBAL_LOCALE: + r = &locale; + break; + + case SYSCALL_LOOKUP: + r = (void*)__syscall_lookup; + break; + + case PRINTF: + r = (void*)(__printf); + break; + + default: + break; + } + + return r; +} diff --git a/src/nonstd/__libc_per_thread.c b/src/nonstd/__libc_per_thread.c new file mode 100644 index 00000000..5cc2f2a5 --- /dev/null +++ b/src/nonstd/__libc_per_thread.c @@ -0,0 +1,28 @@ +#include "nonstd/internal.h" +#include "locale.h" +#include "nonstd/locale.h" + +#if defined __STDC_VERSION__ && 201112L <= __STDC_VERSION__ && !defined __STDC_NO_THREADS__ +#define THREAD_LOCAL static _Thread_local +#else +#define THREAD_LOCAL static +#endif + +void *__libc_per_thread(LIBC_INTERNAL variable) +{ + THREAD_LOCAL int errno; + THREAD_LOCAL struct __locale_t *locale; + + switch (variable) { + case ERRNO: + return &errno; + + case THREAD_LOCALE: + return &locale; + + default: + break; + } + + return (void*)0; +} diff --git a/src/nonstd/__libc_start.c b/src/nonstd/__libc_start.c new file mode 100644 index 00000000..8dab57fb --- /dev/null +++ b/src/nonstd/__libc_start.c @@ -0,0 +1,26 @@ +void __libc_start(int argc, char **argv) +{ + /* + struct __fopen_options fo = {0}; + + fo.fd = 0; + stdin = __libc.stdio.fopen(&fo); + + fo.fd = 1; + stdout = __libc.stdio.fopen(&fo); + + fo.fd = 2; + stderr = __libc.stdio.fopen(&fo); + + #if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE + setlocale(LC_ALL, "POSIX"); + #else + setlocale(LC_ALL, "C"); + #endif + */ + extern void exit(int); + extern int main(int, char*[]); + + exit(main(argc, argv)); +} + diff --git a/src/nonstd/__printf.c b/src/nonstd/__printf.c new file mode 100644 index 00000000..5868a15d --- /dev/null +++ b/src/nonstd/__printf.c @@ -0,0 +1,4 @@ +#include <nonstd/io.h> + +#define __printf(_opts, _fmt, _ap) \ + ((int (*)(struct io_options*, const char*, va_list))__libc(PRINTF))(_opts, _fmt, _ap) diff --git a/src/nonstd/__scanf.c b/src/nonstd/__scanf.c new file mode 100644 index 00000000..7508880d --- /dev/null +++ b/src/nonstd/__scanf.c @@ -0,0 +1,4 @@ +#include <nonstd/io.h> + +#define __scanf(_opts, _fmt, _ap) \ + ((int (*)(struct io_options*, const char*, va_list))__libc(SCANF))(_opts, _fmt, _ap) diff --git a/src/nonstd/__syscall.c b/src/nonstd/__syscall.c new file mode 100644 index 00000000..a1d0d1ed --- /dev/null +++ b/src/nonstd/__syscall.c @@ -0,0 +1,4 @@ +#include <nonstd/syscall.h> + +long __syscall(long number, ...) +; diff --git a/src/nonstd/ctype_t.c b/src/nonstd/ctype_t.c new file mode 100644 index 00000000..468214b1 --- /dev/null +++ b/src/nonstd/ctype_t.c @@ -0,0 +1,15 @@ +#include <nonstd/ctype.h> + +typedef enum { + ALPHA = (1 << 0), + CNTRL = (1 << 1), + DIGIT = (1 << 2), + GRAPH = (1 << 3), + LOWER = (1 << 4), + PRINT = (1 << 5), + PUNCT = (1 << 6), + SPACE = (1 << 7), + UPPER = (1 << 8), + XDIGIT = (1 << 9), + BLANK = (1 << 10), +} ctype_t; diff --git a/src/nonstd/flockfile.c b/src/nonstd/flockfile.c new file mode 100644 index 00000000..54c86a36 --- /dev/null +++ b/src/nonstd/flockfile.c @@ -0,0 +1,5 @@ +#include <nonstd/io.h> + +#if !(defined _POSIX_C_SOURCE && 199506L <= _POSIX_C_SOURCE) && !(defined _XOPEN_SOURCE && 500 <= _XOPEN_SOURCE) +#define flockfile(f) (void)(f) +#endif diff --git a/src/nonstd/fpos_t.ref b/src/nonstd/fpos_t.ref new file mode 100644 index 00000000..2f233e07 --- /dev/null +++ b/src/nonstd/fpos_t.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(stdio/fpos_t.c) diff --git a/src/nonstd/ftrylockfile.c b/src/nonstd/ftrylockfile.c new file mode 100644 index 00000000..61636a7e --- /dev/null +++ b/src/nonstd/ftrylockfile.c @@ -0,0 +1,5 @@ +#include <nonstd/io.h> + +#if !(defined _POSIX_C_SOURCE && 199506L <= _POSIX_C_SOURCE) && !(defined _XOPEN_SOURCE && 500 <= _XOPEN_SOURCE) +#define ftrylockfile(f) (void)(f), 0 +#endif diff --git a/src/nonstd/funlockfile.c b/src/nonstd/funlockfile.c new file mode 100644 index 00000000..0fe52c48 --- /dev/null +++ b/src/nonstd/funlockfile.c @@ -0,0 +1,5 @@ +#include <nonstd/io.h> + +#if !(defined _POSIX_C_SOURCE && 199506L <= _POSIX_C_SOURCE) && !(defined _XOPEN_SOURCE && 500 <= _XOPEN_SOURCE) +#define funlockfile(f) (void)(f) +#endif diff --git a/src/nonstd/getc_unlocked.c b/src/nonstd/getc_unlocked.c new file mode 100644 index 00000000..a575e60a --- /dev/null +++ b/src/nonstd/getc_unlocked.c @@ -0,0 +1,5 @@ +#include <nonstd/io.h> + +#if !(defined _POSIX_C_SOURCE && 199506L <= _POSIX_C_SOURCE) && !(defined _XOPEN_SOURCE && 500 <= _XOPEN_SOURCE) +#define getc_unlocked(f) getc(f) +#endif diff --git a/src/nonstd/intmax_t.ref b/src/nonstd/intmax_t.ref new file mode 100644 index 00000000..b96b2d3b --- /dev/null +++ b/src/nonstd/intmax_t.ref @@ -0,0 +1,2 @@ +#include <nonstd/types.h> +REFERENCE(stdint/intmax_t.c) diff --git a/src/nonstd/pid_t.ref b/src/nonstd/pid_t.ref new file mode 100644 index 00000000..23be346f --- /dev/null +++ b/src/nonstd/pid_t.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(sys/types/pid_t.c) diff --git a/src/nonstd/size_t.ref b/src/nonstd/size_t.ref new file mode 100644 index 00000000..27c403ab --- /dev/null +++ b/src/nonstd/size_t.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(stddef/size_t.c) diff --git a/src/nonstd/struct_FILE.c b/src/nonstd/struct_FILE.c new file mode 100644 index 00000000..a3b8610e --- /dev/null +++ b/src/nonstd/struct_FILE.c @@ -0,0 +1,36 @@ +#include <nonstd/io.h> + +struct __FILE { + fpos_t pos; + char *buf; + enum { SUPPLIED, ALLOCED, UNSET } buftype; + int buffering; + int bsize; + int isopen; + int flags; + int lastop; + + /* verified necessary */ + int fd; + int oflag; + int orientation; + int eof; + int err; + int nlocks; + int thread; + + #ifdef _POSIX_SOURCE + pid_t pipe_pid; + #else + long int pipe_pid; + #endif + + struct { + char *buf; + size_t size; + int allocated; + } mem; + + struct __FILE *prev; + struct __FILE *next; +}; diff --git a/src/nonstd/struct_atexit.c b/src/nonstd/struct_atexit.c new file mode 100644 index 00000000..482bbed1 --- /dev/null +++ b/src/nonstd/struct_atexit.c @@ -0,0 +1,8 @@ +#include <nonstd/internal.h> + +struct atexit { + int nfns; + void (*fns[32])(void); + struct atexit *next; + struct atexit *prev; +}; diff --git a/src/nonstd/struct_io_options.c b/src/nonstd/struct_io_options.c new file mode 100644 index 00000000..db125f6d --- /dev/null +++ b/src/nonstd/struct_io_options.c @@ -0,0 +1,10 @@ +#include <nonstd/io.h> + +struct io_options { + const char *fnname; + char *string; + struct __FILE *stream; + size_t maxlen; + int fd; + int flags; +}; diff --git a/src/nonstd/struct_locale_t.c b/src/nonstd/struct_locale_t.c new file mode 100644 index 00000000..1981bd8d --- /dev/null +++ b/src/nonstd/struct_locale_t.c @@ -0,0 +1,48 @@ +#include <nonstd/locale.h> + +struct __locale_t { + int mask; + char *all; + char *collate; + unsigned char *collation; + char *ctype; + unsigned char *ctattr; + unsigned char *ctoupper; + unsigned char *ctolower; + char *message; + struct { + char *yesexpr; + char *noexpr; + } lc_messages; + char *monetary; + char *numeric; + struct lconv mn; + char *time; + struct { + char *abday[7]; + char *day[7]; + char *abmon[12]; + char *mon[12]; + char *d_t_fmt; + char *d_fmt; + char *t_fmt; + char *am_pm[2]; + char *t_fmt_ampm; + struct { + char direction; + int offset; + int start_year; + int start_month; + int start_day; + int end_year; + int end_month; + int end_day; + char *era_name; + char *era_format; + } era; + char *era_d_fmt; + char *era_t_fmt; + char *era_d_t_fmt; + char *alt_digits; + } lc_time; +}; diff --git a/src/nonstd/syscall_lookup_t.c b/src/nonstd/syscall_lookup_t.c new file mode 100644 index 00000000..d30bdbc2 --- /dev/null +++ b/src/nonstd/syscall_lookup_t.c @@ -0,0 +1,3 @@ +#include <nonstd/syscall.h> + +typedef long (*syscall_lookup_t)(const char *); diff --git a/src/nonstd/va_list.ref b/src/nonstd/va_list.ref new file mode 100644 index 00000000..84f0e484 --- /dev/null +++ b/src/nonstd/va_list.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(stdarg/va_list.c) diff --git a/src/setjmp/jmp_buf.c b/src/setjmp/jmp_buf.c new file mode 100644 index 00000000..6ea7efff --- /dev/null +++ b/src/setjmp/jmp_buf.c @@ -0,0 +1,16 @@ +#include <setjmp.h> +typedef unsigned long int jmp_buf[32]; + +/** program environment **/ + +/*** +is used to hold all the information needed to restore a a calling +environment. +***/ + +/* +TYPEDEF(an array type) +*/ +/* +STDC(1) +*/ diff --git a/src/setjmp/longjmp.c b/src/setjmp/longjmp.c new file mode 100644 index 00000000..bcb97410 --- /dev/null +++ b/src/setjmp/longjmp.c @@ -0,0 +1,35 @@ +#include <setjmp.h> + +/** restore calling environment **/ +_Noreturn void longjmp(jmp_buf env, int val) +{ + (void)env; + if (val == 0) { + val = 1; + } + /* Set env.return_register to val */ + /* Load all registers from env */ + for (;;); /* silence _Noreturn function returns warning */ +} + +/*** +THIS() restores the environment of a previous call to FUNCTION(setjmp) +and continues execution at the location of the call to FUNCTION(setjmp). + +All objects previously accessible at the time of the call to FUNCTION(setjmp) +have the same values. Non-TYPE(volatile) objects of automatic storage duration +that have changed since the call to FUNCTION(setjmp) have intederminate values. + +When execution resumes at the point of the original call to FUNCTION(setjmp), +the value specified by ARGUMENT(val) is returned. If 0 is specified, then the return +value is 1. +***/ + +/* +UNDEFINED(There was no previous call to FUNCTION(setjmp)) +UNDEFINED(The function containing the previous call to FUNCTION(setjmp) is no longer executing) +UNDEFINED(THIS() is called from a nested signal handler) +*/ +/* +STDC(1) +*/ diff --git a/src/setjmp/setjmp.c b/src/setjmp/setjmp.c new file mode 100644 index 00000000..c578d2a9 --- /dev/null +++ b/src/setjmp/setjmp.c @@ -0,0 +1,32 @@ +#include <setjmp.h> + +int setjmp(jmp_buf env) +{ + extern int __setjmp(jmp_buf); + /* + RETURN(0, the environment has been saved by THIS()) + RETURN(NONZERO, the environment has been restored by FUNCTION(longjmp)) + */ + return __setjmp(env); +} + +/** save program state **/ + +/*** +saves the current state of the calling environment +in the TYPEDEF(jmp_buf) ARGUMENT(env). +***/ + +/* CONSTRAINT: entire controlling expression of a selection or iteration statement */ +/* CONSTRAINT: one operand of a relational or equality operator which is the entire controlling expression of a selction or iteration statement */ +/* CONSTRAINT: the operand of a unary ! as the entire controlling expression of a selection or iteration statement */ +/* CONSTRAINT: an entire expression statement */ + +/* +UNSPECIFIED(Whether THIS() is a macro or identifier with external linkage) +UNDEFINED(A macro definition of THIS() is suppressed in order to access an actual function) +UNDEFINED(A program defines an external identifier named LITERAL(setjmp)) +*/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGABRT.c b/src/signal/SIGABRT.c new file mode 100644 index 00000000..f1878ecf --- /dev/null +++ b/src/signal/SIGABRT.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGABRT (1) +/** abnormal termination **/ +/*** +is a signal indicating that the program is being terminated abnormally, +such as when FUNCTION(abort) is called. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGFPE.c b/src/signal/SIGFPE.c new file mode 100644 index 00000000..c61c78fe --- /dev/null +++ b/src/signal/SIGFPE.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGFPE (2) +/** floating point exception **/ +/*** +is a signal that indicates an error resulting from invalid arithmetic +operations, such as division by zero or overflows. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGILL.c b/src/signal/SIGILL.c new file mode 100644 index 00000000..1d6c588f --- /dev/null +++ b/src/signal/SIGILL.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGILL (3) +/** illegal instruction **/ +/*** +is a signal indicating that the program has attempted to execute an illegal +or improperly formed instruction. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGINT.c b/src/signal/SIGINT.c new file mode 100644 index 00000000..32169d73 --- /dev/null +++ b/src/signal/SIGINT.c @@ -0,0 +1,9 @@ +#include <signal.h> +#define SIGINT (4) +/** interrupt **/ +/*** +is a signal that indicates the program is being interactively interrupted. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGSEGV.c b/src/signal/SIGSEGV.c new file mode 100644 index 00000000..5d6da2b4 --- /dev/null +++ b/src/signal/SIGSEGV.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGSEGV (5) +/** segmentation fault **/ +/*** +is a signal that indicates the program is attempting to access an invalid +memory address. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGTERM.c b/src/signal/SIGTERM.c new file mode 100644 index 00000000..990c0730 --- /dev/null +++ b/src/signal/SIGTERM.c @@ -0,0 +1,9 @@ +#include <signal.h> +#define SIGTERM (6) +/** terminate **/ +/*** +is a signal indicating that the system is requesting the program to terminate. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIG_DFL.c b/src/signal/SIG_DFL.c new file mode 100644 index 00000000..549fe6e4 --- /dev/null +++ b/src/signal/SIG_DFL.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIG_DFL ((void(*)(int))-1) +/** default signal action **/ +/*** +is used as the ARGUMENT(func) argument to FUNCTION(signal) to indicate that +the default signal action should occur. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIG_ERR.c b/src/signal/SIG_ERR.c new file mode 100644 index 00000000..0200a72f --- /dev/null +++ b/src/signal/SIG_ERR.c @@ -0,0 +1,12 @@ +#include <signal.h> +#define SIG_ERR ((void(*)(int))-2) + +/** error setting signal handler **/ + +/*** +is a sentinal value returned by FUNCTION(signal) to indicate that an error +occurred. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIG_IGN.c b/src/signal/SIG_IGN.c new file mode 100644 index 00000000..a753adc7 --- /dev/null +++ b/src/signal/SIG_IGN.c @@ -0,0 +1,12 @@ +#include <signal.h> +#define SIG_IGN ((void(*)(int))-3) + +/** ignore signal **/ + +/*** +can be used as the ARGUMENT(func) argument in a call to FUNCTION(signal) to +ignore the specified signal. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/raise.c b/src/signal/raise.c new file mode 100644 index 00000000..530f893b --- /dev/null +++ b/src/signal/raise.c @@ -0,0 +1,28 @@ +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE +#include "sys/types.h" +#include "unistd.h" +#else +#define kill(pid, sig) (sig ? -1 : -1) +#endif +#include <signal.h> + +/** send a signal to the current program **/ +int raise(int sig) +{ + /* + RETURN_FAILURE(NONZERO); + RETURN_SUCCESS(0); + */ + #if (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 199506L) + return pthread_kill(pthread_self(), sig); + #else + return kill(getpid(), sig); + #endif +} + +/*** +sends the signal ARGUMENT(sig) to the current program. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/sig_atomic_t.c b/src/signal/sig_atomic_t.c new file mode 100644 index 00000000..b3ec2a84 --- /dev/null +++ b/src/signal/sig_atomic_t.c @@ -0,0 +1,15 @@ +#include <signal.h> +typedef volatile int sig_atomic_t; + +/** non-interruptible type **/ + +/*** +is a type of object that can be used atomically even in the presence of interrupts. +***/ + +/* +TYPEDEF(integer) +*/ +/* +STDC(1) +*/ diff --git a/src/signal/signal.c b/src/signal/signal.c new file mode 100644 index 00000000..373fddc5 --- /dev/null +++ b/src/signal/signal.c @@ -0,0 +1,42 @@ +#if defined _POSIX_SOURCE +#include "sys/types.h" +#endif + +#include <signal.h> + +/** set a signal handler **/ +void (*signal(int sig, void (*func)(int)))(int) +{ + (void)sig; + /* TODO */ + /* + RETURN_SUCCESS(a pointer to the signal handler); + RETURN_FAILURE(CONSTANT(SIG_ERR), the request could not be honored); + */ + return func; +} + +/*** +sets the signal handler for the signal specified by ARGUMENT(sig) to +ARGUMENT(func). + +Specifying CONSTANT(SIG_DFL) for ARGUMENT(func) resets the signal handler +to its default behavior. + +Specifying CONSTANT(SIG_IGN) for ARGUMENT(func) causes the signal +ARGUMENT(sig) to be ignored. + +Otherwise, ARGUMENT(func) must be a pointer to a function which takes a +single TYPE(int) argument and does not return a value. +***/ + +/* +UNDEFINED(A signal handler for CONSTANT(SIGFPE) returns) +UNDEFINED(A signal handler calling standard library functions other than THIS() if the signal occurs as other than as a result of calling FUNCTION(abort) or FUNCTION(raise)) +UNDEFINED(FIXME: some function calls from signal handlers) +IMPLEMENTATION(Whether signal blocking is performed when a signal occurs) +IMPLEMENTATION(Other signals corresponding to computation exceptions for which signal handlers must not return) +*/ +/* +STDC(1) +*/ diff --git a/src/stdarg/va_arg.c b/src/stdarg/va_arg.c new file mode 100644 index 00000000..37353882 --- /dev/null +++ b/src/stdarg/va_arg.c @@ -0,0 +1,22 @@ +#include <stdarg.h> +#define va_arg(ap, type) __builtin_va_arg(ap, type) + +/** get an unnamed parameter **/ + +/*** +retrieves the next unnamed parameter for use. The +ARGUMENT(ap) parameter must be first initialized with a call to FUNCTION(va_start). +Each successive call to FUNCTION(va_arg) evaluates the next argument as an +object of type ARGUMENT(type) and returns that value, modifying ARGUMENT(ap) for use in +the next call to FUNCTION(va_arg). +***/ + +/* +PROTOTYPE(TYPE(VAR(type)) va_arg(va_list ap, TYPE(VAR(type)));) +UNDEFINED(There is no next argument) +UNDEFINED(The next argument is not compatible with TYPE(ARGUMENT(type))) +RETURN_SUCCESS(an object of TYPE(ARGUMENT(type)) which is the next unnamed function parameter) +*/ +/* +STDC(1) +*/ diff --git a/src/stdarg/va_copy.c b/src/stdarg/va_copy.c new file mode 100644 index 00000000..27c13dc8 --- /dev/null +++ b/src/stdarg/va_copy.c @@ -0,0 +1,6 @@ +#include <stdarg.h> +#define va_copy(dest, src) __builtin_va_copy(dest, src) + +/* +STDC(199901) +*/ diff --git a/src/stdarg/va_end.c b/src/stdarg/va_end.c new file mode 100644 index 00000000..00588526 --- /dev/null +++ b/src/stdarg/va_end.c @@ -0,0 +1,19 @@ +#include <stdarg.h> +#define va_end(ap) __builtin_va_end(ap) + +/** end processing unnamed arguments **/ + +/*** +stops processing unnamed arguments that were +previously begun with a call to FUNCTION(va_start) so that the enclosing function +may return normally. +***/ + +/* +PROTOTYPE(void va_end(va_list ap);) +UNDEFINED(ARGUMENT(ap) was not initialized by FUNCTION(va_start)) +UNDEFINED(THIS() is not called in the same function as FUNCTION(va_start)) +*/ +/* +STDC(1) +*/ diff --git a/src/stdarg/va_list.c b/src/stdarg/va_list.c new file mode 100644 index 00000000..21b1329b --- /dev/null +++ b/src/stdarg/va_list.c @@ -0,0 +1,12 @@ +#include <stdarg.h> +typedef __builtin_va_list va_list; + +/** variable length argument list **/ + +/*** +holds the information necessary for making calls to FUNCTION(va_start), +FUNCTION(va_copy), FUNCTION(va_arg), and FUNCTION(va_end). +***/ +/* +STDC(1) +*/ diff --git a/src/stdarg/va_start.c b/src/stdarg/va_start.c new file mode 100644 index 00000000..6151fb15 --- /dev/null +++ b/src/stdarg/va_start.c @@ -0,0 +1,24 @@ +#include <stdarg.h> +#define va_start(ap, parmN) __builtin_va_start(ap, parmN) + +/** begin processing unnamed arguments **/ + +/*** +prepares unnamed arguments for use. It initializes +ARGUMENT(ap) with the the first argument after the argument named by ARGUMENT(parmN). The +argument named by ARGUMENT(parmN) must be the final named argument to function (i.e. +the argument just prior to LITERAL(`, ...')). +***/ + +/* +PROTOTYPE(void va_start(va_list ap, VAR(parmN));) + +/* +UNDEFINED(ARGUMENT(parmN) is declared TYPE(register)) +UNDEFINED(ARGUMENT(parmN) is a function pointer) +UNDEFINED(ARGUMENT(parmN) is an array type) +UNDEFINED(ARGUMENT(parmN) is a type not compatible with default argument promotions) +*/ +/* +STDC(1) +*/ diff --git a/src/stdbool/__bool_true_false_are_defined.c b/src/stdbool/__bool_true_false_are_defined.c new file mode 100644 index 00000000..65d76ee0 --- /dev/null +++ b/src/stdbool/__bool_true_false_are_defined.c @@ -0,0 +1,6 @@ +#include <stdbool.h> +#define __bool_true_false_are_defined (1) + +/* +STDC(199901) +*/ diff --git a/src/stdbool/bool.c b/src/stdbool/bool.c new file mode 100644 index 00000000..557a1454 --- /dev/null +++ b/src/stdbool/bool.c @@ -0,0 +1,6 @@ +#include <stdbool.h> +#define bool _Bool + +/* +STDC(199901) +*/ diff --git a/src/stdbool/false.c b/src/stdbool/false.c new file mode 100644 index 00000000..15f292d6 --- /dev/null +++ b/src/stdbool/false.c @@ -0,0 +1,6 @@ +#include <stdbool.h> +#define false (0) + +/* +STDC(199901) +*/ diff --git a/src/stdbool/true.c b/src/stdbool/true.c new file mode 100644 index 00000000..da515b7c --- /dev/null +++ b/src/stdbool/true.c @@ -0,0 +1,6 @@ +#include <stdbool.h> +#define true (1) + +/* +STDC(199901) +*/ diff --git a/src/stddef/NULL.c b/src/stddef/NULL.c new file mode 100644 index 00000000..330b6b6e --- /dev/null +++ b/src/stddef/NULL.c @@ -0,0 +1,17 @@ +#include <stddef.h> +#define NULL ((void*)0) + +/** null pointer **/ + +/*** +is an invalid pointer. It is used as a sentinel value in many standard +library functions. +***/ + +/* +UNDEFINED(Dereferencing THIS()) +IMPLEMENTATION(The value of THIS(), DEFINITION((void*)0)) +*/ +/* +STDC(1) +*/ diff --git a/src/stddef/offsetof.c b/src/stddef/offsetof.c new file mode 100644 index 00000000..c5bf733b --- /dev/null +++ b/src/stddef/offsetof.c @@ -0,0 +1,17 @@ +#include <stddef.h> +#define offsetof(type, member) ((size_t)((void*)&(((type*)0)->##member))) + +/** get offset of a structure member **/ + +/*** +determines the offset, in bytes, of a specified field in a TYPE(struct). +***/ + +/* +PROTOTYPE(size_t offsetof(<var>type</var>, <var>member</var>);) +RETURN_SUCCESS(the offset of ARGUMENT(member) in ARGUMENT(type)) +UNDEFINED(ARGUMENT(member) is a bit-field) +*/ +/* +STDC(1) +*/ diff --git a/src/stddef/ptrdiff_t.c b/src/stddef/ptrdiff_t.c new file mode 100644 index 00000000..1bbd99c8 --- /dev/null +++ b/src/stddef/ptrdiff_t.c @@ -0,0 +1,24 @@ +#include <stddef.h> +#ifdef __LLP64__ +# if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199909L +typedef __int64 ptrdiff_t; +# else +typedef long long int ptrdiff_t; +# endif +#else +typedef long int ptrdiff_t; +#endif + +/** pointer arithmetic type **/ + +/*** +is a signed integral type which results when subtracting one pointer +from another. +***/ + +/* +TYPEDEF(signed integer) +*/ +/* +STDC(1) +*/ diff --git a/src/stddef/size_t.c b/src/stddef/size_t.c new file mode 100644 index 00000000..5435d006 --- /dev/null +++ b/src/stddef/size_t.c @@ -0,0 +1,24 @@ +#include <stddef.h> +#ifdef __LLP64__ +# if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199909L +typedef unsigned __int64 size_t; +# else +typedef unsigned long long int size_t; +# endif +#else +typedef unsigned long int size_t; +#endif + +/** memory size type **/ + +/*** +is an unsigned integer type that is the result of using the +OPERATOR(sizeof) operator. +***/ + +/* +TYPEDEF(unsigned integer) +*/ +/* +STDC(1) +*/ diff --git a/src/stddef/wchar_t.c b/src/stddef/wchar_t.c new file mode 100644 index 00000000..dc4955fa --- /dev/null +++ b/src/stddef/wchar_t.c @@ -0,0 +1,17 @@ +#include <stddef.h> +typedef int wchar_t; + +/** wide character type **/ + +/*** +is an integer type used to represent wide characters. Using a THIS(), +every character in the current locale can be represented by a single variable. +The null character will always have the value LITERAL(0). +***/ + +/* +TYPEDEF(integer) +*/ +/* +STDC(1) +*/ diff --git a/src/stdint/INT16_C.c b/src/stdint/INT16_C.c new file mode 100644 index 00000000..59f6e911 --- /dev/null +++ b/src/stdint/INT16_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT16_C(value) ((int_least16_t)value) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT16_MAX.c b/src/stdint/INT16_MAX.c new file mode 100644 index 00000000..16136be3 --- /dev/null +++ b/src/stdint/INT16_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT16_MAX (32767) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT16_MIN.c b/src/stdint/INT16_MIN.c new file mode 100644 index 00000000..35349b4d --- /dev/null +++ b/src/stdint/INT16_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT16_MIN (-32768) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT32_C.c b/src/stdint/INT32_C.c new file mode 100644 index 00000000..fca867f9 --- /dev/null +++ b/src/stdint/INT32_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT32_C(value) ((int_least32_t)value##L) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT32_MAX.c b/src/stdint/INT32_MAX.c new file mode 100644 index 00000000..dd935ae3 --- /dev/null +++ b/src/stdint/INT32_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT32_MAX (2147483647) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT32_MIN.c b/src/stdint/INT32_MIN.c new file mode 100644 index 00000000..4349cf37 --- /dev/null +++ b/src/stdint/INT32_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT32_MIN (-2147483648) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT64_C.c b/src/stdint/INT64_C.c new file mode 100644 index 00000000..ee8fdafa --- /dev/null +++ b/src/stdint/INT64_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT64_C(value) ((int_least64_t)value##LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT64_MAX.c b/src/stdint/INT64_MAX.c new file mode 100644 index 00000000..e50109c2 --- /dev/null +++ b/src/stdint/INT64_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT64_MAX (9223372036854775807LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT64_MIN.c b/src/stdint/INT64_MIN.c new file mode 100644 index 00000000..55d0f702 --- /dev/null +++ b/src/stdint/INT64_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT64_MIN (-9223372036854775808LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT8_C.c b/src/stdint/INT8_C.c new file mode 100644 index 00000000..58135cb6 --- /dev/null +++ b/src/stdint/INT8_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT8_C(value) ((int_least8_t)value) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT8_MAX.c b/src/stdint/INT8_MAX.c new file mode 100644 index 00000000..73da5dbc --- /dev/null +++ b/src/stdint/INT8_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT8_MAX (127) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT8_MIN.c b/src/stdint/INT8_MIN.c new file mode 100644 index 00000000..c08b71ef --- /dev/null +++ b/src/stdint/INT8_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT8_MIN (-128) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INTMAX_C.c b/src/stdint/INTMAX_C.c new file mode 100644 index 00000000..c051c9ae --- /dev/null +++ b/src/stdint/INTMAX_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INTMAX_C(value) ((intmax_t)value##LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INTMAX_MAX.c b/src/stdint/INTMAX_MAX.c new file mode 100644 index 00000000..07d54edc --- /dev/null +++ b/src/stdint/INTMAX_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INTMAX_MAX (9223372036854775807LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INTMAX_MIN.c b/src/stdint/INTMAX_MIN.c new file mode 100644 index 00000000..240d40b6 --- /dev/null +++ b/src/stdint/INTMAX_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INTMAX_MIN (-9223372036854775808LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INTPTR_MAX.c b/src/stdint/INTPTR_MAX.c new file mode 100644 index 00000000..f4b97702 --- /dev/null +++ b/src/stdint/INTPTR_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INTPTR_MAX /* FIXME */ (32767) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INTPTR_MIN.c b/src/stdint/INTPTR_MIN.c new file mode 100644 index 00000000..57a7f882 --- /dev/null +++ b/src/stdint/INTPTR_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INTPTR_MIN /* FIXME */ (-32767) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST16_MAX.c b/src/stdint/INT_FAST16_MAX.c new file mode 100644 index 00000000..4705b9c8 --- /dev/null +++ b/src/stdint/INT_FAST16_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST16_MAX (32767) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST16_MIN.c b/src/stdint/INT_FAST16_MIN.c new file mode 100644 index 00000000..c78c28eb --- /dev/null +++ b/src/stdint/INT_FAST16_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST16_MIN (-32768) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST32_MAX.c b/src/stdint/INT_FAST32_MAX.c new file mode 100644 index 00000000..ea01e62d --- /dev/null +++ b/src/stdint/INT_FAST32_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST32_MAX (2147483647) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST32_MIN.c b/src/stdint/INT_FAST32_MIN.c new file mode 100644 index 00000000..2fc24e5d --- /dev/null +++ b/src/stdint/INT_FAST32_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST32_MIN (-2147483648) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST64_MAX.c b/src/stdint/INT_FAST64_MAX.c new file mode 100644 index 00000000..ffd7bb78 --- /dev/null +++ b/src/stdint/INT_FAST64_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST64_MAX (9223372036854775807LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST64_MIN.c b/src/stdint/INT_FAST64_MIN.c new file mode 100644 index 00000000..07f4a44c --- /dev/null +++ b/src/stdint/INT_FAST64_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST64_MIN (-9223372036854775808LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST8_MAX.c b/src/stdint/INT_FAST8_MAX.c new file mode 100644 index 00000000..58639691 --- /dev/null +++ b/src/stdint/INT_FAST8_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST8_MAX (127) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_FAST8_MIN.c b/src/stdint/INT_FAST8_MIN.c new file mode 100644 index 00000000..86ee6ec9 --- /dev/null +++ b/src/stdint/INT_FAST8_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_FAST8_MIN (-128) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST16_MAX.c b/src/stdint/INT_LEAST16_MAX.c new file mode 100644 index 00000000..9a625094 --- /dev/null +++ b/src/stdint/INT_LEAST16_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST16_MAX (32767) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST16_MIN.c b/src/stdint/INT_LEAST16_MIN.c new file mode 100644 index 00000000..3cd0fec6 --- /dev/null +++ b/src/stdint/INT_LEAST16_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST16_MIN (-32768) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST32_MAX.c b/src/stdint/INT_LEAST32_MAX.c new file mode 100644 index 00000000..6d4d6ff0 --- /dev/null +++ b/src/stdint/INT_LEAST32_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST32_MAX (2147483647) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST32_MIN.c b/src/stdint/INT_LEAST32_MIN.c new file mode 100644 index 00000000..9c714f2c --- /dev/null +++ b/src/stdint/INT_LEAST32_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST32_MIN (-2147483648) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST64_MAX.c b/src/stdint/INT_LEAST64_MAX.c new file mode 100644 index 00000000..a7ff5e2e --- /dev/null +++ b/src/stdint/INT_LEAST64_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST64_MAX (9223372036854775807LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST64_MIN.c b/src/stdint/INT_LEAST64_MIN.c new file mode 100644 index 00000000..d4dfb201 --- /dev/null +++ b/src/stdint/INT_LEAST64_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST64_MIN (-9223372036854775808LL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST8_MAX.c b/src/stdint/INT_LEAST8_MAX.c new file mode 100644 index 00000000..5df7f755 --- /dev/null +++ b/src/stdint/INT_LEAST8_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST8_MAX (127) + +/* +STDC(199901) +*/ diff --git a/src/stdint/INT_LEAST8_MIN.c b/src/stdint/INT_LEAST8_MIN.c new file mode 100644 index 00000000..2b8c6617 --- /dev/null +++ b/src/stdint/INT_LEAST8_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define INT_LEAST8_MIN (-128) + +/* +STDC(199901) +*/ diff --git a/src/stdint/PTRDIFF_MAX.c b/src/stdint/PTRDIFF_MAX.c new file mode 100644 index 00000000..ae518616 --- /dev/null +++ b/src/stdint/PTRDIFF_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define PTRDIFF_MAX /* FIXME */ (65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/PTRDIFF_MIN.c b/src/stdint/PTRDIFF_MIN.c new file mode 100644 index 00000000..44292a10 --- /dev/null +++ b/src/stdint/PTRDIFF_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define PTRDIFF_MIN /* FIXME */ (-65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/SIG_ATOMIC_MAX.c b/src/stdint/SIG_ATOMIC_MAX.c new file mode 100644 index 00000000..da8db676 --- /dev/null +++ b/src/stdint/SIG_ATOMIC_MAX.c @@ -0,0 +1,9 @@ +#include <stdint.h> +#define SIG_ATOMIC_MAX (127) + +/*If sig_atomic_t (see 7.14) is defined as a signed integer type, the value of SIG_ATOMIC_MIN shall be no greater than −127 and the value of SIG_ATOMIC_MAX shall be no less than 127; otherwise, sig_atomic_t is defined as an unsigned integer type, and the value of SIG_ATOMIC_MIN shall be 0 and the value of SIG_ATOMIC_MAX shall be no less than 255.*/ + + +/* +STDC(199901) +*/ diff --git a/src/stdint/SIG_ATOMIC_MIN.c b/src/stdint/SIG_ATOMIC_MIN.c new file mode 100644 index 00000000..f4d27e62 --- /dev/null +++ b/src/stdint/SIG_ATOMIC_MIN.c @@ -0,0 +1,9 @@ +#include <stdint.h> +#define SIG_ATOMIC_MIN (-127) + +/*If sig_atomic_t (see 7.14) is defined as a signed integer type, the value of SIG_ATOMIC_MIN shall be no greater than −127 and the value of SIG_ATOMIC_MAX shall be no less than 127; otherwise, sig_atomic_t is defined as an unsigned integer type, and the value of SIG_ATOMIC_MIN shall be 0 and the value of SIG_ATOMIC_MAX shall be no less than 255.*/ + + +/* +STDC(199901) +*/ diff --git a/src/stdint/SIZE_MAX.c b/src/stdint/SIZE_MAX.c new file mode 100644 index 00000000..22770096 --- /dev/null +++ b/src/stdint/SIZE_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define SIZE_MAX /* FIXME */ (65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT16_C.c b/src/stdint/UINT16_C.c new file mode 100644 index 00000000..dbb276a6 --- /dev/null +++ b/src/stdint/UINT16_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT16_C(value) ((uint_least16_t)value) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT16_MAX.c b/src/stdint/UINT16_MAX.c new file mode 100644 index 00000000..f8a8f586 --- /dev/null +++ b/src/stdint/UINT16_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT16_MAX (65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT32_C.c b/src/stdint/UINT32_C.c new file mode 100644 index 00000000..05583780 --- /dev/null +++ b/src/stdint/UINT32_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT32_C(value) ((uint_least32_t)value##U) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT32_MAX.c b/src/stdint/UINT32_MAX.c new file mode 100644 index 00000000..dd257db3 --- /dev/null +++ b/src/stdint/UINT32_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT32_MAX (4294967295U) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT64_C.c b/src/stdint/UINT64_C.c new file mode 100644 index 00000000..ce05a6bc --- /dev/null +++ b/src/stdint/UINT64_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT64_C(value) ((uint_least32_t)value##ULL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT64_MAX.c b/src/stdint/UINT64_MAX.c new file mode 100644 index 00000000..c92f3d43 --- /dev/null +++ b/src/stdint/UINT64_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT64_MAX (18446744073709551616ULL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT8_C.c b/src/stdint/UINT8_C.c new file mode 100644 index 00000000..93e7ccc5 --- /dev/null +++ b/src/stdint/UINT8_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT8_C(value) ((uint_least8_t)value) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT8_MAX.c b/src/stdint/UINT8_MAX.c new file mode 100644 index 00000000..4ed3d37f --- /dev/null +++ b/src/stdint/UINT8_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT8_MAX (255) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINTMAX_C.c b/src/stdint/UINTMAX_C.c new file mode 100644 index 00000000..d505d108 --- /dev/null +++ b/src/stdint/UINTMAX_C.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINTMAX_C(value) ((uintmax_t)value##ULL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINTMAX_MAX.c b/src/stdint/UINTMAX_MAX.c new file mode 100644 index 00000000..3dcc34a2 --- /dev/null +++ b/src/stdint/UINTMAX_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINTMAX_MAX (18446744073709551616ULL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINTPTR_MAX.c b/src/stdint/UINTPTR_MAX.c new file mode 100644 index 00000000..05d149c1 --- /dev/null +++ b/src/stdint/UINTPTR_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINTPTR_MAX /* FIXME */ (65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_FAST16_MAX.c b/src/stdint/UINT_FAST16_MAX.c new file mode 100644 index 00000000..b1c0274c --- /dev/null +++ b/src/stdint/UINT_FAST16_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_FAST16_MAX (65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_FAST32_MAX.c b/src/stdint/UINT_FAST32_MAX.c new file mode 100644 index 00000000..9431d807 --- /dev/null +++ b/src/stdint/UINT_FAST32_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_FAST32_MAX (4294967295U) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_FAST64_MAX.c b/src/stdint/UINT_FAST64_MAX.c new file mode 100644 index 00000000..f06a53a0 --- /dev/null +++ b/src/stdint/UINT_FAST64_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_FAST64_MAX (18446744073709551616ULL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_FAST8_MAX.c b/src/stdint/UINT_FAST8_MAX.c new file mode 100644 index 00000000..5395c697 --- /dev/null +++ b/src/stdint/UINT_FAST8_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_FAST8_MAX (255) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_LEAST16_MAX.c b/src/stdint/UINT_LEAST16_MAX.c new file mode 100644 index 00000000..f629b638 --- /dev/null +++ b/src/stdint/UINT_LEAST16_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_LEAST16_MAX (65535) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_LEAST32_MAX.c b/src/stdint/UINT_LEAST32_MAX.c new file mode 100644 index 00000000..fdf97254 --- /dev/null +++ b/src/stdint/UINT_LEAST32_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_LEAST32_MAX (4294967295U) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_LEAST64_MAX.c b/src/stdint/UINT_LEAST64_MAX.c new file mode 100644 index 00000000..637e6fb0 --- /dev/null +++ b/src/stdint/UINT_LEAST64_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_LEAST64_MAX (18446744073709551616ULL) + +/* +STDC(199901) +*/ diff --git a/src/stdint/UINT_LEAST8_MAX.c b/src/stdint/UINT_LEAST8_MAX.c new file mode 100644 index 00000000..29f3c09a --- /dev/null +++ b/src/stdint/UINT_LEAST8_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define UINT_LEAST8_MAX (255) + +/* +STDC(199901) +*/ diff --git a/src/stdint/WCHAR_MAX.c b/src/stdint/WCHAR_MAX.c new file mode 100644 index 00000000..502b1735 --- /dev/null +++ b/src/stdint/WCHAR_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define WCHAR_MAX (0x10FFFF) + +/* +STDC(199901) +*/ diff --git a/src/stdint/WCHAR_MIN.c b/src/stdint/WCHAR_MIN.c new file mode 100644 index 00000000..00123ddf --- /dev/null +++ b/src/stdint/WCHAR_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define WCHAR_MIN (0) + +/* +STDC(199901) +*/ diff --git a/src/stdint/WINT_MAX.c b/src/stdint/WINT_MAX.c new file mode 100644 index 00000000..f7303ea1 --- /dev/null +++ b/src/stdint/WINT_MAX.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define WINT_MAX (2147483647) + +/* +STDC(199901) +*/ diff --git a/src/stdint/WINT_MIN.c b/src/stdint/WINT_MIN.c new file mode 100644 index 00000000..2b3005bf --- /dev/null +++ b/src/stdint/WINT_MIN.c @@ -0,0 +1,6 @@ +#include <stdint.h> +#define WINT_MIN (-2147483648) + +/* +STDC(199901) +*/ diff --git a/src/stdint/int16_t.c b/src/stdint/int16_t.c new file mode 100644 index 00000000..30861f20 --- /dev/null +++ b/src/stdint/int16_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef short int int16_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int32_t.c b/src/stdint/int32_t.c new file mode 100644 index 00000000..24059172 --- /dev/null +++ b/src/stdint/int32_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef int int32_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int64_t.c b/src/stdint/int64_t.c new file mode 100644 index 00000000..cc9419cc --- /dev/null +++ b/src/stdint/int64_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef long long int int64_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int8_t.c b/src/stdint/int8_t.c new file mode 100644 index 00000000..11533725 --- /dev/null +++ b/src/stdint/int8_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef signed char int8_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_fast16_t.c b/src/stdint/int_fast16_t.c new file mode 100644 index 00000000..4dcf9838 --- /dev/null +++ b/src/stdint/int_fast16_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef short int int_fast16_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_fast32_t.c b/src/stdint/int_fast32_t.c new file mode 100644 index 00000000..65460677 --- /dev/null +++ b/src/stdint/int_fast32_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef long int int_fast32_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_fast64_t.c b/src/stdint/int_fast64_t.c new file mode 100644 index 00000000..173e0fe2 --- /dev/null +++ b/src/stdint/int_fast64_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef long long int int_fast64_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_fast8_t.c b/src/stdint/int_fast8_t.c new file mode 100644 index 00000000..1bd43b74 --- /dev/null +++ b/src/stdint/int_fast8_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef signed char int_fast8_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_least16_t.c b/src/stdint/int_least16_t.c new file mode 100644 index 00000000..3aaeacff --- /dev/null +++ b/src/stdint/int_least16_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef short int int_least16_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_least32_t.c b/src/stdint/int_least32_t.c new file mode 100644 index 00000000..2290dab6 --- /dev/null +++ b/src/stdint/int_least32_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef long int int_least32_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_least64_t.c b/src/stdint/int_least64_t.c new file mode 100644 index 00000000..02a29079 --- /dev/null +++ b/src/stdint/int_least64_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef long long int int_least64_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/int_least8_t.c b/src/stdint/int_least8_t.c new file mode 100644 index 00000000..2142c96e --- /dev/null +++ b/src/stdint/int_least8_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef signed char int_least8_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/intmax_t.c b/src/stdint/intmax_t.c new file mode 100644 index 00000000..3c5532c5 --- /dev/null +++ b/src/stdint/intmax_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef long long int intmax_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/intptr_t.c b/src/stdint/intptr_t.c new file mode 100644 index 00000000..f72a6eb8 --- /dev/null +++ b/src/stdint/intptr_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long int intptr_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint16_t.c b/src/stdint/uint16_t.c new file mode 100644 index 00000000..b8d579a5 --- /dev/null +++ b/src/stdint/uint16_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned short int uint16_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint32_t.c b/src/stdint/uint32_t.c new file mode 100644 index 00000000..01a11eae --- /dev/null +++ b/src/stdint/uint32_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned int uint32_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint64_t.c b/src/stdint/uint64_t.c new file mode 100644 index 00000000..d4af00d7 --- /dev/null +++ b/src/stdint/uint64_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long long int uint64_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint8_t.c b/src/stdint/uint8_t.c new file mode 100644 index 00000000..136c50be --- /dev/null +++ b/src/stdint/uint8_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned char uint8_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_fast16_t.c b/src/stdint/uint_fast16_t.c new file mode 100644 index 00000000..0e89feca --- /dev/null +++ b/src/stdint/uint_fast16_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned short int uint_fast16_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_fast32_t.c b/src/stdint/uint_fast32_t.c new file mode 100644 index 00000000..3fc55b4e --- /dev/null +++ b/src/stdint/uint_fast32_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned int uint_fast32_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_fast64_t.c b/src/stdint/uint_fast64_t.c new file mode 100644 index 00000000..d2ce6fee --- /dev/null +++ b/src/stdint/uint_fast64_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long long int uint_fast64_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_fast8_t.c b/src/stdint/uint_fast8_t.c new file mode 100644 index 00000000..263bdd7a --- /dev/null +++ b/src/stdint/uint_fast8_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned char uint_fast8_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_least16_t.c b/src/stdint/uint_least16_t.c new file mode 100644 index 00000000..d4216fb1 --- /dev/null +++ b/src/stdint/uint_least16_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned short int uint_least16_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_least32_t.c b/src/stdint/uint_least32_t.c new file mode 100644 index 00000000..7a1b6432 --- /dev/null +++ b/src/stdint/uint_least32_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long int uint_least32_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_least64_t.c b/src/stdint/uint_least64_t.c new file mode 100644 index 00000000..4c3cd753 --- /dev/null +++ b/src/stdint/uint_least64_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long long int uint_least64_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uint_least8_t.c b/src/stdint/uint_least8_t.c new file mode 100644 index 00000000..012c9cf8 --- /dev/null +++ b/src/stdint/uint_least8_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned char uint_least8_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uintmax_t.c b/src/stdint/uintmax_t.c new file mode 100644 index 00000000..95ed2d9a --- /dev/null +++ b/src/stdint/uintmax_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long long int uintmax_t; + +/* +STDC(199901) +*/ diff --git a/src/stdint/uintptr_t.c b/src/stdint/uintptr_t.c new file mode 100644 index 00000000..cb204c66 --- /dev/null +++ b/src/stdint/uintptr_t.c @@ -0,0 +1,6 @@ +#include <stdint.h> +typedef unsigned long long int uintptr_t; + +/* +STDC(199901) +*/ diff --git a/src/stdio/BUFSIZ.c b/src/stdio/BUFSIZ.c new file mode 100644 index 00000000..c1b315c4 --- /dev/null +++ b/src/stdio/BUFSIZ.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#define BUFSIZ (4096) + +/** default buffer size **/ + +/*** +is the buffer size used when buffering is adjusted with FUNCTION(setbuf). +***/ + +/* +VALUE_MIN(256) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/EOF.c b/src/stdio/EOF.c new file mode 100644 index 00000000..84f560a1 --- /dev/null +++ b/src/stdio/EOF.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define EOF (-1) + +/** end-of-file **/ + +/*** +is a sentinal value used to indicated that a TYPEDEF(FILE) stream has reached +the end of file. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/FILE.c b/src/stdio/FILE.c new file mode 100644 index 00000000..854bbcee --- /dev/null +++ b/src/stdio/FILE.c @@ -0,0 +1,15 @@ +#include <stdio.h> +typedef struct __FILE FILE; + +/** buffered I/O stream **/ + +/*** +is used to hold information about buffered input and output streams. The +structure holds information including the current file position indicator, +a pointer to its buffer, an error indicator, and an end-of-file indicator. +No standard defines the members of THIS(). User programs should not attempt +to access or modify its members directly. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/FILENAME_MAX.c b/src/stdio/FILENAME_MAX.c new file mode 100644 index 00000000..4acdbcfb --- /dev/null +++ b/src/stdio/FILENAME_MAX.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define FILENAME_MAX (255) + +/** maximum filename length **/ + +/*** +is size of the longest array of TYPE(char) that the implementation guarantees +can be used as a file name. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/FOPEN_MAX.c b/src/stdio/FOPEN_MAX.c new file mode 100644 index 00000000..2cfc1fb0 --- /dev/null +++ b/src/stdio/FOPEN_MAX.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#define FOPEN_MAX (8) + +/** maximum open FILE streams **/ + +/*** +is the minimum number of TYPEDEF(FILE) streams that the implementation +guarantees can be opened at the same time. +***/ + +/* +VALUE_MIN(8) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/L_tmpnam.c b/src/stdio/L_tmpnam.c new file mode 100644 index 00000000..d35cb988 --- /dev/null +++ b/src/stdio/L_tmpnam.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#define L_tmpnam (255) + +/** temporary file name length **/ + +/*** +is the maximum length of a temporary filename returned by FUNCTION(tmpnam). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/NULL.ref b/src/stdio/NULL.ref new file mode 100644 index 00000000..d1bb9ab5 --- /dev/null +++ b/src/stdio/NULL.ref @@ -0,0 +1,3 @@ +#include <stdio.h> +REFERENCE(stddef/NULL.c) +STDC(1) diff --git a/src/stdio/SEEK_CUR.c b/src/stdio/SEEK_CUR.c new file mode 100644 index 00000000..558d57ef --- /dev/null +++ b/src/stdio/SEEK_CUR.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define SEEK_CUR (1) + +/** seek forward **/ + +/*** +is used as the ARGUMENT(whence) argument to FUNCTION(fseek) to indicate that +seeking should begin at the current file position and move forward. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/SEEK_END.c b/src/stdio/SEEK_END.c new file mode 100644 index 00000000..856d2074 --- /dev/null +++ b/src/stdio/SEEK_END.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define SEEK_END (2) + +/** seek from end **/ + +/*** +is used as the ARGUMENT(whence) argument to FUNCTION(fseek) to indicate that +seeking should begin at the end of the file and move backward. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/SEEK_SET.c b/src/stdio/SEEK_SET.c new file mode 100644 index 00000000..213c3c33 --- /dev/null +++ b/src/stdio/SEEK_SET.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define SEEK_SET (3) + +/** seek from beginning **/ + +/*** +is used as the ARGUMENT(whence) argument to FUNCTION(fseek) to indicate that +seeking should begin at the start of the file and move forward. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/TMP_MAX.c b/src/stdio/TMP_MAX.c new file mode 100644 index 00000000..af429fd3 --- /dev/null +++ b/src/stdio/TMP_MAX.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define TMP_MAX (10000) + +/** maximum temporary file names **/ + +/*** +is the minimum number of unique file names FUNCTION(tmpnam) is guaranteed to +be able to generate. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/_IOFBF.c b/src/stdio/_IOFBF.c new file mode 100644 index 00000000..659b787d --- /dev/null +++ b/src/stdio/_IOFBF.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define _IOFBF (1) + +/** full buffering **/ + +/*** +is used as the ARGUMENT(mode) in calls to FUNCTION(setvbuf) to indicate that +a stream should be fully buffered. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/_IOLBF.c b/src/stdio/_IOLBF.c new file mode 100644 index 00000000..8f84ae97 --- /dev/null +++ b/src/stdio/_IOLBF.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define _IOLBF (2) + +/** line buffering **/ + +/*** +is used as the ARGUMENT(mode) in calls to FUNCTION(setvbuf) to indicate that +a stream should be line buffered. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/_IONBF.c b/src/stdio/_IONBF.c new file mode 100644 index 00000000..aa88cb9b --- /dev/null +++ b/src/stdio/_IONBF.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#define _IONBF (3) + +/** no buffering **/ + +/*** +is used as the ARGUMENT(mode) in calls to FUNCTION(setvbuf) to indicate that +a stream should be unbuffered. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/_stdio.c b/src/stdio/_stdio.c new file mode 100644 index 00000000..05851eeb --- /dev/null +++ b/src/stdio/_stdio.c @@ -0,0 +1,2 @@ +#include "stdio.h" +FILE *stdin, *stdout, *stderr; diff --git a/src/stdio/clearerr.c b/src/stdio/clearerr.c new file mode 100644 index 00000000..9b817a97 --- /dev/null +++ b/src/stdio/clearerr.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** reset file stream error indicator **/ +void clearerr(FILE * stream) +{ + flockfile(stream); + if (stream != NULL) { + stream->eof = 0; + stream->err = 0; + } + funlockfile(stream); +} + +/*** +clears the error and end-of-file indicators of ARGUMENT(stream). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c new file mode 100644 index 00000000..e8cd037e --- /dev/null +++ b/src/stdio/fclose.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include "stdlib.h" +#include "nonstd/io.h" + +#ifdef _POSIX_SOURCE +#include "unistd.h" +#else +#define close(fd) -1 +#endif + +/** close a file stream **/ +int fclose(FILE *stream) +{ + flockfile(stream); + if (fflush(stream) == EOF) { + /* set errno */ + return EOF; + } + + if (stream->mem.buf) { + if (stream->mem.allocated) { + free(stream->mem.buf); + } + } else if (close(stream->fd) == -1) { + /* set errno */ + return EOF; + } + + /* + if (!(stream->flags & FF_USERBUF) && stream->buf != NULL) { + free(stream->buf); + } + */ + + funlockfile(stream); + /* + RETURN_SUCCESS(0); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return 0; +} + +/*** +function closes ARGUMENT(stream) and its associated file. Any +unwritten data is flushed before closing. Any unread data is discarded. If the +buffer was automatically allocated, it is freed. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/feof.c b/src/stdio/feof.c new file mode 100644 index 00000000..26c9a5a8 --- /dev/null +++ b/src/stdio/feof.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include "nonstd/io.h" +#include "nonstd/assert.h" + +/** test for end-of-file **/ +int feof(FILE *stream) +{ + ASSERT_NONNULL(stream); + flockfile(stream); + + if (stream->eof) { + return 1; + } + /* TODO */ + /* system level test */ + funlockfile(stream); + /* + RETURN(0, the end-of-file indicator is not set); + RETURN(NONZERO, the end-of-file indicator is set); + */ + return stream->eof; +} + +/*** +tests for the end-of-file indicator of ARGUMENT(stream). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/ferror.c b/src/stdio/ferror.c new file mode 100644 index 00000000..609f7640 --- /dev/null +++ b/src/stdio/ferror.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include "nonstd/assert.h" +#include "nonstd/io.h" + +/** tests the file stream error indicator **/ +int ferror(FILE *stream) +{ + ASSERT_NONNULL(stream); + /* + RETURN(0, the error indicator is not set); + RETURN(NONZERO, the error indicator is set); + */ + return stream->err; +} + +/*** +tests the error indicator of ARGUMENT(stream). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c new file mode 100644 index 00000000..c7514d10 --- /dev/null +++ b/src/stdio/fflush.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** flush buffered writes **/ +int fflush(FILE *stream) +{ + flockfile(stream); + if (stream == NULL) { + FILE *p; + for (p = __libc(FILE_TAIL); p != NULL; p = p->prev) { + fflush(p); + } + } + + /* + if (fsync(stream->fd) != 0) { + stream->err = 1; + return EOF; + } + */ + + funlockfile(stream); + /* + RETURN_SUCCESS(0); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return 0; +} + +/*** +function flushes any buffered write operations on ARGUMENT(stream) to +the underlying file. + +If ARGUMENT(stream) is CONSTANT(NULL), THIS() will flush all open streams. +***/ + +/* +UNDEFINED(ARGUMENT(stream) is not an output stream) +UNDEFINED(ARGUMENT(stream) is an update stream in which the most recent operation was input) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/fgetc.c b/src/stdio/fgetc.c new file mode 100644 index 00000000..8c682c39 --- /dev/null +++ b/src/stdio/fgetc.c @@ -0,0 +1,24 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** read a character from a file stream **/ +int fgetc(FILE *stream) +{ + flockfile(stream); + char c = getc_unlocked(stream); + funlockfile(stream); + /* + RETURN_SUCCESS(the next character); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return c; +} + +/*** +reads the next character from ARGUMENT(stream) as an +TYPE(unsigned char) converted to an TYPE(int). The file position indicator +of ARGUMENT(stream) is advanced. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c new file mode 100644 index 00000000..177519d1 --- /dev/null +++ b/src/stdio/fgetpos.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** get the file stream position indicator **/ +int fgetpos(FILE * restrict stream, fpos_t * restrict pos) +{ + flockfile(stream); + *pos = stream->pos; + funlockfile(stream); + return 0; +} + +/*** +stores the current value of the file position indicator +for ARGUMENT(stream) into the TYPEDEF(fpos_t) at ARGUMENT(pos). +***/ + +/* +UNSPECIFIED(The information stored in TYPEDEF(fpos_t)) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/fgets.c b/src/stdio/fgets.c new file mode 100644 index 00000000..df110de2 --- /dev/null +++ b/src/stdio/fgets.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** read a string of characters from a file stream **/ +char * fgets(char * restrict s, int n, FILE * restrict stream) +{ + flockfile(stream); + + int i = 0; + if (feof(stream)) { + return NULL; + } + + while (i < n-1) { + s[i] = fgetc(stream); + if (s[i] == '\n') { + s[i+1] = '\0'; + i = n; + } else if (s[i] == EOF && feof(stream)) { + s[i] = '\0'; + i = n; + } + i++; + } + + funlockfile(stream); + /* + RETURN_SUCCESS(ARGUMENT(s)); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return s; +} + +/*** +reads a string of characters from ARGUMENT(stream). Up to +ARGUMENT(n)-1 characters will be read into the array at ARGUMENT(s). + +If a newline is read, it will be appended to ARGUMENT(s) and THIS() will return. + +If end-of-file is reached, THIS() will return. + +A CHAR(\0) will be written immediately after the final character is read. + +If end-of-file is reached before any characters are read, the contents of +ARGUMENT(s) will be unchanged. + +If an error occurs, the contents of ARGUMENT(s) are indeterminite. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c new file mode 100644 index 00000000..935885d9 --- /dev/null +++ b/src/stdio/fopen.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include "stdlib.h" +#include "nonstd/internal.h" +#include "nonstd/io.h" + +/** open a file stream **/ +FILE * fopen(const char * restrict filename, const char * restrict mode) +{ + FILE *f = calloc(1, sizeof(*f)); + f->fd = -1; + if (freopen(filename, mode, f) == NULL) { + free(f); + return NULL; + } + + if (__libc(FILE_TAIL)) { + f->prev = __libc(FILE_TAIL); + f->prev->next = f; + } + + /* __libc(FILE_TAIL) = f; */ + + /* + RETURN_SUCCESS(a pointer to the new file stream); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return f; +} + +/*** +opens a file stream associated with the file ARGUMENT(filename). + +The type of file and allowed operations are determined by ARGUMENT(mode): + +FLAG(LITERAL(r), text file; read-only) +FLAG(LITERAL(w), text file; write-only; truncate to 0 bytes) +FLAG(LITERAL(a), text file; append) +FLAG(LITERAL(rb), binary file; read-only) +FLAG(LITERAL(wb), binary file; write-only; truncate to 0 bytes) +FLAG(LITERAL(ab), binary file; append) +FLAG(LITERAL(r+), text file; update (read and write)) +FLAG(LITERAL(w+), text file; update (read and write); truncate to 0 bytes) +FLAG(LITERAL(a+), text file; update (read and write); append data to end of file) +FLAG(LITERAL(r+b), binary file; update (read and write)) +FLAG(LITERAL(rb+), binary file; update (read and write)) +FLAG(LITERAL(w+b), binary file; update (read and write); truncate to 0 bytes) +FLAG(LITERAL(wb+), binary file; update (read and write); truncate to 0 bytes) +FLAG(LITERAL(a+b), binary file; update (read and write); append data to end of file) +FLAG(LITERAL(ab+), binary file; update (read and write); append data to end of file) + +File streams are opened in fully buffered mode if and only if +ARGUMENT(filename) is not an interactive device. + +The error and end-of-file indicators are cleared. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdio/fpos_t.c b/src/stdio/fpos_t.c new file mode 100644 index 00000000..40d304cf --- /dev/null +++ b/src/stdio/fpos_t.c @@ -0,0 +1,12 @@ +#include <stdio.h> +typedef struct __fpos_t * fpos_t; + +/** file position **/ + +/*** +is used to record information about individual positions within a TYPEDEF(FILE) +stream. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fprintf.c b/src/stdio/fprintf.c new file mode 100644 index 00000000..053277d7 --- /dev/null +++ b/src/stdio/fprintf.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** write formatted output to a file stream **/ +int fprintf(FILE * restrict stream, const char * restrict format, ...) +{ + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = "fprintf"; + opt.stream = stream; + va_start(ap, format); + ret = __printf(&opt, format, ap); + va_end(ap); + /* + RETURN_SUCCESS(the number of characters written); + RETURN_FAILURE(NEGATIVE()); + */ + return ret; +} + +/*** +writes a formatted string to ARGUMENT(stream). The format of ARGUMENT(format) +and the variadic arguments is the same as that for FUNCTION(printf). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fputc.c b/src/stdio/fputc.c new file mode 100644 index 00000000..eb249b77 --- /dev/null +++ b/src/stdio/fputc.c @@ -0,0 +1,42 @@ +#include <stdio.h> +#include "nonstd/io.h" + +#ifdef _POSIX_SOURCE +#include "unistd.h" +#else +#define write(fd, buf, size) -1 +#endif + +/** write a character to a file stream **/ +int fputc(int c, FILE *stream) +{ + unsigned char ch = (unsigned char)c; + flockfile(stream); + + if (!stream) { + return EOF; + } + + if (write(stream->fd, &ch, sizeof(ch)) != 1) { + /* error */ + return EOF; + } + + funlockfile(stream); + /* + RETURN_SUCCESS(ARGUMENT(c)); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return ch; +} + +/*** +writes the character ARGUMENT(c) (converted to an TYPE(unsigned char)) to +ARGUMENT(stream). The character is written at the current +file position indicator, which is advanced. If ARGUMENT(stream) does not support +seeking or was opened in append mode, the character is written to the end of +the stream. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c new file mode 100644 index 00000000..b33d3b59 --- /dev/null +++ b/src/stdio/fputs.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** write a string to a file stream **/ +int fputs(const char * restrict s, FILE * restrict stream) +{ + flockfile(stream); + while (*s) { + if (fputc(*s++, stream) == EOF) { + return EOF; + } + } + funlockfile(stream); + + /* + RETURN_SUCCESS(NONNEGATIVE()); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return 1; +} + +/*** +writes the string ARGUMENT(s) to ARGUMENT(stream), not including +the terminating CHAR(\0) character. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fread.c b/src/stdio/fread.c new file mode 100644 index 00000000..692e3e18 --- /dev/null +++ b/src/stdio/fread.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** read directly from a file stream **/ +size_t fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream) +{ + unsigned char *buf = ptr; + size_t n = 0; + flockfile(stream); + while (nmemb) { + size_t i; + for (i = 0; i < size; i++) { + int c = fgetc(stream); + if (c == EOF) { + /* an error */ + } else { + buf[i] = (char)c; + } + } + nmemb--; + buf += size; + n++; + } + funlockfile(stream); + /* + RETURN_SUCCESS(the number of elements read); + */ + return n; +} + +/*** +reads up to ARGUMENT(nmemb) elements of ARGUMENT(size) bytes each +from ARGUMENT(stream) into the array at ARGUMENT(ptr). + +The file position indicate is advanced by the number of bytes read. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c new file mode 100644 index 00000000..cddf296a --- /dev/null +++ b/src/stdio/freopen.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include "errno.h" +#include "nonstd/io.h" + +#ifdef _POSIX_SOURCE +#include "fcntl.h" +#else +#define open(fname, flags, mode) (filename ? -1 : -1) +#endif + +/** reopen a file stream with a new file **/ +FILE * freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream) +{ + flockfile(stream); + (void)mode; + + int openmode = 0; /* modetoflag(mode); */ + if (openmode == 0) { + #ifdef EINVAL + errno = EINVAL; + #endif + return NULL; + } + + int fd = open(filename, openmode, 0); + if (fd == -1) { + /* set errno */ + return NULL; + } + + stream->fd = fd; + stream->nlocks = 0; + + /* + RETURN_SUCCESS(ARGUMENT(stream)); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return stream; +} + +/*** +changes the file associated with ARGUMENT(stream) to +ARGUMENT(filename). The meaning of ARGUMENT(mode) is the same as with +FUNCTION(fopen). + +Whatever file is currently associated with ARGUMENT(stream) is closed, +ignoring any errors. + +The error and end-of-file indicators are cleared. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c new file mode 100644 index 00000000..adbb753c --- /dev/null +++ b/src/stdio/fscanf.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/internal.h" +#include "nonstd/io.h" + +/** read formatted input from a file stream **/ +int fscanf(FILE * restrict stream, const char * restrict format, ...) +{ + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = "fscanf"; + opt.stream = stream; + va_start(ap, format); + ret = __scanf(&opt, format, ap); + va_end(ap); + /* + RETURN_SUCCESS(the number of input items assigned); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return ret; +} + +/*** +reads formatted input from ARGUMENT(stream). The format of ARGUMENT(format) at +the variadic arguments is the same as that for FUNCTION(scanf). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c new file mode 100644 index 00000000..2cee57a1 --- /dev/null +++ b/src/stdio/fseek.c @@ -0,0 +1,35 @@ +#include <stdio.h> + +/** set the file position indicator **/ +int fseek(FILE *stream, long int offset, int whence) +{ + (void)stream; (void)offset; + + if (whence == SEEK_CUR) { + } else if (whence == SEEK_END) { + } else if (whence == SEEK_SET) { + } + + return 1; +} + +/*** +sets the file position indicator for ARGUMENT(stream). + +How the indicator is set is determined by ARGUMENT(whence): + +FLAG(CONSTANT(SEEK_SET), The indicator is set to the beginning of the file plus ARGUMENT(offset)) +FLAG(CONSTANT(SEEK_CUR), The indicator is advanced from its current position by ARGUMENT(offset), which may be negative) +FLAG(CONSTANT(SEEK_END), The indicator is set to the end of the file minus ARGUMENT(offset)) + +A successful call to fn(fseek) clears the end-of-file indicator and discards +any characters pushed with fn(ungetc). +***/ + +/* +UNDEFINED(Specifying CONSTANT(SEEK_END) for ARGUMENT(whence) on a binary file) +UNDEFINED(Specifying a value for ARGUMENT(offset) other than 0 or a previous return value of FUNCTION(ftell) on a text file) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c new file mode 100644 index 00000000..8ec7cdd8 --- /dev/null +++ b/src/stdio/fsetpos.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +/** set the file position indicator **/ +int fsetpos(FILE *stream, const fpos_t *pos) +{ + (void)stream; (void)pos; + /* TODO */ + return 1; +} + +/*** +sets the file position indicator of ARGUMENT(stream) to +ARGUMENT(pos), which must have been previously obtained by a call to +FUNCTION(fgetpos). + +A successful call to THIS() clears the end-of-file indicator and discards +any characters pushed back with FUNCTION(ungetc). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/ftell.c b/src/stdio/ftell.c new file mode 100644 index 00000000..796a468c --- /dev/null +++ b/src/stdio/ftell.c @@ -0,0 +1,26 @@ +#include <stdio.h> + +/** get the file position indicator **/ +long int ftell(FILE *stream) +{ + (void)stream; + /* TODO */ + /* + RETURN_SUCCESS(the current file position); + RETURN_FAILURE(LITERAL(-1L)); + */ + return -1L; +} + +/*** +obtains the current value of the file position indicitor of ARGUMENT(stream). + +For binary streams, the indicator is the current byte position. +***/ + +/* +UNSPECIFIED(The meaning of the file position indicator for text streams) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c new file mode 100644 index 00000000..047ee892 --- /dev/null +++ b/src/stdio/fwrite.c @@ -0,0 +1,36 @@ +#include <stdio.h> + +/** write directly to a file stream **/ +size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream) +{ + unsigned char *buf = (unsigned char *)ptr; + size_t n = 0; + while (nmemb) { + size_t i; + for (i = 0; i < size; i++) { + int c = fputc(buf[i], stream); + if (c == EOF) { + /* an error */ + } else { + n++; + } + } + nmemb--; + buf += size; + } + /* + RETURN_SUCCESS(the number of elements written); + */ + return n; +} + +/*** +writes ARGUMENT(nmemb) elements of ARGUMENT(size) bytes each from +the array ARGUMENT(ptr) to ARGUMENT(stream). + +The file position inidicate is advanced by the number of bytes successfully +written. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/getc.c b/src/stdio/getc.c new file mode 100644 index 00000000..11a75d4e --- /dev/null +++ b/src/stdio/getc.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +/** read a character from a file stream **/ +int getc(FILE *stream) +{ + /* + RETURN_SUCCESS(the next character); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return fgetc(stream); +} + +/*** +is the equivalent of FUNCTION(fgetc) except that if it is +defined as a macro, it may evaluate ARGUMENT(stream) more than once. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/getchar.c b/src/stdio/getchar.c new file mode 100644 index 00000000..3bd12654 --- /dev/null +++ b/src/stdio/getchar.c @@ -0,0 +1,18 @@ +#include <stdio.h> + +/** read a character from stdin **/ +int getchar(void) +{ + /* + RETURN_SUCCESS(the next character); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return getc(stdin); +} + +/*** +reads the next character from ARGUMENT(stdin). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/gets.c b/src/stdio/gets.c new file mode 100644 index 00000000..fbe16cd2 --- /dev/null +++ b/src/stdio/gets.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include "limits.h" + +/** read a line from stdin **/ +char * gets(char *s) +{ + /* + RETURN_SUCCESS(ARGUMENT(s)); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return fgets(s, INT_MAX, stdin); +} + +/*** +does no bounds checking, is marked obsolete in ISO/IEC 9899:1999, and +has been removed from ISO/IEC 9899:2011. It is a security risk and should not be used. + +The THIS() function reads a line of input from IDENTIFIER(stdin) into the array +ARGUMENT(s). Input characters are read until a newline or end-of-file is reached. The +newline will not be appended to ARGUMENT(s). A CHAR(\0) character will be written +after the last character read into the array. + +If end-of-file is reached before any characters are read, the contents of ARGUMENT(s) +remain unchanged. +***/ +/* +STDC(1,201112) +*/ diff --git a/src/stdio/perror.c b/src/stdio/perror.c new file mode 100644 index 00000000..2aae8470 --- /dev/null +++ b/src/stdio/perror.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include "string.h" +#include "errno.h" + +/** print an error message **/ +void perror(const char *s) +{ + if (s != NULL && *s != '\0') { + fprintf(stderr, "%s: ", s); + } + fprintf(stderr, "%s\n", strerror(errno)); +} + +/*** +writes an error message to IDENTIFIER(stderr). + +If ARGUMENT(s) is CONSTANT(NULL), the error message is a string representation of the +current value of IDENTIFIER(errno). + +If ARGUMENT(s) is not CONSTANT(NULL), the error message will be preceded by the string +pointed to by ARGUMENT(s), a colon (CHAR(:)), and a space. +***/ + +/* +POSIX_(L_C_MESSAGES) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/printf.c b/src/stdio/printf.c new file mode 100644 index 00000000..57684158 --- /dev/null +++ b/src/stdio/printf.c @@ -0,0 +1,111 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/internal.h" +#include "nonstd/io.h" + +/** write formatted output **/ +int printf(const char *format, ...) +{ + + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = "printf"; + opt.stream = stdout; + va_start(ap, format); + ret = __printf(&opt, format, ap); + va_end(ap); + + /* + RETURN_SUCCESS(the number of characters written); + RETURN_FAILURE(NEGATIVE); + */ + return ret; +} + +/*** +writes a formatted string to IDENTIFIER(stdout). + +The argument ARGUMENT(format) controls the output. It points to a +NUL-terminated multibyte character string. Characters other than CHAR(%) +are output unmodified. The CHAR(%) begins a conversion specifier, which is +made up of the following: + +__(Zero or more CONCEPT(flags, flags)) +__(An optional CONCEPT(fieldwidth, field width) <!-- TODO: describe -->) +__(An optional CONCEPT(precision, precision) <!-- TODO: describe -->) +__(An optional CONCEPT(typewidth, type width) <!-- TODO: describe -->) +__(The CONCEPT(typespec, type specifier) <!-- TODO: describe -->) + +CONCEPT_DEFINITION(flags, Flags) +The following flags modify output as indicated: + +FLAG(CHAR(-), Left-justify this field (the default is right-justification)) +FLAG(CHAR(+), Always include a plus or minus sign for signed values (the default is only to display a sign for negative values)) +FLAG(SPACE, TODO: I am not entirely clear on this myself) +FLAG(CHAR(#), TODO: Or this one) +FLAG(CHAR(0), Include leading zeros unless TODO) + +CONCEPT_DEFINITION(fieldwidth, Field Width) +If the provided value has fewer characters than specified here, it will be +padded with spaces or zeroes to fill the desired width. The width is specified +as a decimal integer or a CHAR(*). If CHAR(*) is specified, the width will +be taken from the next argument as an TYPE(int). + +CONCEPT_DEFINITION(precision, Precision) +The maximum number of digits in CHAR(d), CHAR(i), CHAR(o), CHAR(u), +CHAR(x), and CHAR(X) conversions; or, the number of digits after the +decimal for CHAR(e), CHAR(E), and CHAR(f) converions; or, the maximum +number of significant digits for CHAR(g) and CHAR(G) conversions; or, the +maximum number of characters from a string in CHAR(s) conversions. The +precision is specified by a CHAR(.) followed by a decimal integer, a +CHAR(*), or nothing. If CHAR(*) is specified, the precision will be taken +from the next argument as an TYPE(int). If nothing is specified, it is +the same as specifying CHAR(0). + +CONCEPT_DEFINITION(typewidth, Type Width) +The following type widths can be applied to ensure accurate type conversions +following normal argument type promotions: +FLAG(CHAR(h), `Converts the next argument to TYPE(short int) or + TYPE(unsigned short int) for CHAR(d), CHAR(i), CHAR(o), + CHAR(u), CHAR(x), and CHAR(X) conversions.') +FLAG(CHAR(h), `Specifies that pointer at an CHAR(n) conversion is a + TYPE(short int).') +FLAG(CHAR(l), `Converts the next argument to TYPE(long int) or + TYPE(unsigned long int) for CHAR(d), CHAR(i), CHAR(o), + CHAR(u), CHAR(x), and CHAR(X) conversions.') +FLAG(CHAR(l), `Specifies that pointer at an CHAR(n) conversion is a + TYPE(long int).') +FLAG(CHAR(L), `Converts the next argument to TYPE(long double) for + CHAR(e), CHAR(E), CHAR(f), CHAR(g), and CHAR(G) conversions.') + +CONCEPT_DEFINITION(typespec, Type Specifier) +The final character of the conversion specifier indicates the type of value +to be output: + +FLAG(CHAR(d), `Converts an TYPE(int) to a signed decimal number.') +FLAG(CHAR(i), `Same as CHAR(d).') +FLAG(CHAR(o), `Converts an TYPE(unsigned int) to octal notation.') +FLAG(CHAR(u), `Converts an TYPE(unsigned int) to decimal notation.') +FLAG(CHAR(x), `Converts an TYPE(unsigned int) to hexadecimal notation using lowercase letters.') +FLAG(CHAR(X), `Converts an TYPE(unsigned int) to hexadecimal notation using uppercase letters.') +FLAG(CHAR(f), `Converts a TYPE(double) to decimal notation.') +FLAG(CHAR(e), `Converts a TYPE(double) to scientific notation with a lowercase CHAR(e).') +FLAG(CHAR(E), `Converts a TYPE(double) to scientific notation with an uppercase CHAR(E).') +FLAG(CHAR(g), `FIXME: Same as CHAR(f) or CHAR(e) depending on precision.') +FLAG(CHAR(G), `FIXME: Same as CHAR(f) or CHAR(E) depending on precision.') +FLAG(CHAR(c), `Converts a TYPE(unsigned char) to a character.') +FLAG(CHAR(s), `Converts a pointer to an array of TYPE(char) to a NUL-terminated string.') +FLAG(CHAR(p), `Converts a TYPE(void *) to an implementation-defined format.') +FLAG(CHAR(n), `Causes the function to write the total number of characters output so far to an TYPE(int) pointed at by the next argument.') +FLAG(CHAR(%), `Outputs a literal CHAR(%).') +***/ + +/* +IMPLEMENTATION(`The format of CHAR(p) conversions', `STRING(0x%0ARGUMENT(n)x), where ARGUMENT(n) is the number of hexadecimal digits in a canonical address on the platform of execution.') +UNDEFINED(`Precision with a conversion specifier other than CHAR(d), CHAR(i), CHAR(o), CHAR(u), CHAR(x), CHAR(X), CHAR(e), CHAR(E), CHAR(f), CHAR(g), CHAR(G), or CHAR(s)') +UNDEFINED(TODO: Using h or l for !(diouxXn) or L for !(eEfgG)) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/putc.c b/src/stdio/putc.c new file mode 100644 index 00000000..c3509ee2 --- /dev/null +++ b/src/stdio/putc.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +/** write a character to a file stream **/ +int putc(int c, FILE *stream) +{ + /* + RETURN_SUCCESS(ARGUMENT(c)); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return fputc(c, stream); +} + +/*** +is equivalent of FUNCTION(fputc), except that if it is defined +as a macro, it may evaluate ARGUMENT(stream) more than once. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/putchar.c b/src/stdio/putchar.c new file mode 100644 index 00000000..cb12ec0c --- /dev/null +++ b/src/stdio/putchar.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +/** write a character to stdout **/ +int putchar(int c) +{ + /* + RETURN_SUCCESS(c); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return putc(c, stdout); +} + +/*** +writes the character ARGUMENT(c) (converted to an TYPE(unsigned char)) to +IDENTIFIER(stdout). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/puts.c b/src/stdio/puts.c new file mode 100644 index 00000000..7aeb8d83 --- /dev/null +++ b/src/stdio/puts.c @@ -0,0 +1,27 @@ +#include <stdio.h> + +/** write a string to stoud **/ +int puts(const char *s) +{ + if (fputs(s, stdout) == EOF) { + return EOF; + } + + if (putc('\n', stdout) == EOF) { + return EOF; + } + + /* + RETURN_SUCCESS(NONNEGATIVE()); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return 1; +} + +/*** +function writes the string pointed to by ARGUMENT(s) to IDENTIFIER(stdout), +followed by a newline. The terminated CHAR(\0) is not written. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/remove.c b/src/stdio/remove.c new file mode 100644 index 00000000..2a10e443 --- /dev/null +++ b/src/stdio/remove.c @@ -0,0 +1,37 @@ +#include <stdio.h> + +#ifdef _POSIX_SOURCE +#include "sys/types.h" +#include "sys/stat.h" +#include "unistd.h" +#else + struct stat { int st_mode; }; +#define stat(f, b) (void)f +#define S_ISDIR(m) (m = 0) +#define rmdir(f) (-1) +#define unlink(f) (-1) +#endif + +/** delete a file **/ + +int remove(const char *filename) +{ + struct stat st; + stat(filename, &st); + if (S_ISDIR(st.st_mode)) { + return rmdir(filename); + } + return unlink(filename); +} + +/*** +function removes the file ARGUMENT(filename) so the future attempts to +open that file will fail unless creating a new file. +***/ + +/* +IMPLEMENTATION(Whether the file is removed if it is open) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/rename.c b/src/stdio/rename.c new file mode 100644 index 00000000..068cd73d --- /dev/null +++ b/src/stdio/rename.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "errno.h" +#include "nonstd/syscall.h" + +/** rename a file **/ +int rename(const char *old, const char *new) +{ + SYSCALL_NUMBER(sc, "rename", -1); + int err = 0; + + err = __syscall(sc, old, new); + if (err < 0) { + errno = -err; + return -1; + } + + return 0; +} + +/*** +renames a file from its original name ARGUMENT(old) to +ARGUMENT(new). +***/ + +/* +IMPLEMENTATION(Behavior if ARGUMENT(new) exists prior to THIS() being called) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/rewind.c b/src/stdio/rewind.c new file mode 100644 index 00000000..73be1f57 --- /dev/null +++ b/src/stdio/rewind.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +/** reset file position indicator **/ +void rewind(FILE *stream) +{ + fseek(stream, 0L, SEEK_SET); + clearerr(stream); +} + +/*** +sets the file position indicator of ARGUMENT(stream) to the +beginning of the file. The error indicator will be cleared. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/scanf.c b/src/stdio/scanf.c new file mode 100644 index 00000000..5fbe51ec --- /dev/null +++ b/src/stdio/scanf.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/internal.h" +#include "nonstd/io.h" + +/** read formatted input **/ +int scanf(const char * restrict format, ...) +{ + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = "scanf"; + opt.stream = stdout; + va_start(ap, format); + ret = __scanf(&opt, format, ap); + va_end(ap); + /* + RETURN_SUCCESS(the number of input items assigned); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return ret; +} + +/*** +reads formatted input from macro(stdin). + +FIXME: scanf format goes here +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/setbuf.c b/src/stdio/setbuf.c new file mode 100644 index 00000000..351db3d3 --- /dev/null +++ b/src/stdio/setbuf.c @@ -0,0 +1,24 @@ +#include <stdio.h> + +/** specify file stream buffer **/ +void setbuf(FILE * restrict stream, char * restrict buf) +{ + if (buf) { + setvbuf(stream, buf, _IOFBF, BUFSIZ); + } else { + setvbuf(stream, NULL, _IONBF, 0); + } +} + +/*** +sets the buffer for ARGUMENT(stream) to ARGUMENT(buf). The buffer must hold +at least CONSTANT(BUFSIZ) characters. It is the equivalent of: + LITERAL(setvbuf(stream, buf, _IOFBF, BUFSIZ);) + +If ARGUMENT(buf) is CONSTANT(NULL), ARGUMENT(stream) will become unbuffered. It is the +equivalent of: + LITERAL(setvbuf(stream, NULL, _IONBF, 0);) +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c new file mode 100644 index 00000000..0db67cda --- /dev/null +++ b/src/stdio/setvbuf.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include "stdlib.h" +#include "nonstd/io.h" + +/** specify file stream buffering options **/ +int setvbuf(FILE *stream, char *buf, int mode, size_t size) +{ + if (stream == NULL + || !stream->isopen + || stream->buftype != UNSET + || (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)) + { + return 1; + } + + stream->buffering = mode; + stream->bsize = size; + + if (buf != NULL) { + stream->buf = buf; + stream->buftype = SUPPLIED; + } else if (mode != _IONBF) { + stream->buf = calloc(size, sizeof(char)); + stream->buftype = ALLOCED; + } + + return 0; +} + +/*** +function sets the type of buffering for a file stream, along +with the size and location of the buffer. It must be called before any other +operations are performed. + +The type of buffering is specified by ARGUMENT(mode): +FLAG(CONSTANT(_IOFBF), fully buffered) +FLAG(CONSTANT(_IOLBF), line buffered) +FLAG(CONSTANT(_IONBF), unbuffered) + +If ARGUMENT(buf) is CONSTANT(NULL), THIS() will automatically allocate an +appropriate buffer. If ARGUMENT(buf) is not CONSTANT(NULL), it must point to +an array of at least ARGUMENT(size) characters. + +The ARGUMENT(size) argument specifies the size of the buffer. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/size_t.ref b/src/stdio/size_t.ref new file mode 100644 index 00000000..5b9b0797 --- /dev/null +++ b/src/stdio/size_t.ref @@ -0,0 +1,3 @@ +#include <stdio.h> +REFERENCE(stddef/size_t.c) +STDC(1) diff --git a/src/stdio/snprintf.c b/src/stdio/snprintf.c new file mode 100644 index 00000000..bc6df080 --- /dev/null +++ b/src/stdio/snprintf.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int snprintf(char * restrict s, size_t n, const char * restrict format, ...) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c new file mode 100644 index 00000000..babd4ba3 --- /dev/null +++ b/src/stdio/sprintf.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** write formatted output to a string **/ +int sprintf(char * restrict s, const char * restrict format, ...) +{ + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = "sprintf"; + opt.string = s; + opt.maxlen = (size_t)-1; + va_start(ap, format); + ret = __printf(&opt, format, ap); + va_end(ap); + /* + RETURN_SUCCESS(the number of characters written to the array, not counting the terminating null); + */ + return ret; +} + +/*** +writes a formatted string to the buffer at ARGUMENT(s). The format of +ARGUMENT(format) and the variadic arguments is the same as that for +FUNCTION(printf). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/sscanf.c b/src/stdio/sscanf.c new file mode 100644 index 00000000..f6637476 --- /dev/null +++ b/src/stdio/sscanf.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** read formatted input from a string **/ +int sscanf(const char * restrict s, const char * restrict format, ...) +{ + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = "sscanf"; + opt.string = (char *)s; + va_start(ap, format); + ret = __scanf(&opt, format, ap); + va_end(ap); + /* + RETURN_SUCCESS(the number of input items assigned); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return ret; +} + +/*** +reads formatted input from the string ARGUMENT(s). The format of +ARGUMENT(format) at the variadic arguments is the same as that for +FUNCTION(scanf). +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/stderr.c b/src/stdio/stderr.c new file mode 100644 index 00000000..0a2a6a2e --- /dev/null +++ b/src/stdio/stderr.c @@ -0,0 +1,12 @@ +#include <stdio.h> + extern FILE *stderr; +#define stderr stderr + +/** standard error **/ + +/*** +is the standard error stream. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/stdin.c b/src/stdio/stdin.c new file mode 100644 index 00000000..ba24de75 --- /dev/null +++ b/src/stdio/stdin.c @@ -0,0 +1,12 @@ +#include <stdio.h> + extern FILE *stdin; +#define stdin stdin + +/** standard input **/ + +/*** +is the standard input stream. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/stdout.c b/src/stdio/stdout.c new file mode 100644 index 00000000..9a822f8f --- /dev/null +++ b/src/stdio/stdout.c @@ -0,0 +1,12 @@ +#include <stdio.h> + extern FILE *stdout; +#define stdout stdout + +/** standard output **/ + +/*** +is the standard output stream. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c new file mode 100644 index 00000000..7143b491 --- /dev/null +++ b/src/stdio/tmpfile.c @@ -0,0 +1,33 @@ +#include <stdio.h> + +/* open a temporary file stream */ +FILE * tmpfile(void) +{ + char *path = "FIXME: A temporary file name *not* calling tmpnam()"; + FILE *f = fopen(path, "w+"); + if (f) { + /* FIXME: set flag for temporary in FILE struct */ + } else { + /* FIXME: set errno */ + } + + /* + RETURN_SUCCESS(a pointer to the temporary file stream); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return f; +} + +/*** +creates a temporary binary file stream for update (as +when ARGUMENT(mode) is specified as LITERAL("wb+") to FUNCTION(fopen)). +The file stream will be automatically removed when closed by FUNCTION(fclose) +or when the program exits. +***/ + +/* +IMPLEMENTATION(Whether the temporary file is removed if the program terminates abnormally) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/tmpnam.c b/src/stdio/tmpnam.c new file mode 100644 index 00000000..b4b5d932 --- /dev/null +++ b/src/stdio/tmpnam.c @@ -0,0 +1,43 @@ +#include <stdio.h> + +/** generate a temporary file name **/ +char * tmpnam(char *s) +{ + static int ntimescalled = 0; + static char path[L_tmpnam]; + + if (ntimescalled >= TMP_MAX) { + return NULL; + } + ntimescalled++; + + if (s == NULL) { + s = path; + } + + /* + RETURN_SUCCESS(a pointer to the temporary file name); + */ + return s; +} + +/*** +generates a unique file name that can be used as a +temporary file. A new file name is generated every time the function is called +up to CONSTANT(TMP_MAX) times. + +If ARGUMENT(s) is CONSTANT(NULL), the temporary name is stored in a static +internal buffer. This buffer may be overwritten by additional calls to +THIS(). + +If ARGUMENT(s) is not CONSTANT(NULL), it should point to a TYPE(char) array of +at least CONSTANT(L_tmpnam) characters. The temporary name will be copied to +this array. +***/ + +/* +IMPLEMENTATION(Behavior if THIS() is called more than CONSTANT(TMP_MAX) times) +*/ +/* +STDC(1) +*/ diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c new file mode 100644 index 00000000..1c32ac1f --- /dev/null +++ b/src/stdio/ungetc.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include "nonstd/io.h" + +/** push a character back into an input stream **/ +int ungetc(int c, FILE *stream) +{ + (void)c; (void)stream; + /* TODO */ + /* + RETURN_SUCCESS(ARGUMENT(c)); + RETURN_FAILURE(CONSTANT(EOF)); + */ + return EOF; +} + +/*** +pushes the characer ARGUMENT(c) (converted to an +type(unsigned char)) into the input stream ARGUMENT(stream). Future function calls +that read input will return the pushed character. Calls to seeking functions +(e.g. FUNCTION(fseek), FUNCTION(fsetpos), or FUNCTION(rewind)) will discard pushed characters. +The file associated with ARGUMENT(stream) is unchanged. + +At least one character can be pushed back. Multiple calls to THIS() without +intervening read operations may fail. + +If macro(EOF) is specified for ARGUMENT(c), THIS() fails and the input stream +is unchagned. + +A successfull call clears the end-of-file indicator for ARGUMENT(stream). The file +position indicator is decremented. + +Calling THIS() on a binary stream when the file position indicator is zero +is obsolete in ISO/IEC 9899:1999. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/va_list.ref b/src/stdio/va_list.ref new file mode 100644 index 00000000..f1fd28ec --- /dev/null +++ b/src/stdio/va_list.ref @@ -0,0 +1,3 @@ +#include <stdio.h> +REFERENCE(stdarg/va_list.c) +STDC(1) diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c new file mode 100644 index 00000000..c6a35edc --- /dev/null +++ b/src/stdio/vfprintf.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** write formatted output to a file stream **/ +int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg) +{ + int ret = 0; + struct io_options opt = {0}; + opt.fnname = "vfprintf"; + opt.stream = stream; + ret = __printf(&opt, format, arg); + /* + RETURN_SUCCESS(the number of characters written); + RETURN_FAILURE(an error occured); + */ + return ret; +} + +/*** +is equivalent to FUNCTION(fprintf), but with a TYPEDEF(va_list) +argument instead of variadic arguments. The argument ARGUMENT(arg) must be +initialized with FUNCTION(va_start) prior to calling THIS(). The THIS() +function does not call FUNCTION(va_end), so the calling function is +responsible for this. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c new file mode 100644 index 00000000..44ce6ea2 --- /dev/null +++ b/src/stdio/vfscanf.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/stdio/vprintf.c b/src/stdio/vprintf.c new file mode 100644 index 00000000..eb9b4d30 --- /dev/null +++ b/src/stdio/vprintf.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** write formatted output **/ +int vprintf(const char * restrict format, va_list arg) +{ + int ret = 0; + struct io_options opt = {0}; + opt.fnname = "vfprintf"; + opt.stream = stdout; + ret = __printf(&opt, format, arg); + /* + RETURN_SUCCESS(the number of characters written); + RETURN_FAILURE(NEGATIVE()); + */ + return ret; +} + +/*** +is equivalent to FUNCTION(printf), but with a TYPEDEF(va_list) +argument instead of variadic arguments. The argument ARGUMENT(arg) must be +initialized with FUNCTION(va_start) prior to calling THIS(). The THIS() +function does not call FUNCTION(va_end), so the calling function is +responsible for this. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/vscanf.c b/src/stdio/vscanf.c new file mode 100644 index 00000000..189ae04f --- /dev/null +++ b/src/stdio/vscanf.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int vscanf(const char * restrict format, va_list arg) +{ + return vfscanf(stdin, format, arg); +} + +/* +STDC(199901) +*/ diff --git a/src/stdio/vsnprintf.c b/src/stdio/vsnprintf.c new file mode 100644 index 00000000..7c5a1e03 --- /dev/null +++ b/src/stdio/vsnprintf.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include "stdarg.h" + +int vsnprintf(char * restrict s, size_t n, va_list ap) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/stdio/vsprintf.c b/src/stdio/vsprintf.c new file mode 100644 index 00000000..4a6ec2b8 --- /dev/null +++ b/src/stdio/vsprintf.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" +#include "nonstd/internal.h" + +/** write formatted output to a string **/ +int vsprintf(char *s, const char *format, va_list arg) +{ + int ret = 0; + struct io_options opt = {0}; + opt.fnname = "fprintf"; + opt.string = s; + opt.maxlen = (size_t)-1; + ret = __printf(&opt, format, arg); + /* + RETURN_SUCCESS(the number of characters written, not including the final CHAR(\0)); + */ + return ret; +} + +/*** +is equivalent to fn(sprintf), but with a TYPEDEF(va_list) +argument instead of variadic arguments. The argument ARGUMENT(arg) must be +initialized with FUNCTION(va_start) prior to calling THIS(). The +THIS() function does not call FUNCTION(va_end), so the calling function is +responsible for this. +***/ +/* +STDC(1) +*/ diff --git a/src/stdio/vsscanf.c b/src/stdio/vsscanf.c new file mode 100644 index 00000000..534f30ea --- /dev/null +++ b/src/stdio/vsscanf.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include "stdarg.h" + +int vsscanf(const char * restrict s, const char * restrict format, va_list arg) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/EXIT_FAILURE.c b/src/stdlib/EXIT_FAILURE.c new file mode 100644 index 00000000..4558c660 --- /dev/null +++ b/src/stdlib/EXIT_FAILURE.c @@ -0,0 +1,15 @@ +#include <stdlib.h> + +/** unsuccessful program termination **/ + +#define EXIT_FAILURE (1) + +/*** +is used as the ARGUMENT(status) argument to FUNCTION(exit) or FUNCTION(_Exit), +or the return value from FUNCTION(main), to indicate that the program is +exiting unsuccessfully. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdlib/EXIT_SUCCESS.c b/src/stdlib/EXIT_SUCCESS.c new file mode 100644 index 00000000..ce2ed9df --- /dev/null +++ b/src/stdlib/EXIT_SUCCESS.c @@ -0,0 +1,15 @@ +#include <stdlib.h> + +/** successful program termination **/ + +#define EXIT_SUCCESS (0) + +/*** +is used as the ARGUMENT(status) argument to FUNCTION(exit) or FUNCTION(_Exit), +or the return value from FUNCTION(main), to indicate that the program is +exiting successfully. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdlib/MB_CUR_MAX.c b/src/stdlib/MB_CUR_MAX.c new file mode 100644 index 00000000..4961e343 --- /dev/null +++ b/src/stdlib/MB_CUR_MAX.c @@ -0,0 +1,15 @@ +#include <stdlib.h> + +/** current longest multibyte character **/ + +#define MB_CUR_MAX (4) + +/*** +is the maximum number of bytes required to store any character in the current +multibyte character set as specified by CONSTANT(LC_CTYPE). +***/ + +/* +VALUE_MAX(CONSTANT(MB_LEN_MAX)) +STDC(1) +*/ diff --git a/src/stdlib/NULL.ref b/src/stdlib/NULL.ref new file mode 100644 index 00000000..87e994d4 --- /dev/null +++ b/src/stdlib/NULL.ref @@ -0,0 +1,3 @@ +#include <stdlib.h> +REFERENCE(stddef/NULL.c) +STDC(1) diff --git a/src/stdlib/RAND_MAX.c b/src/stdlib/RAND_MAX.c new file mode 100644 index 00000000..dbbdbde0 --- /dev/null +++ b/src/stdlib/RAND_MAX.c @@ -0,0 +1,14 @@ +#include <stdlib.h> + +/** random number range **/ + +#define RAND_MAX (32767) + +/*** +is the maximum value returned by FUNCTION(rand). +***/ + +/* +VALUE_MIN(32767) +STDC(1) +*/ diff --git a/src/stdlib/_Exit.c b/src/stdlib/_Exit.c new file mode 100644 index 00000000..a90d4a24 --- /dev/null +++ b/src/stdlib/_Exit.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include "nonstd/syscall.h" + +/** cause normal program termination without handlers **/ +_Noreturn void _Exit(int status) +{ + __syscall("_exit", status); + for (;;); +} + +/*** +The fn(exit) function causes the program to terminate normally, returning the +value arg(status) to the host environment. + +No functions registered by fn(atexit) or fn(at_quick_exit) are called. +***/ + +/* UNSPECIFIED: - */ +/* UNDEFINED: - */ +/* IMPLEMENTATION: the successful termination value returned to the host environment when arg(status) is 0 of macro(EXIT_SUCESS) */ +/* IMPLEMENTATION: the unsuccessful termination value returned to the host environment when arg(status) is macro(EXIT_FAILURE) */ +/* IMPLEMENTATION: whether open streams are flushed */ +/* IMPLEMENTATION: whether open streams are closed */ +/* IMPLEMENTATION: whether temporary files are removed */ +/* LOCALE: - */ + +/* +STDC(199901) +*/ diff --git a/src/stdlib/abort.c b/src/stdlib/abort.c new file mode 100644 index 00000000..d079bdf1 --- /dev/null +++ b/src/stdlib/abort.c @@ -0,0 +1,27 @@ +#include <stdlib.h> +#ifdef _POSIX_SOURCE +#include "sys/types.h" +#endif +#include "signal.h" + +/** cause abnormal program termination **/ + +_Noreturn void abort(void) +{ + raise(SIGABRT); + for(;;); /* silence gcc warning about returning */ +} + +/*** +causes the program to terminate abnormally, unless the +signal CONSTANT(SIGABRT) is caught and the signal handler continues program +execution. +***/ + +/* +IMPLEMENTATION(whether open output streams are flushed) +IMPLEMENTATION(whether open streams are closed) +IMPLEMENTATION(whether temporary files are removed) +IMPLEMENTATION(the value of unsuccessful termination returned to the host environment) +STDC(1) +*/ diff --git a/src/stdlib/abs.c b/src/stdlib/abs.c new file mode 100644 index 00000000..9bc6ca28 --- /dev/null +++ b/src/stdlib/abs.c @@ -0,0 +1,23 @@ +#include <stdlib.h> +#include "limits.h" + +/** absolute value **/ + +int abs(int j) +{ + if (j == INT_MIN) { + /* undefined behavior */ + } + + return j < 0 ? -j : j; +} + +/*** +computes the absolute value of ARGUMENT(j). +***/ + +/* +UNDEFINED(ABS(ARGUMENT(j)) cannot be represented) +RETURN_SUCCESS(ABS(j)); +STDC(1) +*/ diff --git a/src/stdlib/atexit.c b/src/stdlib/atexit.c new file mode 100644 index 00000000..180dc5e2 --- /dev/null +++ b/src/stdlib/atexit.c @@ -0,0 +1,38 @@ +#include <stdlib.h> +#include "errno.h" +#include "nonstd/internal.h" + +/** register a function to run at program exit **/ + +int atexit(void (*func)(void)) +{ + struct atexit *ae = __libc(ATEXIT); + while (ae->nfns == sizeof(ae->fns) / sizeof(ae->fns[0])) { + if (ae->next == NULL) { + ae->next = calloc(1, sizeof(*ae->next)); + if (ae->next == NULL) { + #ifdef ENOMEM + errno = ENOMEM; + #endif + return 1; + } + ae->next->prev = ae; + } + ae = ae->next; + } + ae->fns[ae->nfns++] = func; + return 0; +} + +/*** +registers the function ARGUMENT(func) to be called when the program +exits normally by calling FUNCTION(exit) or returning from FUNCTION(main). The +function must take no parameters and return no value. +***/ + +/* +IMPLEMENTATION(The number of registrations allowed (at least 32)) +RETURN_FAILURE(NONZERO) +RETURN_SUCCESS(0) +STDC(1) +*/ diff --git a/src/stdlib/atof.c b/src/stdlib/atof.c new file mode 100644 index 00000000..c8fd2344 --- /dev/null +++ b/src/stdlib/atof.c @@ -0,0 +1,19 @@ +#include <stdlib.h> + +/** convert string to floating-point **/ + +double atof(const char * nptr) +{ + return strtod(nptr, (char**)NULL); +} + +/*** +converts the string at ARGUMENT(nptr) to a TYPE(double). The +conversion goes until the first inappropriate character. +***/ + +/* +LC_CTYPE +RETURN_SUCCESS(the converted value) +STDC(1) +*/ diff --git a/src/stdlib/atoi.c b/src/stdlib/atoi.c new file mode 100644 index 00000000..6e58dd22 --- /dev/null +++ b/src/stdlib/atoi.c @@ -0,0 +1,19 @@ +#include <stdlib.h> + +/** convert string to integer **/ + +int atoi(const char * nptr) +{ + return (int)strtol(nptr, (char**)NULL, 10); +} + +/*** +converts the string at ARGUMENT(nptr) to an TYPE(int) value, +using base 10. The conversion goes until the first non-digit character. +***/ + +/* +LC_CTYPE +RETURN_SUCCESS(the converted value) +STDC(1) +*/ diff --git a/src/stdlib/atol.c b/src/stdlib/atol.c new file mode 100644 index 00000000..6bcebf7d --- /dev/null +++ b/src/stdlib/atol.c @@ -0,0 +1,19 @@ +#include <stdlib.h> + +/** convert string to long integer **/ + +long int atol(const char * nptr) +{ + return strtol(nptr, (char**)NULL, 10); +} + +/*** +converts the string at ARGUMENT(nptr) to a TYPE(long int) value, +using base 10. The conversion goes until the first non-digit character. +***/ + +/* +LC_CTYPE +RETURN_SUCCESS(the converted value) +STDC(1) +*/ diff --git a/src/stdlib/atoll.c b/src/stdlib/atoll.c new file mode 100644 index 00000000..bc098876 --- /dev/null +++ b/src/stdlib/atoll.c @@ -0,0 +1,10 @@ +#include <stdlib.h> + +long long int atoll(const char *nptr) +{ + return strtoll(str, (char**)NULL, 10); +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/bsearch.c b/src/stdlib/bsearch.c new file mode 100644 index 00000000..d625599f --- /dev/null +++ b/src/stdlib/bsearch.c @@ -0,0 +1,44 @@ +#include <stdlib.h> + +/** binary search **/ + +void * bsearch(const void * key, const void * base, size_t nmemb, size_t size, int (*compar)(const void *, const void*)) +{ + /* TODO: testing */ + void *ret = NULL; + size_t i = nmemb / 2; + unsigned int trip = 1; + (void)size; + + while (ret == NULL) { + int comp = compar(key, base + i); + if (comp == 0) { + return (void*)(base + i); + } else if (comp > 0) { + i -= (nmemb >> trip); + } else { + i += (nmemb >> trip); + } + } + return NULL; +} + +/*** +performs a binary search for ARGUMENT(key) in the array +ARGUMENT(base), which contains ARGUMENT(nmemb) members of ARGUMENT(size) bytes +each. + +The search is performed by calling ARGUMENT(compar) with the first argument of +ARGUMENT(key), and the second being an element from the array at +ARGUMENT(base). The function must return less than 0 if ARGUMENT(key) is less +than the other element, 0 if they are equal, and greater than 0 if +ARGUMENT(key) is greater than the other element. +***/ + +/* +UNSPECIFIED(Which element is matched if two elements are equal) +UNDEFINED(The array at ARGUMENT(base) is not sorted) +RETURN_FAILURE(CONSTANT(NULL)) +RETURN_SUCCESS(a pointer to the matching element) +STDC(1) +*/ diff --git a/src/stdlib/calloc.c b/src/stdlib/calloc.c new file mode 100644 index 00000000..aeed4aef --- /dev/null +++ b/src/stdlib/calloc.c @@ -0,0 +1,33 @@ +#include <stdlib.h> +#include "string.h" + +/** allocate and initialize memory **/ + +void * calloc(size_t nmemb, size_t size) +{ + void *p = NULL; + + if (nmemb == 0 || size == 0) { + return NULL; + } + + p = realloc(NULL, size * nmemb); + if (p != NULL) { + memset(p, 0, size * nmemb); + } + + return p; +} + +/*** +allocates an array of ARGUMENT(nmemb) elements, each of which +are ARGUMENT(size) bytes, and sets all their bits to 0. +***/ + +/* +UNSPECIFIED(The order and contiguity of space allocated by success calls) +IMPLEMENTATION(What is returned if ARGUMENT(nmemb) or ARGUMENT(size) is 0) +RETURN_FAILURE(CONSTANT(NULL)) +RETURN_SUCCESS(a pointer to the newly allocated memory) +STDC(1) +*/ diff --git a/src/stdlib/div.c b/src/stdlib/div.c new file mode 100644 index 00000000..dfd80652 --- /dev/null +++ b/src/stdlib/div.c @@ -0,0 +1,22 @@ +#include <stdlib.h> + +/** calculate quotient and remainder **/ + +div_t div(int numer, int denom) +{ + div_t d; + d.quot = numer / denom; + d.rem = numer % denom; + return d; +} + +/*** +computes both the quotient and remainder of ARGUMENT(numer) +divided by ARGUMENT(denom). +***/ + +/* +UNDEFINED(The result cannot be represented) +RETURN_SUCCESS(a TYPEDEF(div_t) containing both the quotient and remainder) +STDC(1) +*/ diff --git a/src/stdlib/div_t.c b/src/stdlib/div_t.c new file mode 100644 index 00000000..60acd660 --- /dev/null +++ b/src/stdlib/div_t.c @@ -0,0 +1,17 @@ +#include <stdlib.h> + +/** quotient and remainder **/ + +typedef struct { + int quot; + int rem; +} div_t; + +/*** +is the type returned by FUNCTION(div) to hold both the quotient and remainder +of an integer division. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c new file mode 100644 index 00000000..b0ba271d --- /dev/null +++ b/src/stdlib/exit.c @@ -0,0 +1,51 @@ +#include <stdlib.h> +#include "limits.h" +#include "stddef.h" +#include "nonstd/internal.h" +#include "nonstd/syscall.h" + +/** cause normal program termination **/ +_Noreturn void exit(int status) +{ + struct atexit *ae = __libc(ATEXIT); + + /* execute all atexit() registered functions in reverse order */ + while (ae) { + int i = ae->nfns; + while (i > 0) { + ae->fns[--i](); + } + ae = ae->prev; + } + + /* close all open files */ + /* + while (__libc.stdio.lastfile) { + fclose(__libc.stdio.lastfile); + } + */ + + (void)status; + /* __syscall(__libc(SYSCALL_LOOKUP)("exit"), status); */ + for (;;); /* quiet _Noreturn functions returns warning */ +} + +/*** +causes the program to terminate normally, returning the +value ARGUMENT(status) to the host environment. + +First, all functions registered by FUNCTION(atexit) are called in the reverse +order in which they were registered. + +Then, all open streams with unwritten buffered data are flushed. All open +streams are closed. All temporary files created by FUNCTION(tmpfile) are +removed. +***/ + +/* +IMPLEMENTATION(The successful termination value returned to the host environment when ARGUMENT(status) is 0 or CONSTANT(EXIT_SUCESS)) +IMPLEMENTATION(The unsuccessful termination value returned to the host environment when ARGUMENT(status) is CONSTANT(EXIT_FAILURE)) +*/ +/* +STDC(1) +*/ diff --git a/src/stdlib/free.c b/src/stdlib/free.c new file mode 100644 index 00000000..55a98a2f --- /dev/null +++ b/src/stdlib/free.c @@ -0,0 +1,22 @@ +#include <stdlib.h> + +/** deallocate memory **/ + +void free(void * ptr) +{ + if (ptr == NULL) { + return; + } + + realloc(ptr, 0); +} + +/*** +deallocates the memory at ARGUMENT(ptr). Specifying CONSTANT(NULL) +causes nothing to happen. +***/ + +/* +UNDEFINED(ARGUMENT(ptr) was not returned by a previous call to FUNCTION(calloc), FUNCTION(malloc), or FUNCTION(realloc)) +STDC(1) +*/ diff --git a/src/stdlib/getenv.c b/src/stdlib/getenv.c new file mode 100644 index 00000000..edf5c4f9 --- /dev/null +++ b/src/stdlib/getenv.c @@ -0,0 +1,31 @@ +#include <stdlib.h> +#include "string.h" + +/** get an environment variable **/ + +char * getenv(const char * name) +{ + extern char **environ; + int i = 0; + + while (environ[i] != 0) { + if (!strncmp(environ[i], name, strlen(name)) && environ[i][strlen(name)] == '=') + return environ[i]; + i++; + } + + return NULL; +} + +/*** +read the environment variable ARGUMENT(name) from the host environment. +***/ + +/* +UNDEFINED(Modifying the returned string) +IMPLEMENTATION(The set of environment variable names) +IMPLEMENTATION(The method of altering the environment) +RETURN_FAILURE(CONSTANT(NULL)) +RETURN_SUCCESS(a pointer to the environment string) +STDC(1) +*/ diff --git a/src/stdlib/labs.c b/src/stdlib/labs.c new file mode 100644 index 00000000..fd092f5a --- /dev/null +++ b/src/stdlib/labs.c @@ -0,0 +1,22 @@ +#include <stdlib.h> +#include "limits.h" + +/** absolute value **/ +long int labs(long int j) +{ + if (j == LONG_MIN) { + /* undefined */ + } + + return j < 0 ? -j : j; +} + +/*** +function computes the absolute value of ARGUMENT(j). +***/ + +/* +UNDEFINED(ABS(ARGUMENT(j)) cannot be represented) +RETURN_SUCCESS(ABS(ARGUMENT(j))) +STDC(1) +*/ diff --git a/src/stdlib/ldiv.c b/src/stdlib/ldiv.c new file mode 100644 index 00000000..0aebaf49 --- /dev/null +++ b/src/stdlib/ldiv.c @@ -0,0 +1,22 @@ +#include <stdlib.h> + +/** calculate quotient and remainder **/ + +ldiv_t ldiv(long int numer, long int denom) +{ + ldiv_t d; + d.quot = numer / denom; + d.rem = numer % denom; + return d; +} + +/*** +computes both the quotient and remainder of ARGUMENT(numer) +divided by ARGUMENT(denom). +***/ + +/* +UNDEFINED(The result cannot be represented) +RETURN_SUCCESS(a TYPEDEF(ldiv_t) containing both the quotient and remainder) +STDC(1) +*/ diff --git a/src/stdlib/ldiv_t.c b/src/stdlib/ldiv_t.c new file mode 100644 index 00000000..00161cf6 --- /dev/null +++ b/src/stdlib/ldiv_t.c @@ -0,0 +1,17 @@ +#include <stdlib.h> + +/** long quotient and remainder **/ + +typedef struct { + long int quot; + long int rem; +} ldiv_t; + +/*** +is the type returned by FUNCTION(ldiv) to hold both the quotient and remainder +of an integer division. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdlib/llabs.c b/src/stdlib/llabs.c new file mode 100644 index 00000000..2f474fe9 --- /dev/null +++ b/src/stdlib/llabs.c @@ -0,0 +1,18 @@ +#include <stdlib.h> + +long long int llabs(long long int j) +{ + if (j == LLONG_MIN) { + /* undefined */ + } + + if (j < 0) { + return -j; + } + + return j; +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/lldiv.c b/src/stdlib/lldiv.c new file mode 100644 index 00000000..f4835ec2 --- /dev/null +++ b/src/stdlib/lldiv.c @@ -0,0 +1,13 @@ +#include <stdlib.h> + +lldiv_t lldiv(long long int numer, long long int denom) +{ + lldiv_t d; + d.quot = numer / denom; + d.rem = numer % denom; + return d; +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/lldiv_t.c b/src/stdlib/lldiv_t.c new file mode 100644 index 00000000..e7e72e6b --- /dev/null +++ b/src/stdlib/lldiv_t.c @@ -0,0 +1,10 @@ +#include <stdlib.h> + +typedef struct { + long long int quot; + long long int rem; +} lldiv_t; + +/* +STDC(199901) +*/ diff --git a/src/stdlib/malloc.c b/src/stdlib/malloc.c new file mode 100644 index 00000000..b2116fa7 --- /dev/null +++ b/src/stdlib/malloc.c @@ -0,0 +1,23 @@ +#include <stdlib.h> + +/** allocate memory **/ +void * malloc(size_t size) +{ + if (size == 0) { + return NULL; + } + + return realloc(NULL, size); +} + +/*** +allocates ARGUMENT(size) bytes of memory. +***/ + +/* +UNSPECIFIED(The order and contiguity of space allocated by success calls) +IMPLEMENTATION(What is returned if ARGUMENT(size) is 0) +RETURN_FAILURE(CONSTANT(NULL)) +RETURN_SUCCESS(a pointer to the allocated space) +STDC(1) +*/ diff --git a/src/stdlib/mblen.c b/src/stdlib/mblen.c new file mode 100644 index 00000000..db7c4f1c --- /dev/null +++ b/src/stdlib/mblen.c @@ -0,0 +1,33 @@ +#include <stdlib.h> + +/** count bytes in multibyte character **/ +int mblen(const char * s, size_t n) +{ + /* FIXME: forward dependency on AMD1 */ + #if 0 + mbstate_t ps = 0; + return mbrlen(s, n, &ps); + #else + (void)s; (void)n; + return 0; + #endif +} + +/*** +counts the number of bytes in the multibyte character +starting at ARGUMENT(s), if the next ARGUMENT(n) or fewer bytes contain a full multibyte +character. + +If ARGUMENT(s) is CONSTANT(NULL), THIS() tests whether multibyte encodings carry +state dependency. +***/ + +/* +LC_CTYPE +RETURN(0, If ARGUMENT(s) is CONSTANT(NULL), multibyte encodings do not have state dependencies); +RETURN(NZ, If ARGUMENT(s) is CONSTANT(NULL), multibyte encodings do have state dependencies); +RETURN(-1, The ARGUMENT(n) bytes at ARGUMENT(s) do not form a valid mutlibyte character); +RETURN(0, ARGUMENT(s) points to a null character); +RETURN(TYPE(int), the number of bytes in the multibyte character); +STDC(1) +*/ diff --git a/src/stdlib/mbstowcs.c b/src/stdlib/mbstowcs.c new file mode 100644 index 00000000..a5ce53d8 --- /dev/null +++ b/src/stdlib/mbstowcs.c @@ -0,0 +1,30 @@ +#include <stdlib.h> + +/** convert multibyte string to wide character string **/ + +size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n) +{ + /* FIXME: forward dependency on AMD1 */ + #if 0 + mbstate_t ps = 0; + return mbsrtowcs(pwcs, s, n, &ps); + #else + (void)pwcs; (void)s; + return n; + #endif +} + +/*** +converts the string of multibyte characters ARGUMENT(s) +to a string of wide characters, which are stored at ARGUMENT(pwcs). No more than +ARGUMENT(n) wide characters are stored at ARGUMENT(pwcs). No further +characters will be converted after a null character, which is converted. +***/ + +/* +UNDEFINED(The memory regions of ARGUMENT(s) and ARGUMENT(pwcs) overlap) +LC_CTYPE +RETURN_FAILURE(-1) +RETURN_SUCCESS(the number of wide characters converted, not counting any terminating zero) +STDC(1) +*/ diff --git a/src/stdlib/mbtowc.c b/src/stdlib/mbtowc.c new file mode 100644 index 00000000..3704acd4 --- /dev/null +++ b/src/stdlib/mbtowc.c @@ -0,0 +1,37 @@ +#include <stdlib.h> + +/** convert a multibyte character to a wide character **/ + +int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n) +{ + /* FIXME: forward dependency on AMD1 */ + #if 0 + static mbstate_t ps = 0; + return mbrtowc(pwc, s, n, &ps); + #else + (void)pwc; (void)s; (void)n; + return 0; + #endif +} + +/*** +converts the multibyte character, of no more than ARGUMENT(n) bytes, at +ARGUMENT(s) to a wide character, which is stored at the address pointed to by +ARGUMENT(pwc). + +If ARGUMENT(s) is CONSTANT(NULL), THIS() tests whether multibyte encodings carry +state dependency. + +If ARGUMENT(pwc) is CONSTANT(NULL), THIS() counts the number of bytes in the +multibyte character at ARGUMENT(s). +***/ + +/* +LC_CTYPE +RETURN(0, If ARGUMENT(s) is CONSTANT(NULL), multibyte encodings do not have state dependencies) +RETURN(NONZERO, If ARGUMENT(s) is CONSTANT(NULL), multibyte encodings do have state dependencies) +RETURN(-1, The ARGUMENT(n) bytes at ARGUMENT(s) do not form a valid mutlibyte character) +RETURN(0, ARGUMENT(s) points to a null character) +RETURN(TYPE(int), the number of bytes in the converted multibyte character) +STDC(1) +*/ diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c new file mode 100644 index 00000000..da4c5c15 --- /dev/null +++ b/src/stdlib/qsort.c @@ -0,0 +1,24 @@ +#include <stdlib.h> + +/** sort an array **/ + +void qsort(void * base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) +{ + (void)base; (void)nmemb; (void)size; (void)compar; + /* TODO */ +} + +/*** +sorts the array at ARGUMENT(base), which consists of ARGUMENT(nmemb) elements +of ARGUMENT(size) bytes each. + +The sorting is performed by calling ARGUMENT(compar) with two elements of the +array. The function must return less than 0 if the first argument is less +than the second, 0 if they are equal, and greater than 0 if the first argument +is greater than the second. +***/ + +/* +UNSPECIFIED(The order of equal elements) +STDC(1) +*/ diff --git a/src/stdlib/rand.c b/src/stdlib/rand.c new file mode 100644 index 00000000..bd561736 --- /dev/null +++ b/src/stdlib/rand.c @@ -0,0 +1,19 @@ +#include <stdlib.h> +#include "nonstd/internal.h" + +/** get a pseudo-random number **/ +int rand(void) +{ + /* FIXME: forward dependency on POSIX.1c-1995 */ + extern int rand_r(unsigned int*); + return rand_r(__libc(RAND)); +} + +/*** +computes a pseudo-random number in the range [0,CONSTANT(RAND_MAX)]. +***/ + +/* +RETURN_SUCCESS(a pseudo-random integer) +STDC(1) +*/ diff --git a/src/stdlib/realloc.c b/src/stdlib/realloc.c new file mode 100644 index 00000000..f16ba8a5 --- /dev/null +++ b/src/stdlib/realloc.c @@ -0,0 +1,58 @@ +#include <stdlib.h> +#if defined _POSIX_C_SOURCE && 199305L <= _POSIX_C_SOURCE +#include "sys/types.h" +#include "fcntl.h" +#include "sys/mman.h" +#endif + +/** change the amount of memory allocated **/ + +void * realloc(void * ptr, size_t size) +{ +#if defined _POSIX_C_SOURCE && 199305L <= _POSIX_C_SOURCE + /* FIXME: forward dependency on POSIX.1b-1993, non-std /dev/zero */ + static int backing = -1; + + if (backing == -1) { + backing = open("/dev/zero", O_RDWR /* | O_CLOEXEC */, 0); + } + + if (ptr == NULL) { + /* malloc() */ + return (void*)(long)mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_PRIVATE, backing, 0); + } else if (size == 0) { + /* free() */ + } + + /* TODO: reallocate */ +#else + (void)size; +#endif + + return ptr; +} + +/*** +changes the amount of memory allocated to ARGUMENT(ptr) to ARGUMENT(size) +bytes. + +If ARGUMENT(ptr) is CONSTANT(NULL), a new allocation is made. + +If ARGUMENT(size) is 0 and ARGUMENT(ptr) is not CONSTANT(NULL), the memory at ARGUMENT(ptr) is +deallocated. + +Otherwise, the memory allocated to ARGUMENT(ptr) is resized. If enough memory cannot +be allocated, ARGUMENT(ptr) will not change. If enough memory is available, the +address of ARGUMENT(ptr) may change, but the contents will be the same up to the +minimum of the old and new sizes. +***/ + +/* +UNSPECIFIED(The order and contiguity of space allocated by success calls) +UNDEFINED(ARGUMENT(ptr) is not CONSTANT(NULL) or a pointer returned by a previous call to FUNCTION(calloc), FUNCTION(malloc), or FUNCTION(realloc)) +UNDEFINED(ARGUMENT(ptr) has been previously deallocated by FUNCTION(free) or FUNCTION(realloc)) +RETURN_FAILURE(CONSTANT(NULL)) +RETURN_SUCCESS(a pointer to the reallocate space) +STDC(1) +*/ diff --git a/src/stdlib/size_t.ref b/src/stdlib/size_t.ref new file mode 100644 index 00000000..e525842a --- /dev/null +++ b/src/stdlib/size_t.ref @@ -0,0 +1,3 @@ +#include <stdlib.h> +REFERENCE(stddef/size_t.c) +STDC(1) diff --git a/src/stdlib/srand.c b/src/stdlib/srand.c new file mode 100644 index 00000000..66ce786e --- /dev/null +++ b/src/stdlib/srand.c @@ -0,0 +1,19 @@ +#include <stdlib.h> +#include "nonstd/internal.h" + +/** seed the pseudo-random number generator **/ + +void srand(unsigned int seed) +{ + *((int*)__libc(RAND)) = seed; +} + +/*** +seeds the pseudo-random number generator with ARGUMENT(seed). The +sequence of pseudo-random numbers generated by a single seed is repeatable. +Program execution begins with a seed of 1. +***/ + +/* +STDC(1) +*/ diff --git a/src/stdlib/strtod.c b/src/stdlib/strtod.c new file mode 100644 index 00000000..4420b02e --- /dev/null +++ b/src/stdlib/strtod.c @@ -0,0 +1,37 @@ +#include <stdlib.h> +#include "errno.h" + +/** convert string to floating-point **/ + +double strtod(const char * restrict nptr, char ** restrict endptr) +{ + (void)nptr; (void)endptr; + /* TODO */ + + if (0) { + errno = ERANGE; /* converted value out of range */ + } + + return 0.0; +} + +/*** +converts the string at ARGUMENT(nptr) to a TYPE(double). +Leading whitespace is ignored. The first character that is not a valid character +for a floating-point constant and any characters after it are also ignored. A +pointer to the first invalid character is stored in ARGUMENT(endptr), unless +ARGUMENT(endptr) is CONSTANT(NULL). + +The converted portion of the string may start with an optional plus or minus +sign, followed by a nonempty series of digits, optionally containing a +decimal-point character. This may optionally be followed by an exponent. +***/ + +/* +LC_CTYPE +RETURN(ZERO, underflow or no conversion could be performed) +RETURN(CONSTANT(HUGE_VAL), converted value too large) +RETURN(CONSTANT(-HUGE_VAL), converted value too small) +RETURN(VAR(a TYPE(double)), the converted value) +STDC(1) +*/ diff --git a/src/stdlib/strtof.c b/src/stdlib/strtof.c new file mode 100644 index 00000000..b3da169c --- /dev/null +++ b/src/stdlib/strtof.c @@ -0,0 +1,9 @@ +#include <stdlib.h> + +float strtof(const char * restrict nptr, char ** restrict endptr) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/strtol.c b/src/stdlib/strtol.c new file mode 100644 index 00000000..247ac5de --- /dev/null +++ b/src/stdlib/strtol.c @@ -0,0 +1,60 @@ +#include <stdlib.h> +#include "limits.h" +#include "errno.h" + +#if defined __STDC_VERSION__ && 199912L <= __STDC_VERSION__ +#include "inttypes.h" +#else +typedef long intmax_t; +#define strtoimax(n, e, b) ((long)n & (long)e & (long)b) ? 0 : 0 +#endif + +/** convert string to long integer **/ + +long int strtol(const char * restrict nptr, char ** restrict endptr, int base) +{ + /* FIXME: forward dependency on 9899-1999 */ + intmax_t ret = strtoimax(nptr, endptr, base); + + if (ret < LONG_MIN) { + ret = LONG_MIN; + errno = ERANGE; /* converted value out of range */ + } + + if (ret > LONG_MAX) { + ret = LONG_MAX; + errno = ERANGE; /* converted value out of range */ + } + + return (long int)ret; +} + +/*** +converts the string at ARGUMENT(nptr) to a TYPE(long int). +Leading whitespace is ignored. The first character that is not a valid character +for a integer constant and any characters after it are also ignored. A pointer +to the first invalid character is stored in ARGUMENT(endptr), unless +ARGUMENT(endptr) is CONSTANT(NULL). + +The conversion is conducted in the base specified by ARGUMENT(base). +Specifying 0 for ARGUMENT(base) will check the first few characters of +ARGUMENT(nptr) to determine the conversion base. If it begins with LITERAL(0x) +or LITERAL(0X), a base of 16 will be used. Otherwise, if it begins with +CHAR(0), base 8 will be used. If neither of those occur, base 10 will be used. + +If ARGUMENT(base) is specified, it must be in the range [2,36]. For bases +larger than 10, the letters CHAR(a) through CHAR(z) and their uppercase +conversions are assigned the values 10 through 35. Base 16 numbers may be +preceded by LITERAL(0x) or LITERAL(0X). + +The numeric string consists of an optional leading plus or minus followed by +digits in the appropriate base. +***/ + +/* +RETURN(ZERO, no conversion could be performed) +RETURN(CONSTANT(LONG_MAX), converted value too large) +RETURN(CONSTANT(LONG_MIN), converted value too small) +RETURN(a TYPE(long int) value, the converted value) +STDC(1) +*/ diff --git a/src/stdlib/strtold.c b/src/stdlib/strtold.c new file mode 100644 index 00000000..185f359e --- /dev/null +++ b/src/stdlib/strtold.c @@ -0,0 +1,9 @@ +#include <stdlib.h> + +long double strtold(const char * restrict nptr, char ** restrict endptr) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/strtoll.c b/src/stdlib/strtoll.c new file mode 100644 index 00000000..2f40229c --- /dev/null +++ b/src/stdlib/strtoll.c @@ -0,0 +1,15 @@ +#include <stdlib.h> + +long long int strtoll(const char * restrict nptr, char ** restrict endptr, int base) +{ + intmax_t ret = strtoimax(nptr, endptr, base); + if (ret < LLONG_MIN) { + } + if (ret > LLONG_MAX) { + } + return (long long int)ret; +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/strtoul.c b/src/stdlib/strtoul.c new file mode 100644 index 00000000..9a00910b --- /dev/null +++ b/src/stdlib/strtoul.c @@ -0,0 +1,53 @@ +#include <stdlib.h> +#include "errno.h" +#include "limits.h" + +#if defined __STDC_VERSION__ && 199912L <= __STDC_VERSION__ +#include "inttypes.h" +#else +typedef unsigned long uintmax_t; +#define strtoumax(n, e, b) ((long)n & (long)e & (long)b ? 0 : 0) +#endif + +/** convert string to unsigned long integer **/ +unsigned long int strtoul(const char * nptr, char ** endptr, int base) +{ + /* FIXME: forward dependency on 9899-1999 */ + uintmax_t ret = strtoumax(nptr, endptr, base); + + if (ret > ULONG_MAX) { + ret = ULONG_MAX; + errno = ERANGE; /* converted value too large */ + } + + return (unsigned long int)ret; +} + +/*** +converts the string at ARGUMENT(nptr) to a +type(unsigned long int). Leading whitespace is ignored. The first character +that is not a valid character for a integer constant and any characters after +it are also ignored. A pointer to the first invalid character is stored in +ARGUMENT(endptr), unless ARGUMENT(endptr) is CONSTANT(NULL). + +The conversion is conducted in the base specified by ARGUMENT(base). +Specifying 0 for ARGUMENT(base) will check the first few characters of +ARGUMENT(nptr) to determine the conversion base. If it begins with LITERAL(0x) +or LITERAL(0X), a base of 16 will be used. Otherwise, if it begins with +CHAR(0), base 8 will be used. If neither of those occur, base 10 will be used. + +If ARGUMENT(base) is specified, it must be in the range [2,36]. For bases +larger than 10, the letters CHAR(a) through CHAR(z) and their uppercase +conversions are assigned the values 10 through 35. Base 16 numbers may be +preceded by LITERAL(0x) or LITERAL(0X). + +The numeric string consists of an optional leading plus or minus followed by +digits in the appropriate base. +***/ + +/* +RETURN(ZERO, no conversion could be performed) +RETURN(ULONG_MAX, converted value too large) +RETURN(an TYPE(unsigned long int) value, the converted value) +STDC(1) +*/ diff --git a/src/stdlib/strtoull.c b/src/stdlib/strtoull.c new file mode 100644 index 00000000..c95bac77 --- /dev/null +++ b/src/stdlib/strtoull.c @@ -0,0 +1,13 @@ +#include <stdlib.h> + +unsigned long long int strtoull(const char * restrict nptr, char ** restrict endptr, int base) +{ + uintmax_t ret = strtoumax(nptr, endptr, base); + if (ret > ULLONG_MAX) { + } + return (unsigned long long int)ret; +} + +/* +STDC(199901) +*/ diff --git a/src/stdlib/system.c b/src/stdlib/system.c new file mode 100644 index 00000000..ac0d54d5 --- /dev/null +++ b/src/stdlib/system.c @@ -0,0 +1,61 @@ +#include <stdlib.h> + +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE +# include "errno.h" +# include "sys/types.h" +# include "unistd.h" +# include "sys/wait.h" +# define USE_FORK +#endif + +/** execute a command **/ + +int system(const char * string) +{ + #if defined USE_FORK + pid_t pid; + int status; + + if (string == NULL) { + return 0; + } + + pid = fork(); + if (pid < 0) { + /* errno comes from fork() */ + return -1; + } + + if (pid == 0) { + execl("/bin/sh", "sh", "-c", string, (char *)0); + _exit(1); + } + + if (waitpid(pid, &status, 0) == -1) { + errno = ECHILD; + return -1; + } + + return status; + + #else + (void)string; + return 1; + #endif +} + +/*** +runs the command ARGUMENT(string) using the host environment's command +processor. + +Specifying CONSTANT(NULL) for ARGUMENT(string) tests whether a command +processor is available. +***/ + +/* +IMPLEMENTATION(How the command processor is invoked) +IMPLEMENTATION(The return value when ARGUMENT(string) is not CONSTANT(NULL)) +RETURN(NONZERO, If ARGUMENT(string) is CONSTANT(NULL), a command processor is available) +RETURN(0, If ARGUMENT(string) is CONSTANT(NULL), a command processor is not available) +STDC(1) +*/ diff --git a/src/stdlib/wchar_t.ref b/src/stdlib/wchar_t.ref new file mode 100644 index 00000000..d551680b --- /dev/null +++ b/src/stdlib/wchar_t.ref @@ -0,0 +1,3 @@ +#include <stdlib.h> +REFERENCE(stddef/wchar_t.c) +STDC(1) diff --git a/src/stdlib/wcstombs.c b/src/stdlib/wcstombs.c new file mode 100644 index 00000000..3643a5a4 --- /dev/null +++ b/src/stdlib/wcstombs.c @@ -0,0 +1,25 @@ +#include <stdlib.h> + +/** convert wide character string to multibyte string **/ + +size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n) +{ + (void)s; (void)pwcs; (void)n; + /* TODO */ + return 0; +} + +/*** +converts the wide character string ARGUMENT(pwcs) to a multibyte string, which +is stored at ARGUMENT(s), beginning in the initial shift state. No more than +ARGUMENT(n) bytes are written to ARGUMENT(s). Conversion stops after reaching +a null wide character, which is converted and stored. +***/ + +/* +UNDEFINED(The memory regions of ARGUMENT(s) and ARGUMENT(pwcs) overlap) +LC_CTYPE +RETURN_FAILURE(-1) +RETURN_SUCCESS(the number of bytes modified, not counting any terminating null) +STDC(1) +*/ diff --git a/src/stdlib/wctomb.c b/src/stdlib/wctomb.c new file mode 100644 index 00000000..a2928a8b --- /dev/null +++ b/src/stdlib/wctomb.c @@ -0,0 +1,33 @@ +#include <stdlib.h> + +/** convert wide character to multibyte character **/ + +int wctomb(char * s, wchar_t wchar) +{ + /* FIXME: forward dependency on AMD1 */ + #if 0 + static mbstate_t ps = 0; + return wcrtomb(s, wchar, &ps); + #else + (void)s; (void)wchar; + return 0; + #endif +} + +/*** +converts the wide character ARGUMENT(wchar) to a multibyte character, which is +stored at the address ARGUMENT(s). At most CONSTANT(MB_CUR_MAX) bytes are +stored. + +If ARGUMENT(s) is CONSTANT(NULL), fn(wctomb) tests whether multibyte encodings +carry state dependency. +***/ + +/* +LC_CTYPE +RETURN(0, `If ARGUMENT(s) is CONSTANT(NULL), multibyte encodings do not have state dependencies') +RETURN(NONZERO, `If ARGUMENT(s) is CONSTANT(NULL), multibyte encodings do have state dependencies') +RETURN(-1, The value of ARGUMENT(wchar) does not correspond to a valid multibyte character) +RETURN(TYPE(int), The number of bytes contained in the multibyte character corresponding to ARGUMENT(wchar)) +STDC(1) +*/ diff --git a/src/string/NULL.ref b/src/string/NULL.ref new file mode 100644 index 00000000..5d6e9890 --- /dev/null +++ b/src/string/NULL.ref @@ -0,0 +1,3 @@ +#include <string.h> +REFERENCE(stddef/NULL.c) +STDC(1) diff --git a/src/string/memchr.c b/src/string/memchr.c new file mode 100644 index 00000000..97f6b257 --- /dev/null +++ b/src/string/memchr.c @@ -0,0 +1,31 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** search memory **/ +void * memchr(const void *s, int c, size_t n) +{ + char *p = (char*)s; + size_t i = 0; + + ASSERT_NONNULL(s); + + for (i = 0; i < n; i++) { + if (p[i] == (unsigned char)c) { + return p + i; + } + } + + /* + RETURN_FAILURE(CONSTANT(NULL)); + RETURN_SUCCESS(a pointer to the located byte); + */ + return NULL; +} + +/*** +searches the first ARGUMENT(n) bytes of memory at ARGUMENT(s) for +ARGUMENT(c) (converted to an TYPE(unsigned char)). +***/ +/* +STDC(1) +*/ diff --git a/src/string/memcmp.c b/src/string/memcmp.c new file mode 100644 index 00000000..64dcb464 --- /dev/null +++ b/src/string/memcmp.c @@ -0,0 +1,34 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** compare memory regions **/ +int memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *p = (unsigned char*)s1; + unsigned char *q = (unsigned char*)s2; + size_t i = 0; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + for (i = 0; i < n; i++) { + if (p[i] != q[i]) { + break; + } + } + + /* + RETURN(NEGATIVE, ARGUMENT(s1) is less than ARGUMENT(s2)); + RETURN(ZERO, ARGUMENT(s1) and ARGUMENT(s2) are equal); + RETURN(POSITIVE(), ARGUMENT(s1) is greater than ARGUMENT(s2)); + */ + return p[i] - q[i]; +} + +/*** +compares the first ARGUMENT(n) bytes of memory at ARGUMENT(s1) +and ARGUMENT(s2). +***/ +/* +STDC(1) +*/ diff --git a/src/string/memcpy.c b/src/string/memcpy.c new file mode 100644 index 00000000..f53fe5d8 --- /dev/null +++ b/src/string/memcpy.c @@ -0,0 +1,31 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** copy memory **/ +void * memcpy(void * restrict s1, const void * restrict s2, size_t n) +{ + char *dst = (char*)s1; + char *src = (char*)s2; + size_t i = 0; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + ASSERT_NOOVERLAP(s1, s2, n); + + for (i = 0; i < n; i++) { + dst[i] = src[i]; + } + + /* + RETURN_ALWAYS(ARGUMENT(s1)); + */ + return dst; +} + +/*** +copies ARGUMENT(n) bytes from the object at ARGUMENT(s2) to the object at +ARGUMENT(s1). +***/ +/* +STDC(1) +*/ diff --git a/src/string/memmove.c b/src/string/memmove.c new file mode 100644 index 00000000..33000e0e --- /dev/null +++ b/src/string/memmove.c @@ -0,0 +1,35 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** move memory **/ +void * memmove(void *s1, const void *s2, size_t n) +{ + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + if (s1 < s2) { + return memcpy(s1, s2, n); + } + + /* reverse memcpy() */ + while (n > 0) { + ((char*)s1)[n] = ((char*)s2)[n]; + n--; + } + /* last byte */ + ((char*)s1)[n] = ((char*)s2)[n]; + + /* + RETURN_ALWAYS(ARGUMENT(s1)); + */ + return s1; +} + +/*** +copies ARGUMENT(n) bytes of memory from the object at +ARGUMENT(s2) to the object at ARGUMENT(s1). If ARGUMENT(s1) and ARGUMENT(s2) overlap, the memory +is copied so that the ARGUMENT(n) bytes are safely written to ARGUMENT(s1). +***/ +/* +STDC(1) +*/ diff --git a/src/string/memset.c b/src/string/memset.c new file mode 100644 index 00000000..1f3d14ff --- /dev/null +++ b/src/string/memset.c @@ -0,0 +1,28 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** fill memory **/ +void * memset(void *s, int c, size_t n) +{ + unsigned char *p = (unsigned char *)s; + size_t i = 0; + + ASSERT_NONNULL(s); + + for (i = 0; i < n; i++) { + p[i] = (unsigned char)c; + } + + /* + RETURN_ALWAYS(ARGUMENT(s)); + */ + return s; +} + +/*** +fills the first ARGUMENT(n) bytes of memory at ARGUMENT(s) with +the value ARGUMENT(c) (converted to an TYPE(unsigned char)). +***/ +/* +STDC(1) +*/ diff --git a/src/string/size_t.ref b/src/string/size_t.ref new file mode 100644 index 00000000..3c087e0b --- /dev/null +++ b/src/string/size_t.ref @@ -0,0 +1,3 @@ +#include <string.h> +REFERENCE(stddef/size_t.c) +STDC(1) diff --git a/src/string/strcat.c b/src/string/strcat.c new file mode 100644 index 00000000..9526cd59 --- /dev/null +++ b/src/string/strcat.c @@ -0,0 +1,24 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** concatenate strings **/ +char * strcat(char * restrict s1, const char * restrict s2) +{ + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + ASSERT_NOOVERLAP(s1, s2, strlen(s1) + strlen(s2)); + + /* + RETURN_ALWAYS(ARGUMENT(s1)); + */ + return strncat(s1, s2, strlen(s2)); +} + +/*** +appends a copy of the string at ARGUMENT(s2) to the end of +the string at ARGUMENT(s1). The first byte of ARGUMENT(s2) will overwrite the terminating +null character of ARGUMENT(s1). +***/ +/* +STDC(1) +*/ diff --git a/src/string/strchr.c b/src/string/strchr.c new file mode 100644 index 00000000..874db9be --- /dev/null +++ b/src/string/strchr.c @@ -0,0 +1,22 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** string search **/ +char * strchr(const char *s, int c) +{ + ASSERT_NONNULL(s); + + /* + RETURN_FAILURE(CONSTANT(NULL)); + RETURN_SUCCESS(a pointer to the located character); + */ + return (char*)memchr(s, (char)c, strlen(s)); +} + +/*** +searches the string ARGUMENT(s) for the first occurrence of +ARGUMENT(c) (converted to a TYPE(char)). +***/ +/* +STDC(1) +*/ diff --git a/src/string/strcmp.c b/src/string/strcmp.c new file mode 100644 index 00000000..ed089c77 --- /dev/null +++ b/src/string/strcmp.c @@ -0,0 +1,29 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** compare strings **/ +int strcmp(const char *s1, const char *s2) +{ + size_t n1 = 0; + size_t n2 = 0; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + n1 = strlen(s1); + n2 = strlen(s2); + + /* + RETURN(NEGATIVE, ARGUMENT(s1) is less than ARGUMENT(s2)); + RETURN(ZERO, ARGUMENT(s1) is equal to ARGUMENT(s2)); + RETURN(POSITIVE, ARGUMENT(s1) is greater than ARGUMENT(s2)); + */ + return strncmp(s1, s2, n1 < n2 ? n1 : n2); +} + +/*** +compares the strings at ARGUMENT(s1) and ARGUMENT(s2). +***/ +/* +STDC(1) +*/ diff --git a/src/string/strcoll.c b/src/string/strcoll.c new file mode 100644 index 00000000..8707ba73 --- /dev/null +++ b/src/string/strcoll.c @@ -0,0 +1,44 @@ +#include <string.h> +#include "stdlib.h" +#include "nonstd/assert.h" + +/** collate strings **/ +int strcoll(const char *s1, const char *s2) +{ + char *x1 = NULL; + char *x2 = NULL; + int ret = 0; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + x1 = malloc(strxfrm(x1, s1, 0)); + x2 = malloc(strxfrm(x2, s2, 0)); + + if (x1 && x2) { + strxfrm(x1, s1, 0); + strxfrm(x2, s2, 0); + ret = strcmp(x1, x2); + } + + free(x1); + free(x2); + + /* + RETURN(NEGATIVE, ARGUMENT(s1) collates before ARGUMENT(s2)); + RETURN(ZERO, ARGUMENT(s1) collates equal to ARGUMENT(s2)); + RETURN(POSITIVE, ARGUMENT(s1) collates after ARGUMENT(s2)); + */ + return ret; +} + +/*** +compares the collation values of the strings at ARGUMENT(s1) and ARGUMENT(s2). +***/ + +/* +LC_COLLATE +*/ +/* +STDC(1) +*/ diff --git a/src/string/strcpy.c b/src/string/strcpy.c new file mode 100644 index 00000000..cf4eeb21 --- /dev/null +++ b/src/string/strcpy.c @@ -0,0 +1,29 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** copy string **/ +char * strcpy(char * restrict s1, const char * restrict s2) +{ + char *p = s1; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + ASSERT_NOOVERLAP(s1, s2, strlen(s2)); + + while ((*s1++ = *s2++) != '\0') { + continue; + } + + /* + RETURN_ALWAYS(ARGUMENT(s1)); + */ + return p; +} + +/*** +copies the string at ARGUMENT(s2) to ARGUMENT(s1), up to and +including the terminating CHAR(\0). +***/ +/* +STDC(1) +*/ diff --git a/src/string/strcspn.c b/src/string/strcspn.c new file mode 100644 index 00000000..4bbdee2e --- /dev/null +++ b/src/string/strcspn.c @@ -0,0 +1,28 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** count non-matching characters **/ +size_t strcspn(const char *s1, const char *s2) +{ + size_t i = 0; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + for (i = 0; s1[i] != '\0'; i++) { + if (strchr (s2, s1[i]) != NULL) { + break; + } + } + + return i; +} + +/*** +the number of characters that the beginning of +the string ARGUMENT(s1) that are not in the string ARGUMENT(s2). +***/ +/* + RETURN_ALWAYS(the number of non-matching characters); +STDC(1) +*/ diff --git a/src/string/strerror.c b/src/string/strerror.c new file mode 100644 index 00000000..055a11f7 --- /dev/null +++ b/src/string/strerror.c @@ -0,0 +1,31 @@ +#include <string.h> +#include "errno.h" +#include "stdio.h" +# define __LONGEST_STRERR 64 /* FIXME */ + +/** convert error number to string **/ +char * strerror(int errnum) +{ + static char errstr[__LONGEST_STRERR+1]; + + switch (errnum) { + #include "_strerror.h" + default: + sprintf(errstr, "unknown error [%d]", errnum); + break; + } + + /* + RETURN_ALWAYS(a pointer to the message string); + */ + return errstr; +} + +/*** +converts the error number ARGUMENT(errnum) to an error message +string. The string returned should not be modified, and may be overwritten by +subsequent calls. +***/ +/* +STDC(1) +*/ diff --git a/src/string/strlen.c b/src/string/strlen.c new file mode 100644 index 00000000..89ccbfcc --- /dev/null +++ b/src/string/strlen.c @@ -0,0 +1,25 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** find string length **/ +size_t strlen(const char *s) +{ + size_t i = 0; + + ASSERT_NONNULL(s); + + for (i = 0; s[i] != '\0'; i++) { + continue; + } + + return i; +} + +/*** +counts the number of bytes in the string ARGUMENT(s), not +including the terminating null character. +***/ +/* + RETURN_ALWAYS(the length of the string); +STDC(1) +*/ diff --git a/src/string/strncat.c b/src/string/strncat.c new file mode 100644 index 00000000..34800069 --- /dev/null +++ b/src/string/strncat.c @@ -0,0 +1,40 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** concatenate bounded string **/ +char * strncat(char * restrict s1, const char * restrict s2, size_t n) +{ + char *append = NULL; + size_t i; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + ASSERT_NOOVERLAP(s1, s2, strlen(s1) + strlen(s2)); + + append = s1 + strlen(s1); + + for (i = 0; i < n; i++) { + append[i] = s2[i]; + if (append[i] == '\0') { + break; + } + } + + if (append[i - 1] != '\0') { + append[i] = '\0'; + } + + return s1; +} + +/*** +appends a copy of the frist ARGUMENT(n) bytes of the string +at ARGUMENT(s2) to the end of the string at ARGUMENT(s1). The first byte of ARGUMENT(s2) will +overwrite the terminating null character of ARGUMENT(s1). No characters after the +first CHAR(\0) will be copied. The resulting string will always be null +terminated. +***/ +/* + RETURN_ALWAYS(ARGUMENT(s1)); +STDC(1) +*/ diff --git a/src/string/strncmp.c b/src/string/strncmp.c new file mode 100644 index 00000000..23c8104e --- /dev/null +++ b/src/string/strncmp.c @@ -0,0 +1,31 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** compare bound strings **/ +int strncmp(const char *s1, const char *s2, size_t n) +{ + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + if (strlen(s1) < n) { + n = strlen(s1); + } + if (strlen(s2) < n) { + n = strlen(s2); + } + + /* + RETURN(NEGATIVE, ARGUMENT(s1) is less than ARGUMENT(s2)); + RETURN(ZERO, ARGUMENT(s1) is equal to ARGUMENT(s2)); + RETURN(POSITIVE, ARGUMENT(s1) is greater than ARGUMENT(s2)); + */ + return memcmp(s1, s2, n); +} + +/*** +compares up to the first ARGUMENT(n) bytes of the strings at ARGUMENT(s1) and +ARGUMENT(s2), or until the first CHAR(\0), whichever comes first. +***/ +/* +STDC(1) +*/ diff --git a/src/string/strncpy.c b/src/string/strncpy.c new file mode 100644 index 00000000..ee632d69 --- /dev/null +++ b/src/string/strncpy.c @@ -0,0 +1,34 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** copy bounded string **/ +char * strncpy(char * restrict s1, const char * restrict s2, size_t n) +{ + size_t i; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + ASSERT_NOOVERLAP(s1, s2, n); + + for (i = 0; i < n; i++) { + s1[i] = s2[i]; + if (s1[i] == '\0') { + memset(s1 + i, '\0', n - i); + break; + } + } + + return s1; +} + +/*** +copies up to ARGUMENT(n) bytes from the string at ARGUMENT(s2) +to ARGUMENT(s1). If a CHAR(\0) is encountered, null characters are appended to +ARGUMENT(s1) until ARGUMENT(n) bytes have been written. If no null characters are copied +in the first ARGUMENT(n) bytes of ARGUMENT(s2), the resulting string will not be null +terminated. +***/ +/* + RETURN_ALWAYS(ARGUMENT(s1)); +STDC(1) +*/ diff --git a/src/string/strpbrk.c b/src/string/strpbrk.c new file mode 100644 index 00000000..0b88b999 --- /dev/null +++ b/src/string/strpbrk.c @@ -0,0 +1,28 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** count matching characters **/ +char * strpbrk(const char *s1, const char *s2) +{ + size_t i; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + for (i = 0; i < strlen (s1); i++) { + if (strchr(s2, s1[i]) != NULL) { + return (char*)s1 + i; + } + } + + return NULL; +} + +/*** +locates the first occurence in ARGUMENT(s1) of any character in ARGUMENT(s2). +***/ +/* + RETURN_FAILURE(CONSTANT(NULL)); + RETURN_SUCCESS(a pointer to the located character); +STDC(1) +*/ diff --git a/src/string/strrchr.c b/src/string/strrchr.c new file mode 100644 index 00000000..0427aa66 --- /dev/null +++ b/src/string/strrchr.c @@ -0,0 +1,30 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** search string from end **/ +char * strrchr(const char *s, int c) +{ + int i = 0; + + ASSERT_NONNULL(s); + + for (i = strlen(s) + 1; i >= 0; i--) { + if (s[i] == (char)c) { + return (char*)s + i; + } + } + + /* + RETURN_SUCCESS(a pointer to the found character); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return NULL; +} + +/*** +finds the last occurence of ARGUMENT(c) (converted to TYPE(char)) in the +string ARGUMENT(s). +***/ +/* +STDC(1) +*/ diff --git a/src/string/strspn.c b/src/string/strspn.c new file mode 100644 index 00000000..e67461a5 --- /dev/null +++ b/src/string/strspn.c @@ -0,0 +1,28 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** count matching characters **/ +size_t strspn(const char *s1, const char *s2) +{ + size_t i = 0; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + for (i = 0; i < strlen (s1); i++) { + if (strchr(s2, s1[i]) == NULL) { + break; + } + } + + return i; +} + +/*** +computes the length of the maximum initial segment of the ARGUMENT(s1) made +up of characters from ARGUMENT(s2). +***/ +/* + RETURN_ALWAYS(the number of matching characters); +STDC(1) +*/ diff --git a/src/string/strstr.c b/src/string/strstr.c new file mode 100644 index 00000000..898db1be --- /dev/null +++ b/src/string/strstr.c @@ -0,0 +1,43 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** search for substring **/ +char * strstr(const char *s1, const char *s2) +{ + size_t l1 = 0; + size_t l2 = 0; + char *p = (char*)s1; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + l2 = strlen(s2); + if (l2 == 0) { + return p; + } + + l1 = strlen(s1); + + do { + p = memchr(p, *s2, l1); + if (p == NULL || strcmp(p + 1, s2 + 1) == 0) { + break; + } + p++; + } while (p < s1 + l2); + + /* + RETURN_FAILURE(CONSTANT(NULL)); + RETURN_SUCCESS(a pointer to the located string); + */ + return p; +} + +/*** +finds the first occurrence of the string ARGUMENT(s2) in the string +ARGUMENT(s1). Specifying the empty string for ARGUMENT(s2) matches the first +character of ARGUMENT(s1). +***/ +/* +STDC(1) +*/ diff --git a/src/string/strtok.c b/src/string/strtok.c new file mode 100644 index 00000000..9a7137cf --- /dev/null +++ b/src/string/strtok.c @@ -0,0 +1,34 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** split string into tokens **/ +char * strtok(char * restrict s1, const char * restrict s2) +{ + extern char * strtok_r(char *restr, const char *restrict, char **); + static char *current; + + /* TODO */ + ASSERT_NONNULL(s2); + + /* + RETURN(CONSTANT(NULL), there are no further tokens, only token separators); + RETURN(NONNULL, a pointer to the first character of the next token); + */ + + return strtok_r (s1, s2, ¤t); +} + +/*** +splits the string ARGUMENT(s1) into a series of tokens +delimited by characters from the string ARGUMENT(s2). + +The first call in a sequence specifies a string for ARGUMENT(s1). Further calls +specify CONSTANT(NULL) in order to continue from the end of the previous token. +The list of token separators in ARGUMENT(s2) may vary from call to call. + +When tokens are found, the next token separate character is replaced with a +CHAR(\0), terminating the token. +***/ +/* +STDC(1) +*/ diff --git a/src/string/strxfrm.c b/src/string/strxfrm.c new file mode 100644 index 00000000..b6ec62b6 --- /dev/null +++ b/src/string/strxfrm.c @@ -0,0 +1,32 @@ +#include <string.h> +#include "nonstd/assert.h" + +/** transform string **/ +size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n) +{ + /* TODO */ + (void)s1; (void)s2; (void)n; + ASSERT_NONNULL(s2); + + if (n != 0) { + ASSERT_NONNULL(s1); + ASSERT_NOOVERLAP(s1, s2, n); + } + + return 0; +} + +/*** +transforms up to ARGUMENT(n) bytes of the string at ARGUMENT(s2), +placing the transformed string at ARGUMENT(s1). The transformed string is the +canonical form of the string used for collation purposes. If a CHAR(\0) is +transformed, no further characters are transformed. +***/ + +/* +UNDEFINED(ARGUMENT(n) is not ZERO and ARGUMENT(s1) is CONSTANT(NULL)) +*/ +/* + RETURN_ALWAYS(the length of the transformed string, not including the terminating CHAR(\0)); +STDC(1) +*/ diff --git a/src/time/CLOCKS_PER_SEC.c b/src/time/CLOCKS_PER_SEC.c new file mode 100644 index 00000000..7ef4bb89 --- /dev/null +++ b/src/time/CLOCKS_PER_SEC.c @@ -0,0 +1,12 @@ +#include <time.h> +#define CLOCKS_PER_SEC ((clock_t)1000000) + +/** clock ticks per second **/ + +/*** +is the number of clock ticks per second returned by FUNCTION(clock). +***/ + +/* +STDC(1) +*/ diff --git a/src/time/NULL.ref b/src/time/NULL.ref new file mode 100644 index 00000000..0ac4b016 --- /dev/null +++ b/src/time/NULL.ref @@ -0,0 +1,3 @@ +#include <time.h> +REFERENCE(stddef/NULL.c) +STDC(1) diff --git a/src/time/asctime.c b/src/time/asctime.c new file mode 100644 index 00000000..06dceae8 --- /dev/null +++ b/src/time/asctime.c @@ -0,0 +1,36 @@ +#include <time.h> +#include "stdio.h" + +/** convert broken down time to string **/ +char * asctime(const struct tm * timeptr) +{ + const char days[7][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + const char months[12][3] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + static char result[26]; + + sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", + days[timeptr->tm_wday], months[timeptr->tm_mon], + timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, + timeptr->tm_sec, timeptr->tm_year + 1900); + return result; +} + +/*** +converts the time specified at ARGUMENT(timeptr) to a string +in the format LITERAL(DDD MMM dd hh:mm:ss yyyy\n\0), where LITERAL(DDD) is the +three-character abbreviated day of the week, LITERAL(MMM) is the three-character +abbreviated month, LITERAL(dd) is the day of the month, LITERAL(hh) is the +hour of the day (in the range (0,23)), LITERAL(mm) is the minute of the hour +(in the range (0,59)), LITERAL(ss) is the second of the minute (in the range +(0,61)), and LITERAL(yyyy) is the year. +***/ + +/* +RETURN_ALWAYS(a pointer to the string) +STDC(1) +*/ diff --git a/src/time/clock.c b/src/time/clock.c new file mode 100644 index 00000000..a141e36d --- /dev/null +++ b/src/time/clock.c @@ -0,0 +1,19 @@ +#include <time.h> + +/** get processor time **/ +clock_t clock(void) +{ + return (clock_t)-1; +} + +/*** +returns the amount of processor time used by the current +program. To convert this time to seconds, divide it by CONSTANT(CLOCKS_PER_SEC). +***/ + +/* +IMPLEMENTATION(What constitutes CAST(TYPEDEF(clock_t), 0)) +RETURN_FAILURE(CAST(TYPEDEF(clock_t), -1)) +RETURN_SUCCESS(the processor time of the current program) +STDC(1) +*/ diff --git a/src/time/clock_t.c b/src/time/clock_t.c new file mode 100644 index 00000000..fe7a3842 --- /dev/null +++ b/src/time/clock_t.c @@ -0,0 +1,13 @@ +#include <time.h> +typedef long int clock_t; + +/** clock ticks **/ + +/*** +is an arithmetic type representing clock ticks. +***/ + +/* +DEFINED_TYPE(an arithmetic type) +STDC(1) +*/ diff --git a/src/time/ctime.c b/src/time/ctime.c new file mode 100644 index 00000000..5619e316 --- /dev/null +++ b/src/time/ctime.c @@ -0,0 +1,18 @@ +#include <time.h> + +/** convert arithmetic time to string **/ + +char * ctime(const time_t * timer) +{ + return asctime(localtime(timer)); +} + +/*** +converts the time at ARGUMENT(timer) to a string in the same format as +FUNCTION(asctime). +***/ + +/* +RETURN_ALWAYS(a pointer to the string) +STDC(1) +*/ diff --git a/src/time/difftime.c b/src/time/difftime.c new file mode 100644 index 00000000..17bb5c71 --- /dev/null +++ b/src/time/difftime.c @@ -0,0 +1,17 @@ +#include <time.h> + +/** find difference between two times **/ + +double difftime(time_t time1, time_t time0) +{ + return (double)time1 - (double)time0; +} + +/*** +subtracts ARGUMENT(time0) from ARGUMENT(time1). +***/ + +/* +RETURN_ALWAYS(the difference in seconds) +STDC(1) +*/ diff --git a/src/time/gmtime.c b/src/time/gmtime.c new file mode 100644 index 00000000..a844d097 --- /dev/null +++ b/src/time/gmtime.c @@ -0,0 +1,71 @@ +#include <time.h> +#include "nonstd/assert.h" + +# define SEC_PER_MIN (60L) +# define MIN_PER_HR (60L) +# define SEC_PER_HR ((SEC_PER_MIN) * (MIN_PER_HR)) +# define HR_PER_DAY (24L) +# define SEC_PER_DAY ((SEC_PER_HR) * (HR_PER_DAY)) +# define DAY_PER_YEAR (365L) /* not counting leap year */ +# define SEC_PER_YEAR ((SEC_PER_DAY) * (DAY_PER_YEAR)) +# define ISLEAPYEAR(y) ((y) % 4L == 0 && ((y) % 100L != 0 || (y) % 400L == 0)) +# define EPOCH_YEAR (70) + +/** convert arithmetic time to borken down time **/ + +struct tm * gmtime(const time_t * timer) +{ + static struct tm tm = {0}; + time_t seconds = 0; + int days = 0; + int days_per_mon[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + ASSERT_NONNULL(timer); + seconds = *timer; + + tm.tm_year = EPOCH_YEAR; + while (seconds > SEC_PER_YEAR) { + /* TODO: Will this mess up Dec 31 of leap year? */ + /* TODO: Or Jan 1 of year after leap year? */ + seconds -= SEC_PER_YEAR; + if (ISLEAPYEAR(tm.tm_year + 1900)) { + seconds -= SEC_PER_DAY; + } + tm.tm_year++; + } + if (ISLEAPYEAR(tm.tm_year + 1900)) { + days_per_mon[1] = 29; + } + + tm.tm_yday = (int)(seconds / SEC_PER_DAY); + seconds = seconds % SEC_PER_DAY; + tm.tm_hour = (int)(seconds / SEC_PER_HR); + seconds = seconds % SEC_PER_HR; + tm.tm_min = (int)(seconds / SEC_PER_MIN); + tm.tm_sec = (int)(seconds % SEC_PER_MIN); + + days = tm.tm_yday; + tm.tm_mon = 0; + while (days > days_per_mon[tm.tm_mon]) { + days -= days_per_mon[tm.tm_mon]; + tm.tm_mon++; + } + tm.tm_mday = days; + + /* TODO: tm_wday */ + tm.tm_wday = 0; + /* TODO: tm_isdst */ + tm.tm_isdst = 0; + + return &tm; +} + +/*** +converts the UTC time at ARGUMENT(timer) to a filled out STRUCTDEF(tm). +***/ + +/* +RETURN_FAILURE(CONSTANT(NULL)) +RETURN_SUCCESS(a pointer to the converted time) +STDC(1) +*/ diff --git a/src/time/localtime.c b/src/time/localtime.c new file mode 100644 index 00000000..b09f84a5 --- /dev/null +++ b/src/time/localtime.c @@ -0,0 +1,24 @@ +#include <time.h> +#include "nonstd/assert.h" + +/** convert arithmetic time to broken down time **/ + +struct tm * localtime(const time_t * timer) +{ + static struct tm tm = {0}; + ASSERT_NONNULL(timer); + + tm = *gmtime(timer); + /* TODO: adjust for timezone */ + + return &tm; +} + +/*** +converts the locale time at ARGUMENT(timer) to a filled out STRUCTDEF(tm). +***/ + +/* +RETURN_ALWAYS(a pointer to the converted object) +STDC(1) +*/ diff --git a/src/time/mktime.c b/src/time/mktime.c new file mode 100644 index 00000000..9e58d4eb --- /dev/null +++ b/src/time/mktime.c @@ -0,0 +1,23 @@ +#include <time.h> + +/** convert time structure to arithmetic type **/ + +time_t mktime(struct tm * timeptr) +{ + (void)timeptr; + return (time_t)-1; +} + +/*** +converts the local time pointed to by ARGUMENT(timeptr) to +an arithmetic value of type TYPEDEF(time_t). It also normalizes the values in +the STRUCTDEF(tm) at ARGUMENT(timeptr) to fit the defined limits, as well as +correcting the members MEMBER(tm_wday) and MEMBER(tm_yday) if they were +previously incorrect. +***/ + +/* +RETURN_FAILURE(CAST(TYPEDEF(time_t), -1)) +RETURN_SUCCESS(the converted time) +STDC(1) +*/ diff --git a/src/time/size_t.ref b/src/time/size_t.ref new file mode 100644 index 00000000..75ce0309 --- /dev/null +++ b/src/time/size_t.ref @@ -0,0 +1,3 @@ +#include <time.h> +REFERENCE(stddef/size_t.c) +STDC(1) diff --git a/src/time/strftime.c b/src/time/strftime.c new file mode 100644 index 00000000..abf56bc5 --- /dev/null +++ b/src/time/strftime.c @@ -0,0 +1,187 @@ +#include <time.h> +#include "stdio.h" +#include "nonstd/assert.h" +#include "nonstd/internal.h" +#include "locale.h" +#include "nonstd/locale.h" + +/** convert time to a formatted string **/ + +size_t strftime(char * restrict s, size_t maxsize, const char * restrict format, const struct tm * restrict timeptr) +{ + size_t converted = 0, i, j; + char buf[64]; + struct __locale_t *lc; + + ASSERT_NONNULL(s); + ASSERT_NONNULL(format); + ASSERT_NONNULL(timeptr); + + lc = __libc(THREAD_LOCALE); + + for (i = 0; format[i] != '\0' && converted < maxsize; i++) { + if (format[i] != '%') { + s[converted++] = format[i]; + continue; + } + + switch (format[++i]) { + case 'a': + sprintf(buf, "%s", lc->lc_time.abday[timeptr->tm_wday]); + break; + + case 'A': + sprintf(buf, "%s", lc->lc_time.day[timeptr->tm_wday]); + break; + + case 'b': + sprintf(buf, "%s", lc->lc_time.abmon[timeptr->tm_mon]); + break; + + case 'B': + sprintf(buf, "%s", lc->lc_time.mon[timeptr->tm_mon]); + break; + + case 'c': + /* FIXME: expand this */ + sprintf(buf, "%s", lc->lc_time.d_t_fmt); + break; + + case 'd': + sprintf(buf, "%02d", timeptr->tm_mday); + break; + + case 'H': + sprintf(buf, "%02d", timeptr->tm_hour); + break; + + case 'I': + sprintf(buf, "%02d", (timeptr->tm_hour + 1) % 13); + break; + + case 'j': + sprintf(buf, "%03d", timeptr->tm_yday + 1); + break; + + case 'm': + sprintf(buf, "%02d", timeptr->tm_mon + 1); + break; + + case 'M': + sprintf(buf, "%02d", timeptr->tm_min); + break; + + case 'p': + sprintf(buf, "%s", lc->lc_time.am_pm[timeptr->tm_hour < 12 ? 0 : 1]); + break; + + case 'S': + sprintf(buf, "%02d", timeptr->tm_sec); + break; + + case 'U': + /* TODO: two digit week of year, sunday based week */ + sprintf(buf, "%02d", timeptr->tm_yday / 7); + break; + + case 'w': + sprintf(buf, "%1d", timeptr->tm_wday); + break; + + case 'W': + /* TODO: two digit week of year, monday based week */ + sprintf(buf, "%02d", timeptr->tm_yday / 7); + break; + + case 'x': + /* TODO: expand this */ + sprintf(buf, "%s", lc->lc_time.d_fmt); + break; + + case 'X': + /* TODO: expand this */ + sprintf(buf, "%s", lc->lc_time.t_fmt); + break; + + case 'y': + sprintf(buf, "%02d", timeptr->tm_year % 100); + break; + + case 'Y': + sprintf(buf, "%d", timeptr->tm_year + 1900); + break; + + case 'Z': + sprintf(buf, "%s", "timezone"); + break; + + case '%': + sprintf(buf, "%%"); + break; + + default: + sprintf(buf, "UNDEFINED"); + /* undefined behavior */ + break; + } + + for (j = 0; buf[j] != '\0'; j++) { + s[converted++] = buf[j]; + if (converted >= maxsize - 1) { + break; + } + } + } + + s[converted++] = '\0'; + + if (converted >= maxsize) { + return 0; + } + + return converted; +} + +/*** +converts the time at ARGUMENT(timeptr) to a string of no more than +ARGUMENT(maxsize) bytes at ARGUMENT(s). The format of the converted string +is specified by ARGUMENT(format). The string at ARGUMENT(format) may contain +conversion specifiers, which consist of a CHAR(%) followed by one character. +All other characters are copied to ARGUMENT(s) verbatim. + +The conversion specifiers are: + +FLAG(%a, the current locales abbreviated weekday name) +FLAG(%A, the current locales full weekday name) +FLAG(%b, the current locales abbreviated month name) +FLAG(%B, the current locales full month name) +FLAG(%c, the current locales date and time representation) +FLAG(%d, the day of the month (in the range (01,31))) +FLAG(%H, the hour (in the range (00,23))) +FLAG(%I, the hour (in the range (01,12))) +FLAG(%j, the day of the year (in the range (001,366))) +FLAG(%m, the numeric month (in the range (01,12))) +FLAG(%M, the minute (in the range (00,59))) +FLAG(%p, the current locales AM/PM designator) +FLAG(%S, the second (in the range (00,61))) +FLAG(%U, the week of the year (Sunday based, in the range (00,53))) +FLAG(%w, the numeric weekday (in the range (0,6), with Sunday as 0)) +FLAG(%W, the week of the year (Monday based, in the range (00,53))) +FLAG(%x, the current locales date representation) +FLAG(%X, the current locales time representation) +FLAG(%y, the year without centruy (in the range (00,99))) +FLAG(%Y, the year with century) +FLAG(%Z, the time zone name or abbreviation, if determinable) +FLAG(%%, a literal %) +***/ + +/* +UNDEFINED(Copying takes place between objects that overlap) +LC_TIME +RETURN_FAILURE(ZERO) +RETURN_SUCCESS(the length of the converted string, not counting the terminating null) +*/ + +/* +STDC(1) +*/ diff --git a/src/time/struct_tm.c b/src/time/struct_tm.c new file mode 100644 index 00000000..067d54f3 --- /dev/null +++ b/src/time/struct_tm.c @@ -0,0 +1,23 @@ +#include <time.h> + +/** broken-down time **/ + +struct tm { + int tm_sec; /* Seconds [0,60] */ + int tm_min; /* Minutes [0, 59] */ + int tm_hour; /* Hour [0,23] */ + int tm_mday; /* Day of the month [1,31] */ + int tm_mon; /* Month of the year [0,11] */ + int tm_year; /* Years since 1900 */ + int tm_wday; /* Day of the week [0,6] (Sunday = 0) */ + int tm_yday; /* Day of the year [0,365] */ + int tm_isdst; /* Daylight Saving Time flag */ +}; + +/*** +is used to represent time broken down into its individual components. +***/ + +/* +STDC(1) +*/ diff --git a/src/time/time.c b/src/time/time.c new file mode 100644 index 00000000..abe47471 --- /dev/null +++ b/src/time/time.c @@ -0,0 +1,31 @@ +#include <time.h> +#include "nonstd/internal.h" +#include "nonstd/syscall.h" + +/** get current time **/ + +time_t time(time_t * timer) +{ + long int now; + SYSCALL_NUMBER(sc, "time", 0); + + now = __syscall(sc); + + if (timer != NULL && now != -1) { + *timer = (time_t)now; + } + + return (time_t)now; +} + +/*** +gets the current time. If ARGUMENT(timer) is not CONSTANT(NULL), +the current time is also stored in the object it points to. +***/ + +/* +UNSPECIFIED(The encoding of TYPEDEF(time_t)) +RETURN_FAILURE(CAST(TYPEDEF(time_t), -1)) +RETURN_SUCCESS(the current calndar time) +STDC(1) +*/ diff --git a/src/time/time_t.c b/src/time/time_t.c new file mode 100644 index 00000000..df2f34e8 --- /dev/null +++ b/src/time/time_t.c @@ -0,0 +1,14 @@ +#include <time.h> + +/** time representation **/ + +typedef long int time_t; + +/*** +is used for representing time. +***/ + +/* +DEFINED_TYPE(an arithmetic type) +STDC(1) +*/ diff --git a/src/wchar/FILE.ref b/src/wchar/FILE.ref new file mode 100644 index 00000000..5d9aa059 --- /dev/null +++ b/src/wchar/FILE.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(stdio/FILE.c) +STDC(199409) diff --git a/src/wchar/NULL.ref b/src/wchar/NULL.ref new file mode 100644 index 00000000..251fc86a --- /dev/null +++ b/src/wchar/NULL.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(stddef/NULL.c) +STDC(199409) diff --git a/src/wchar/WCHAR_MAX.c b/src/wchar/WCHAR_MAX.c new file mode 100644 index 00000000..de021945 --- /dev/null +++ b/src/wchar/WCHAR_MAX.c @@ -0,0 +1,6 @@ +#include <wchar.h> +#define WCHAR_MAX (0x1FFFF) + +/* +STDC(199409) +*/ diff --git a/src/wchar/WCHAR_MIN.c b/src/wchar/WCHAR_MIN.c new file mode 100644 index 00000000..dbf961db --- /dev/null +++ b/src/wchar/WCHAR_MIN.c @@ -0,0 +1,6 @@ +#include <wchar.h> +#define WCHAR_MIN (0) + +/* +STDC(199409) +*/ diff --git a/src/wchar/WEOF.ref b/src/wchar/WEOF.ref new file mode 100644 index 00000000..e8aa99f1 --- /dev/null +++ b/src/wchar/WEOF.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(wctype/WEOF.c) +STDC(199409) diff --git a/src/wchar/btowc.c b/src/wchar/btowc.c new file mode 100644 index 00000000..dd986119 --- /dev/null +++ b/src/wchar/btowc.c @@ -0,0 +1,21 @@ +#include <wchar.h> +#include "locale.h" +#include "string.h" + +wint_t btowc(int c) +{ + char *l = setlocale(LC_CTYPE, NULL); + + if (!strcmp(l, "C") || !strcmp(l, "POSIX")) { + if (c <= 127) { + return (unsigned char)c; + } + } + + /* conversion */ + return WEOF; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fgetwc.c b/src/wchar/fgetwc.c new file mode 100644 index 00000000..30d98083 --- /dev/null +++ b/src/wchar/fgetwc.c @@ -0,0 +1,35 @@ +#include <wchar.h> +#include "stdio.h" +#include "nonstd/io.h" +#include "limits.h" + +wint_t fgetwc(FILE * stream) +{ + if (fwide(stream, 1) <= 0) { + + return WEOF; + } + + flockfile(stream); + stream->orientation = -1; + + char mbr[MB_LEN_MAX+1] = {0}; + int n = 0; + mbstate_t ps = 0; + wint_t wc = 0; + + /* FIXME: check for (size_t)-2 and (size_t)-1 from mbrtowc */ + do { + mbr[n++] = getc_unlocked(stream); + ps = 0; + } while (mbrtowc(&wc, mbr, n, &ps) != 0); + + stream->orientation = 1; + funlockfile(stream); + + return wc; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fgetws.c b/src/wchar/fgetws.c new file mode 100644 index 00000000..5262a79d --- /dev/null +++ b/src/wchar/fgetws.c @@ -0,0 +1,37 @@ +#include <wchar.h> +#include "stdio.h" +#include "nonstd/assert.h" + +wchar_t * fgetws(wchar_t * restrict s, int n, FILE * restrict stream) +{ + ASSERT_NONNULL(s); + ASSERT_NONNULL(stream); + + if (fwide(stream, 1) <= 0) { + /* not a wide stream */ + return NULL; + } + + int i; + for (i = 0; i < n; i++) { + s[i] = fgetwc(stream); + if (s[i] == WEOF) { + if (feof(stream)) { + s[i] = L'\0'; + return s; + } + /* read or encoding error */ + return NULL; + } + if (s[i] == L'\0') { + break; + } + } + s[i] = L'\0'; + + return s; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fputwc.c b/src/wchar/fputwc.c new file mode 100644 index 00000000..e7b9c503 --- /dev/null +++ b/src/wchar/fputwc.c @@ -0,0 +1,41 @@ +#include <wchar.h> +#include "stdio.h" +#include "nonstd/io.h" +#include "limits.h" +#include "errno.h" + +wint_t fputwc(wchar_t c, FILE * stream) +{ + size_t i; + + if (fwide(stream, 1) <= 0) { + /* not a wide stream */ + return WEOF; + } + + flockfile(stream); + stream->orientation = -1; + + char mbs[MB_LEN_MAX+1] = {0}; + mbstate_t ps = 0; + size_t len = wcrtomb(mbs, c, &ps); + + if (len == (size_t)-1) { + errno = EILSEQ; + return WEOF; + } + + /* FIXME: check for errors here */ + for (i = 0; i < len; i++) { + fputc(mbs[i], stream); + } + + stream->orientation = 1; + funlockfile(stream); + + return c; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fputws.c b/src/wchar/fputws.c new file mode 100644 index 00000000..69c0aec3 --- /dev/null +++ b/src/wchar/fputws.c @@ -0,0 +1,12 @@ +#include <wchar.h> +#include "stdio.h" + +int fputws(const wchar_t * restrict s, FILE * restrict stream) +{ + (void)s; (void)stream; + return -1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fwide.c b/src/wchar/fwide.c new file mode 100644 index 00000000..a1401a42 --- /dev/null +++ b/src/wchar/fwide.c @@ -0,0 +1,18 @@ +#include <wchar.h> +#include "stdio.h" +#include "nonstd/io.h" +#include "nonstd/assert.h" + +int fwide(FILE * stream, int mode) +{ + ASSERT_NONNULL(stream); + + if (stream->orientation == 0) { + stream->orientation = mode; + } + return stream->orientation; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fwprintf.c b/src/wchar/fwprintf.c new file mode 100644 index 00000000..540405f9 --- /dev/null +++ b/src/wchar/fwprintf.c @@ -0,0 +1,16 @@ +#include <wchar.h> +#include "stdio.h" +#include "stdarg.h" + +int fwprintf(FILE * restrict stream, const wchar_t * restrict format, ...) +{ + va_list ap; + va_start(ap, format); + int ret = vfwprintf(stream, format, ap); + va_end(ap); + return ret; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/fwscanf.c b/src/wchar/fwscanf.c new file mode 100644 index 00000000..63324366 --- /dev/null +++ b/src/wchar/fwscanf.c @@ -0,0 +1,20 @@ +#include <wchar.h> +#include "stdio.h" +#include "stdarg.h" + +int fwscanf(FILE * restrict stream, const wchar_t * restrict format, ...) +{ + /* + va_list ap; + va_start(ap, format); + int ret = vfwscanf(stream, format, ap); + va_end(ap); + return ret; + */ + (void)stream; (void)format; + return -1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/getwc.c b/src/wchar/getwc.c new file mode 100644 index 00000000..6783e93c --- /dev/null +++ b/src/wchar/getwc.c @@ -0,0 +1,11 @@ +#include <wchar.h> +#include "stdio.h" + +wint_t getwc(FILE * stream) +{ + return fgetwc(stream); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/getwchar.c b/src/wchar/getwchar.c new file mode 100644 index 00000000..8d4efa06 --- /dev/null +++ b/src/wchar/getwchar.c @@ -0,0 +1,11 @@ +#include <wchar.h> +#include "stdio.h" + +wint_t getwchar(void) +{ + return getwc(stdin); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/mbrlen.c b/src/wchar/mbrlen.c new file mode 100644 index 00000000..dd0af70b --- /dev/null +++ b/src/wchar/mbrlen.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +size_t mbrlen(const char * restrict s, size_t n, mbstate_t * restrict ps) +{ + static mbstate_t internal = 0; + return mbrtowc(NULL, s, n, ps != NULL ? ps : &internal); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/mbrtowc.c b/src/wchar/mbrtowc.c new file mode 100644 index 00000000..f6795d7f --- /dev/null +++ b/src/wchar/mbrtowc.c @@ -0,0 +1,19 @@ +#include <wchar.h> + +size_t mbrtowc(wchar_t * restrict pwc, const char * restrict s, size_t n, mbstate_t * restrict ps) +{ + (void)ps; (void)pwc; (void)n; + + if (s == NULL) { + s = ""; + n = 1; + } + + /* TODO */ + + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/mbsinit.c b/src/wchar/mbsinit.c new file mode 100644 index 00000000..f3d7b44f --- /dev/null +++ b/src/wchar/mbsinit.c @@ -0,0 +1,14 @@ +#include <wchar.h> + +int mbsinit(const mbstate_t * ps) +{ + if (ps == NULL || *ps == 0) { + return 1; + } + + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/mbsrtowcs.c b/src/wchar/mbsrtowcs.c new file mode 100644 index 00000000..12f5e6a1 --- /dev/null +++ b/src/wchar/mbsrtowcs.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +size_t mbsrtowcs(wchar_t * restrict dst, const char * restrict src, size_t len, mbstate_t * restrict ps) +{ + (void)dst; (void)src; (void)len; (void)ps; + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/mbstate_t.c b/src/wchar/mbstate_t.c new file mode 100644 index 00000000..d29ecfa5 --- /dev/null +++ b/src/wchar/mbstate_t.c @@ -0,0 +1,6 @@ +#include <wchar.h> +typedef int mbstate_t; + +/* +STDC(199409) +*/ diff --git a/src/wchar/putwc.c b/src/wchar/putwc.c new file mode 100644 index 00000000..58154c49 --- /dev/null +++ b/src/wchar/putwc.c @@ -0,0 +1,11 @@ +#include <wchar.h> +#include "stdio.h" + +wint_t putwc(wchar_t c, FILE * stream) +{ + return fputwc(c, stream); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/putwchar.c b/src/wchar/putwchar.c new file mode 100644 index 00000000..291c45e9 --- /dev/null +++ b/src/wchar/putwchar.c @@ -0,0 +1,11 @@ +#include <wchar.h> +#include "stdio.h" + +wint_t putwchar(wchar_t c) +{ + return putwc(c, stdout); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/size_t.ref b/src/wchar/size_t.ref new file mode 100644 index 00000000..a5058ebc --- /dev/null +++ b/src/wchar/size_t.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(stddef/size_t.c) +STDC(199409) diff --git a/src/wchar/struct_tm.c b/src/wchar/struct_tm.c new file mode 100644 index 00000000..a33f964c --- /dev/null +++ b/src/wchar/struct_tm.c @@ -0,0 +1,6 @@ +#include <wchar.h> +struct tm; + +/* +STDC(199409) +*/ diff --git a/src/wchar/swprintf.c b/src/wchar/swprintf.c new file mode 100644 index 00000000..1b9ef406 --- /dev/null +++ b/src/wchar/swprintf.c @@ -0,0 +1,15 @@ +#include <wchar.h> +#include "stdarg.h" + +int swprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict format, ...) +{ + va_list ap; + va_start(ap, format); + int ret = vswprintf(s, n, format, ap); + va_end(ap); + return ret; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/swscanf.c b/src/wchar/swscanf.c new file mode 100644 index 00000000..2f10842a --- /dev/null +++ b/src/wchar/swscanf.c @@ -0,0 +1,19 @@ +#include <wchar.h> +#include "stdarg.h" + +int swscanf(const wchar_t * restrict s, const wchar_t * restrict format, ...) +{ + /* + va_list ap; + va_start(ap, format); + int ret = vswscanf(s, format, ap); + va_end(ap); + return ret; + */ + (void)s; (void)format; + return -1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/ungetwc.c b/src/wchar/ungetwc.c new file mode 100644 index 00000000..7c40ddb5 --- /dev/null +++ b/src/wchar/ungetwc.c @@ -0,0 +1,12 @@ +#include <wchar.h> +#include "stdio.h" + +wint_t ungetwc(wint_t c, FILE * stream) +{ + (void)c; (void)stream; + return -1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/va_list.ref b/src/wchar/va_list.ref new file mode 100644 index 00000000..ead1b4e1 --- /dev/null +++ b/src/wchar/va_list.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(stdarg/va_list.c) +STDC(199409) diff --git a/src/wchar/vfwprintf.c b/src/wchar/vfwprintf.c new file mode 100644 index 00000000..fbff917f --- /dev/null +++ b/src/wchar/vfwprintf.c @@ -0,0 +1,25 @@ +#include <wchar.h> +#include "stdio.h" +#include "stdarg.h" +#include "stdlib.h" + +int vfwprintf(FILE * restrict stream, const wchar_t * restrict format, va_list arg) +{ + /* + va_list ap; + va_copy(ap, arg); + int len = vsnwprintf(NULL, 0, format, arg); + wchar_t *buf = malloc((len + 1) * sizeof(wchar_t)); + len = vsnwprintf(buf, len, format, ap); + va_end(ap); + len = (int)fwrite(buf, sizeof(*buf), len, stream); + free(buf); + return len; + */ + (void)stream; (void)format; (void)arg; + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/vfwscanf.c b/src/wchar/vfwscanf.c new file mode 100644 index 00000000..75451ac6 --- /dev/null +++ b/src/wchar/vfwscanf.c @@ -0,0 +1,10 @@ +#include "stdio.h" +#include <wchar.h> + +int vfwscanf(FILE * restrict stream, const wchar_t * restrict format, va_list arg) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/vswprintf.c b/src/wchar/vswprintf.c new file mode 100644 index 00000000..63169a59 --- /dev/null +++ b/src/wchar/vswprintf.c @@ -0,0 +1,12 @@ +#include "stdarg.h" +#include <wchar.h> + +int vswprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict format, va_list arg) +{ + (void)s; (void)n; (void)format; (void)arg; + return -1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/vswscanf.c b/src/wchar/vswscanf.c new file mode 100644 index 00000000..b0896b75 --- /dev/null +++ b/src/wchar/vswscanf.c @@ -0,0 +1,9 @@ +#include <wchar.h> + +int vswscanf(const wchar_t * restrict s, const wchar_t * restrict format, va_list arg) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/vwprintf.c b/src/wchar/vwprintf.c new file mode 100644 index 00000000..1f983489 --- /dev/null +++ b/src/wchar/vwprintf.c @@ -0,0 +1,11 @@ +#include <wchar.h> +#include "stdio.h" + +int vwprintf(const wchar_t * restrict format, va_list arg) +{ + return vfwprintf(stdout, format, arg); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/vwscanf.c b/src/wchar/vwscanf.c new file mode 100644 index 00000000..757224a4 --- /dev/null +++ b/src/wchar/vwscanf.c @@ -0,0 +1,11 @@ +#include <wchar.h> +#include "stdarg.h" + +int vwscanf(const wchar_t * restrict format, va_list arg) +{ + return vfwscanf(stdin, format, arg); +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/wchar_t.ref b/src/wchar/wchar_t.ref new file mode 100644 index 00000000..7fef322e --- /dev/null +++ b/src/wchar/wchar_t.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(stddef/wchar_t.c) +STDC(199409) diff --git a/src/wchar/wcrtomb.c b/src/wchar/wcrtomb.c new file mode 100644 index 00000000..f68c2177 --- /dev/null +++ b/src/wchar/wcrtomb.c @@ -0,0 +1,19 @@ +#include <wchar.h> +#include "limits.h" + +size_t wcrtomb(char * restrict s, wchar_t wc, mbstate_t * restrict ps) +{ + char buf[MB_LEN_MAX+1]; + if (s == NULL) { + s = buf; + wc = L'\0'; + } + (void)wc; (void)ps; + + /* do stuff */ + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcscat.c b/src/wchar/wcscat.c new file mode 100644 index 00000000..8ffec24f --- /dev/null +++ b/src/wchar/wcscat.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +wchar_t * wcscat(wchar_t * restrict s1, const wchar_t * restrict s2) +{ + wcscpy(s1 + wcslen(s1), s2); + return s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcschr.c b/src/wchar/wcschr.c new file mode 100644 index 00000000..cc206ed8 --- /dev/null +++ b/src/wchar/wcschr.c @@ -0,0 +1,17 @@ +#include <wchar.h> + +wchar_t * wcschr(const wchar_t * s, wchar_t c) +{ + while (*s) { + if (*s == c) { + return (wchar_t*) s; + } + s++; + } + + return NULL; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcscmp.c b/src/wchar/wcscmp.c new file mode 100644 index 00000000..d07d9a10 --- /dev/null +++ b/src/wchar/wcscmp.c @@ -0,0 +1,25 @@ +#include <wchar.h> +#include "nonstd/assert.h" + +int wcscmp(const wchar_t * s1, const wchar_t * s2) +{ + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + while (*s1 == *s2 && *s1 != L'\0') { + s1++; + s2++; + } + + if (*s1 > *s2) { + return 1; + } else if (*s1 < *s2) { + return -1; + } + + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcscoll.c b/src/wchar/wcscoll.c new file mode 100644 index 00000000..097a2cc4 --- /dev/null +++ b/src/wchar/wcscoll.c @@ -0,0 +1,15 @@ +#include <wchar.h> + +int wcscoll(const wchar_t * s1, const wchar_t * s2) +{ + /* + wchar_t *collated_s1 = s1; + wchar_t *collated_s2 = s2; + */ + /* wcsxfrm */ + return wcscmp(s1, s2); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcscpy.c b/src/wchar/wcscpy.c new file mode 100644 index 00000000..2f92bc3f --- /dev/null +++ b/src/wchar/wcscpy.c @@ -0,0 +1,10 @@ +#include <wchar.h> + +wchar_t * wcscpy(wchar_t * restrict s1, const wchar_t * restrict s2) +{ + return wcsncpy(s1, s2, wcslen(s2)); +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcscspn.c b/src/wchar/wcscspn.c new file mode 100644 index 00000000..0c300a4a --- /dev/null +++ b/src/wchar/wcscspn.c @@ -0,0 +1,21 @@ +#include <wchar.h> +#include "nonstd/assert.h" + +size_t wcscspn(const wchar_t * s1, const wchar_t * s2) +{ + size_t i; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + for (i = 0; s1[i] != L'\0'; i++) { + if (s1[i] == L'\0' || wcschr(s2, s1[i]) == NULL) { + return i; + } + } + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsftime.c b/src/wchar/wcsftime.c new file mode 100644 index 00000000..ddca082d --- /dev/null +++ b/src/wchar/wcsftime.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +size_t wcsftime(wchar_t * restrict s, size_t maxsize, const wchar_t * restrict format, const struct tm * restrict timeptr) +{ + (void)s; (void)maxsize; (void)format; (void)timeptr; + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcslen.c b/src/wchar/wcslen.c new file mode 100644 index 00000000..5b4ec7be --- /dev/null +++ b/src/wchar/wcslen.c @@ -0,0 +1,14 @@ +#include <wchar.h> + +size_t wcslen(const wchar_t * s) +{ + size_t l = 0; + while (s[l] != L'\0') { + l++; + } + return l; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsncat.c b/src/wchar/wcsncat.c new file mode 100644 index 00000000..8dccba65 --- /dev/null +++ b/src/wchar/wcsncat.c @@ -0,0 +1,12 @@ +#include <wchar.h> + +wchar_t * wcsncat(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n) +{ + wcsncpy(s1 + wcslen(s1), s2, n); + /* ensure trailing nul */ + return s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsncmp.c b/src/wchar/wcsncmp.c new file mode 100644 index 00000000..d41899f4 --- /dev/null +++ b/src/wchar/wcsncmp.c @@ -0,0 +1,24 @@ +#include <wchar.h> +#include "nonstd/assert.h" + +int wcsncmp(const wchar_t * s1, const wchar_t * s2, size_t n) +{ + size_t i; + + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + for (i = 0; i < n; i++) { + if (s1[i] > s2[i]) { + return 1; + } else if (s1[i] < s2[i]) { + return -1; + } + } + + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsncpy.c b/src/wchar/wcsncpy.c new file mode 100644 index 00000000..ebae8133 --- /dev/null +++ b/src/wchar/wcsncpy.c @@ -0,0 +1,18 @@ +#include <wchar.h> + +wchar_t * wcsncpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n) +{ + size_t i; + int nul = 0; + for (i = 0; i < n; i++) { + s1[i] = nul ? s2[i] : L'\0'; + if (s1[i] == L'\0') { + nul = 1; + } + } + return s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcspbrk.c b/src/wchar/wcspbrk.c new file mode 100644 index 00000000..d1553fd1 --- /dev/null +++ b/src/wchar/wcspbrk.c @@ -0,0 +1,17 @@ +#include <wchar.h> + +wchar_t * wcspbrk(const wchar_t * s1, const wchar_t * s2) +{ + int i; + for (i = 0; s1[i] != L'\0'; i++) { + if (wcschr(s2, s1[i]) != NULL) { + return (wchar_t*)s1 + i; + } + } + + return NULL; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsrchr.c b/src/wchar/wcsrchr.c new file mode 100644 index 00000000..291dc6f4 --- /dev/null +++ b/src/wchar/wcsrchr.c @@ -0,0 +1,17 @@ +#include <wchar.h> + +wchar_t * wcsrchr(const wchar_t * s, wchar_t c) +{ + wchar_t *last = NULL; + while (*s) { + if (*s == c) { + last = (wchar_t*)s; + } + s++; + } + return last; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsrtombs.c b/src/wchar/wcsrtombs.c new file mode 100644 index 00000000..8df0bedf --- /dev/null +++ b/src/wchar/wcsrtombs.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +size_t wcsrtombs(char * restrict dst, const wchar_t ** restrict src, size_t len, mbstate_t * restrict ps) +{ + (void)dst; (void)src; (void)len; (void)ps; + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsspn.c b/src/wchar/wcsspn.c new file mode 100644 index 00000000..50cd0e02 --- /dev/null +++ b/src/wchar/wcsspn.c @@ -0,0 +1,17 @@ +#include <wchar.h> + +size_t wcsspn(const wchar_t * s1, const wchar_t * s2) +{ + size_t i; + for (i = 0; s1[i] != L'\0'; i++) { + if (wcschr(s2, s1[i]) == NULL) { + return i; + } + } + + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c new file mode 100644 index 00000000..22cf9fa7 --- /dev/null +++ b/src/wchar/wcsstr.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +wchar_t * wcsstr(const wchar_t * s1, const wchar_t * s2) +{ + (void)s2; + return (wchar_t*)s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcstod.c b/src/wchar/wcstod.c new file mode 100644 index 00000000..d8eeef74 --- /dev/null +++ b/src/wchar/wcstod.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +double wcstod(const wchar_t * restrict nptr, wchar_t ** restrict endptr) +{ + (void)nptr; (void)endptr; + return 0.0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcstof.c b/src/wchar/wcstof.c new file mode 100644 index 00000000..c9de199b --- /dev/null +++ b/src/wchar/wcstof.c @@ -0,0 +1,9 @@ +#include <wchar.h> + +float wcstof(const wchar_t * restrict nptr, wchar_t ** restrict endptr) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/wcstok.c b/src/wchar/wcstok.c new file mode 100644 index 00000000..0c40f5d9 --- /dev/null +++ b/src/wchar/wcstok.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +wchar_t * wcstok(wchar_t * restrict s1, const wchar_t * restrict s2, wchar_t ** restrict ptr) +{ + (void)s1; (void)s2; (void)ptr; + return s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcstol.c b/src/wchar/wcstol.c new file mode 100644 index 00000000..5d4a605d --- /dev/null +++ b/src/wchar/wcstol.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +long int wcstol(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) +{ + (void)nptr; (void)endptr; (void)base; + return 0L; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcstold.c b/src/wchar/wcstold.c new file mode 100644 index 00000000..32001008 --- /dev/null +++ b/src/wchar/wcstold.c @@ -0,0 +1,9 @@ +#include <wchar.h> + +long double wcstold(const wchar_t * restrict nptr, wchar_t ** restrict endptr) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/wcstoll.c b/src/wchar/wcstoll.c new file mode 100644 index 00000000..fc231433 --- /dev/null +++ b/src/wchar/wcstoll.c @@ -0,0 +1,9 @@ +#include <wchar.h> + +long long int wcstoll(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/wcstoul.c b/src/wchar/wcstoul.c new file mode 100644 index 00000000..8fcaeb8e --- /dev/null +++ b/src/wchar/wcstoul.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +unsigned long int wcstoul(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) +{ + (void)nptr; (void)endptr; (void)base; + return 0UL; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wcstoull.c b/src/wchar/wcstoull.c new file mode 100644 index 00000000..92e12e59 --- /dev/null +++ b/src/wchar/wcstoull.c @@ -0,0 +1,9 @@ +#include <wchar.h> + +unsigned long long int wcstoull(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) +{ +} + +/* +STDC(199901) +*/ diff --git a/src/wchar/wcsxfrm.c b/src/wchar/wcsxfrm.c new file mode 100644 index 00000000..acc87510 --- /dev/null +++ b/src/wchar/wcsxfrm.c @@ -0,0 +1,11 @@ +#include <wchar.h> + +size_t wcsxfrm(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n) +{ + (void)s1; (void)s2; (void)n; + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wctob.c b/src/wchar/wctob.c new file mode 100644 index 00000000..fb110e0b --- /dev/null +++ b/src/wchar/wctob.c @@ -0,0 +1,22 @@ +#include <wchar.h> +#include "locale.h" +#include "string.h" +#include "stdio.h" + +int wctob(wint_t c) +{ + char *l = setlocale(LC_CTYPE, NULL); + + if (!strcmp(l, "C") || !strcmp(l, "POSIX")) { + if (c <= 127) { + return c; + } + } + + /* conversion */ + return EOF; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wint_t.ref b/src/wchar/wint_t.ref new file mode 100644 index 00000000..387f9fa3 --- /dev/null +++ b/src/wchar/wint_t.ref @@ -0,0 +1,3 @@ +#include <wchar.h> +REFERENCE(wctype/wint_t.c) +STDC(199409) diff --git a/src/wchar/wmemchr.c b/src/wchar/wmemchr.c new file mode 100644 index 00000000..b6d9ac7b --- /dev/null +++ b/src/wchar/wmemchr.c @@ -0,0 +1,21 @@ +#include <wchar.h> +#include "nonstd/assert.h" + +wchar_t * wmemchr(const wchar_t * s, wchar_t c, size_t n) +{ + size_t i; + + ASSERT_NONNULL(s); + + for (i = 0; i < n; i++) { + if (s[i] == c) { + return (wchar_t*)s + i; + } + } + + return NULL; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wmemcmp.c b/src/wchar/wmemcmp.c new file mode 100644 index 00000000..d3c2ce52 --- /dev/null +++ b/src/wchar/wmemcmp.c @@ -0,0 +1,20 @@ +#include <wchar.h> + +int wmemcmp(const wchar_t * s1, const wchar_t * s2, size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) { + if (s1[i] > s2[i]) { + return 1; + } else if (s1[i] < s2[i]) { + return -1; + } + } + + return 0; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wmemcpy.c b/src/wchar/wmemcpy.c new file mode 100644 index 00000000..0b583011 --- /dev/null +++ b/src/wchar/wmemcpy.c @@ -0,0 +1,14 @@ +#include <wchar.h> + +wchar_t * wmemcpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n) +{ + size_t i; + for (i = 0; i < n; i++) { + s1[i] = s2[i]; + } + return s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wmemmove.c b/src/wchar/wmemmove.c new file mode 100644 index 00000000..11fd35dc --- /dev/null +++ b/src/wchar/wmemmove.c @@ -0,0 +1,15 @@ +#include <wchar.h> +#include "stdlib.h" + +wchar_t * wmemmove(wchar_t * s1, const wchar_t * s2, size_t n) +{ + wchar_t *tmp = malloc(n * sizeof(wchar_t)); + wmemcpy(tmp, s2, n); + wmemcpy(s1, tmp, n); + free(tmp); + return s1; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wmemset.c b/src/wchar/wmemset.c new file mode 100644 index 00000000..9b6ebe6d --- /dev/null +++ b/src/wchar/wmemset.c @@ -0,0 +1,14 @@ +#include <wchar.h> + +wchar_t * wmemset(wchar_t * s, wchar_t c, size_t n) +{ + size_t i; + for (i = 0; i < n; i++) { + s[i] = c; + } + return s; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wprintf.c b/src/wchar/wprintf.c new file mode 100644 index 00000000..9394e785 --- /dev/null +++ b/src/wchar/wprintf.c @@ -0,0 +1,15 @@ +#include <wchar.h> +#include "stdarg.h" + +int wprintf(const wchar_t * restrict format, ...) +{ + va_list ap; + va_start(ap, format); + int ret = vwprintf(format, ap); + va_end(ap); + return ret; +} + +/* +STDC(199409) +*/ diff --git a/src/wchar/wscanf.c b/src/wchar/wscanf.c new file mode 100644 index 00000000..abd74a33 --- /dev/null +++ b/src/wchar/wscanf.c @@ -0,0 +1,19 @@ +#include <wchar.h> +#include "stdarg.h" + +int wscanf(const wchar_t * restrict format, ...) +{ + /* + va_list ap; + va_start(ap, format); + int ret = vwscanf(format, ap); + va_end(ap); + return ret; + */ + (void)format; + return -1; +} + +/* +STDC(199409) +*/ diff --git a/src/wctype/WEOF.c b/src/wctype/WEOF.c new file mode 100644 index 00000000..021fed95 --- /dev/null +++ b/src/wctype/WEOF.c @@ -0,0 +1,6 @@ +#include <wctype.h> +#define WEOF ((wint_t)(-1)) + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswalnum.c b/src/wctype/iswalnum.c new file mode 100644 index 00000000..dafc242e --- /dev/null +++ b/src/wctype/iswalnum.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "wchar.h" + +/** test whether a wide character is alphanumeric **/ +int iswalnum(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + return iswalpha(wc) || iswdigit(wc); +} + +/*** +The fn(iswalnum) function tests whether arg(wc) is a wide character in the class +cclass(alpha) or cclass(digit) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is an alphanumeric character */ +/* RETURN(0): arg(wc) is not an alphanumeric character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswalpha.c b/src/wctype/iswalpha.c new file mode 100644 index 00000000..6fcc275f --- /dev/null +++ b/src/wctype/iswalpha.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is alphabetic **/ +int iswalpha(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t alpha = wctype("alpha"); + return iswctype(wc, alpha); +} + +/*** +The fn(iswalpha) function tests whether arg(wc) is a wide character in the class +cclass(alpha) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is an alphabetic character */ +/* RETURN(0): arg(wc) is not an alphabetic character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswblank.c b/src/wctype/iswblank.c new file mode 100644 index 00000000..b6a44d3c --- /dev/null +++ b/src/wctype/iswblank.c @@ -0,0 +1,27 @@ +#include <wctype.h> +#include "nonstd/assert.h" + +/** test whether a wide character is blank **/ +int iswblank(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t blank = wctype("blank"); + return iswctype(wc, blank); +} + +/*** +The fn(iswblank) functions tests whether a wide character is a of the character +class cclass(blank) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a blank character */ +/* RETURN(0): arg(wc) is not a blank character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199901) +*/ diff --git a/src/wctype/iswcntrl.c b/src/wctype/iswcntrl.c new file mode 100644 index 00000000..7859148a --- /dev/null +++ b/src/wctype/iswcntrl.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is a control character */ +int iswcntrl(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t cntrl = wctype("cntrl"); + return iswctype(wc, cntrl); +} + +/*** +The fn(iswcntrl) function tests whether arg(wc) is a wide character in the class +cclass(cntrl) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a control character */ +/* RETURN(0): arg(wc) is not a control character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswctype.c b/src/wctype/iswctype.c new file mode 100644 index 00000000..fd24051a --- /dev/null +++ b/src/wctype/iswctype.c @@ -0,0 +1,32 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is part of a character class **/ +int iswctype(wint_t wc, wctype_t desc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + ASSERT_REPRESENTABLE(desc, 1, __libc.wctype.nwctype, "wctype_t", 0); + + /* TODO: actual work */ + (void)wc; (void)desc; + + return 0; +} + +/*** +The fn(iswctype) function tests whether arg(wc) is a wide character in the +character class represented by arg(desc), which must have been previously +returned by fn(wctype), in the current locale. +***/ + +/* RETURN(0): arg(wc) is not in the character class represented by arg(desc) */ +/* RETURN(NZ): arg(wc) is in the character class represented by arg(desc) */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswdigit.c b/src/wctype/iswdigit.c new file mode 100644 index 00000000..1ccdf84d --- /dev/null +++ b/src/wctype/iswdigit.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is a digit **/ +int iswdigit(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t digit = wctype("digit"); + return iswctype(wc, digit); +} + +/*** +The fn(iswdigit) function tests whether arg(wc) is a wide character in the class +cclass(digit) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a digit */ +/* RETURN(0): arg(wc) is not a digit */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswgraph.c b/src/wctype/iswgraph.c new file mode 100644 index 00000000..f20ad02c --- /dev/null +++ b/src/wctype/iswgraph.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is graphic **/ +int iswgraph(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t graph = wctype("graph"); + return iswctype(wc, graph); +} + +/*** +The fn(iswgraph) function tests whether arg(wc) is a wide character in the class +cclass(graph) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a graphic character */ +/* RETURN(0): arg(wc) is not a graphic character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswlower.c b/src/wctype/iswlower.c new file mode 100644 index 00000000..739c36e8 --- /dev/null +++ b/src/wctype/iswlower.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a character is a lowercase letter **/ +int iswlower(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t lower = wctype("lower"); + return iswctype(wc, lower); +} + +/*** +The fn(iswlower) function tests whether arg(wc) is a wide character in the class +cclass(lower) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a lowercase letter */ +/* RETURN(0): arg(wc) is not a lowercase letter */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswprint.c b/src/wctype/iswprint.c new file mode 100644 index 00000000..11bf9033 --- /dev/null +++ b/src/wctype/iswprint.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is printable **/ +int iswprint(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t print = wctype("print"); + return iswctype(wc, print); +} + +/*** +The fn(iswprint) function tests whether arg(wc) is a character in the class +cclass(print) in the current locale. +***/ + +/* RETURN(NZ): arg(c) is a printable character */ +/* RETURN(0): arg(c) is not a printable character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswpunct.c b/src/wctype/iswpunct.c new file mode 100644 index 00000000..5ffdbe85 --- /dev/null +++ b/src/wctype/iswpunct.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is punctuation **/ +int iswpunct(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t punct = wctype("punct"); + return iswctype(wc, punct); +} + +/*** +The fn(iswpunct) function tests whether arg(wc) is a character in the class +cclass(punct) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a punctuation character */ +/* RETURN(0): arg(wc) is not a punctuation character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswspace.c b/src/wctype/iswspace.c new file mode 100644 index 00000000..60bf723a --- /dev/null +++ b/src/wctype/iswspace.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is white-space **/ +int iswspace(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t space = wctype("space"); + return iswctype(wc, space); +} + +/*** +The fn(iswspace) function tests whether arg(wc) is a wide character in the class +cclass(space) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a white-space character */ +/* RETURN(0): arg(wc) is not a white-space character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswupper.c b/src/wctype/iswupper.c new file mode 100644 index 00000000..27fe2359 --- /dev/null +++ b/src/wctype/iswupper.c @@ -0,0 +1,29 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is an uppercase letter **/ +int iswupper(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t upper = wctype("upper"); + return iswctype(wc, upper); +} + +/*** +The fn(iswupper) function tests whether arg(wc) is a wide character in the class +cclass(upper) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is an uppercase letter */ +/* RETURN(0): arg(wc) is not an uppercase letter */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswxdigit.c b/src/wctype/iswxdigit.c new file mode 100644 index 00000000..b544b285 --- /dev/null +++ b/src/wctype/iswxdigit.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is a hexadecimal digit **/ +int iswxdigit(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t xdigit = wctype("xdigit"); + return iswctype(wc, xdigit); +} + +/*** +The fn(iswxdigit) function tests whether arg(wc) is a wide character in the +class cclass(xdigit) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a hexadecimal digit */ +/* RETURN(0): arg(wc) is not a hexadecimal digit */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/towctrans.c b/src/wctype/towctrans.c new file mode 100644 index 00000000..9ea0c8a6 --- /dev/null +++ b/src/wctype/towctrans.c @@ -0,0 +1,30 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +wint_t towctrans(wint_t wc, wctrans_t desc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + ASSERT_REPRESENTABLE(desc, 1, __libc.wctype.nwctrans, "wctrans_t", 0); + + /* TODO: actual work */ + (void)wc; (void)desc; + + return 0; +} + +/*** +The fn(towctrans) function translates the wide character arg(wc) according to +mapping described by arg(desc), which must come from a previous call to +fn(wctrans), in the current locale. +***/ + +/* RETURN: the translated wide character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/towlower.c b/src/wctype/towlower.c new file mode 100644 index 00000000..8e5254d8 --- /dev/null +++ b/src/wctype/towlower.c @@ -0,0 +1,33 @@ +#include <wctype.h> +#include "wchar.h" +#include "stdlib.h" +#include "nonstd/assert.h" + +/** convert a wide uppercase letter to lowercase **/ +wint_t towlower(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + if (!iswupper(wc)) { + return wc; + } + + wctrans_t trans = wctrans("tolower"); + return towctrans(wc, trans); +} + +/*** +The fn(towlower) function converts a wide uppercase letter to its equivalent +lowercase letter in the current locale. +***/ + +/* RETURN(arg(c)): arg(wc) was not a wide uppercase letter or it has no equivalent lowercase letter */ +/* RETURN: arg(wc) converted to lowercase */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/towupper.c b/src/wctype/towupper.c new file mode 100644 index 00000000..1310e109 --- /dev/null +++ b/src/wctype/towupper.c @@ -0,0 +1,32 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** convert a wide lowercase letter to uppercase **/ +wint_t towupper(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + if (!iswlower(wc)) { + return wc; + } + + wctrans_t trans = wctrans("toupper"); + return towctrans(wc, trans); +} + +/*** +The fn(towupper) function converts a wide lowercase letter to its equivalent +uppercase letter in the current locale. +***/ + +/* RETURN(arg(c)): arg(wc) was not a wide lowercase letter or it has no equivalent upercase letter */ +/* RETURN: arg(c) converted to uppercase */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctrans.c b/src/wctype/wctrans.c new file mode 100644 index 00000000..54a6e211 --- /dev/null +++ b/src/wctype/wctrans.c @@ -0,0 +1,38 @@ +#include <wctype.h> +#include "string.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" + +/** lookup character translation **/ +wctrans_t wctrans(const char * property) +{ + ASSERT_NONNULL(property); + + if (!strcmp(property, "tolower")) { + return LOWER; + } else if (!strcmp(property, "toupper")) { + return UPPER; + } + + return 0; +} + +/*** +The fn(wctrans) function looks up the wide character translation mapping +specified by the string arg(property), to be used as the arg(desc) parameter +to fn(towctrans). + +At least the following mappings are supported: ctrans(tolower) and +ctrans(toupper). +***/ + +/* RETURN(0): arg(property) is not a recognized translation */ +/* RETURN(NZ): a mapping identifier to be used as the arg(desc) parameter to fn(towctrans) */ + +/* UNSPECIFED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctrans_t.c b/src/wctype/wctrans_t.c new file mode 100644 index 00000000..f11d5863 --- /dev/null +++ b/src/wctype/wctrans_t.c @@ -0,0 +1,6 @@ +#include <wctype.h> +typedef int wctrans_t; + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctype.c b/src/wctype/wctype.c new file mode 100644 index 00000000..1b27af1d --- /dev/null +++ b/src/wctype/wctype.c @@ -0,0 +1,57 @@ +#include <wctype.h> +#include "string.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" + +/** lookup character class **/ +wctype_t wctype(const char * property) +{ + ASSERT_NONNULL(property); + + if (!strcmp(property, "alnum")) { + return ALPHA | DIGIT; + } else if (!strcmp(property, "alpha")) { + return ALPHA; + } else if (!strcmp(property, "cntrl")) { + return CNTRL; + } else if (!strcmp(property, "digit")) { + return DIGIT; + } else if (!strcmp(property, "graph")) { + return GRAPH; + } else if (!strcmp(property, "lower")) { + return LOWER; + } else if (!strcmp(property, "print")) { + return PRINT; + } else if (!strcmp(property, "punct")) { + return PUNCT; + } else if (!strcmp(property, "space")) { + return SPACE; + } else if (!strcmp(property, "upper")) { + return UPPER; + } else if (!strcmp(property, "xdigit")) { + return XDIGIT; + } + + return 0; +} + +/*** +The fn(wctype) function looks up the character class specified by the string +arg(property). If arg(property) is a recognized character class, a value is +returned that can be used as the arg(desc) parameter to fn(iswctype). + +At least the following character classes are recognized: cclass(alnum), +cclass(alpha), cclass(cntrl), cclass(digit), cclass(graph), cclass(lower), +cclass(print), cclass(punct), cclass(space), cclass(upper), and cclass(xdigit). +***/ + +/* RETURN(0): the requested character class is not recognized */ +/* RETURN(NZ): a value usable as the arg(desc) parameter to fn(iswctype) */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctype_t.c b/src/wctype/wctype_t.c new file mode 100644 index 00000000..6406fc3c --- /dev/null +++ b/src/wctype/wctype_t.c @@ -0,0 +1,6 @@ +#incude <wctype.h> +typedef int wctype_t; + +/* +STDC(199409) +*/ diff --git a/src/wctype/wint_t.c b/src/wctype/wint_t.c new file mode 100644 index 00000000..ba069f94 --- /dev/null +++ b/src/wctype/wint_t.c @@ -0,0 +1,6 @@ +#include <wctype.h> +typedef int wint_t; + +/* +STDC(199409) +*/ |