diff options
105 files changed, 457 insertions, 195 deletions
diff --git a/.deps/all.c b/.deps/all.c index 942eaba7..55b6cf90 100644 --- a/.deps/all.c +++ b/.deps/all.c @@ -19,6 +19,7 @@ ./src/nonstd/_FTM/_POSIX_C_SOURCE.c ./src/nonstd/_FTM/_POSIX_SOURCE.c ./src/nonstd/_FTM/_XOPEN_SOURCE_EXTENDED.c +./src/nonstd/__load_locale.c ./src/nonstd/struct_FILE.c ./src/nonstd/SYSCALL_NUMBER.c ./src/nonstd/__syscall.c diff --git a/.deps/all.h b/.deps/all.h index a25b589c..5ffc5c5c 100644 --- a/.deps/all.h +++ b/.deps/all.h @@ -30,6 +30,7 @@ nonstd/assert.h nonstd/ctype.h nonstd/internal.h nonstd/io.h +nonstd/lib.h nonstd/locale.h nonstd/syscall.h poll.h diff --git a/.deps/all.ref b/.deps/all.ref index 5ae77ca9..bd32369a 100644 --- a/.deps/all.ref +++ b/.deps/all.ref @@ -1,8 +1,13 @@ -./src/nonstd/nonstd-inernal.ref +./src/nonstd/syscall-internal.ref +./src/nonstd/io-internal.ref +./src/nonstd/lib-internal.ref +./src/nonstd/locale-limits.ref +./src/nonstd/locale-internal.ref ./src/nonstd/pid_t.ref ./src/nonstd/ENOSYS.ref ./src/nonstd/stdio.ref ./src/nonstd/errno.ref +./src/nonstd/ctype-internal.ref ./src/signal/ucontext_t.ref ./src/signal/pid_t.ref ./src/term/bool.ref diff --git a/.deps/nonstd/ctype.h.deps b/.deps/nonstd/ctype.h.deps index b8b88446..626cfee5 100644 --- a/.deps/nonstd/ctype.h.deps +++ b/.deps/nonstd/ctype.h.deps @@ -1 +1,2 @@ ./src/nonstd/ctype_t.c +./src/nonstd/ctype-internal.ref diff --git a/.deps/nonstd/io.h.deps b/.deps/nonstd/io.h.deps index c79016c7..09191a4e 100644 --- a/.deps/nonstd/io.h.deps +++ b/.deps/nonstd/io.h.deps @@ -6,5 +6,6 @@ ./src/nonstd/ftrylockfile.c ./src/nonstd/getc_unlocked.c ./src/nonstd/__scanf.c +./src/nonstd/io-internal.ref ./src/nonstd/pid_t.ref ./src/nonstd/stdio.ref diff --git a/.deps/nonstd/lib.h.deps b/.deps/nonstd/lib.h.deps new file mode 100644 index 00000000..18c50822 --- /dev/null +++ b/.deps/nonstd/lib.h.deps @@ -0,0 +1 @@ +./src/nonstd/lib-internal.ref diff --git a/.deps/nonstd/locale.h.deps b/.deps/nonstd/locale.h.deps index 114cbee5..8f50496b 100644 --- a/.deps/nonstd/locale.h.deps +++ b/.deps/nonstd/locale.h.deps @@ -1 +1,4 @@ ./src/nonstd/struct_locale_t.c +./src/nonstd/__load_locale.c +./src/nonstd/locale-limits.ref +./src/nonstd/locale-internal.ref diff --git a/.deps/nonstd/syscall.h.deps b/.deps/nonstd/syscall.h.deps index eea79e92..47150833 100644 --- a/.deps/nonstd/syscall.h.deps +++ b/.deps/nonstd/syscall.h.deps @@ -3,6 +3,6 @@ ./src/nonstd/__lookup.c ./src/nonstd/syscall_lookup_t.c ./src/nonstd/SYSCALL.c -./src/nonstd/nonstd-inernal.ref +./src/nonstd/syscall-internal.ref ./src/nonstd/ENOSYS.ref ./src/nonstd/errno.ref diff --git a/.headers.mk b/.headers.mk index e9ec5dbb..88982a91 100644 --- a/.headers.mk +++ b/.headers.mk @@ -87,19 +87,22 @@ $(INCDIR)/nl_types.h: mkh.sh $(SRCDIR)/nl_types/nl_catd.c $(SRCDIR)/nl_types/NL_ $(INCDIR)/nonstd/assert.h: mkh.sh $(SRCDIR)/nonstd/ASSERT_REPRESENTABLE.c $(SRCDIR)/nonstd/ASSERT_NONNULL.c $(SRCDIR)/nonstd/ASSERT_NOOVERLAP.c $(SRCDIR)/nonstd/ASSERT_NONZERO.c INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/assert.h -$(INCDIR)/nonstd/ctype.h: mkh.sh $(SRCDIR)/nonstd/ctype_t.c +$(INCDIR)/nonstd/ctype.h: mkh.sh $(SRCDIR)/nonstd/ctype_t.c $(SRCDIR)/nonstd/ctype-internal.ref INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/ctype.h $(INCDIR)/nonstd/internal.h: mkh.sh $(SRCDIR)/nonstd/__libc.c $(SRCDIR)/nonstd/struct_atexit.c $(SRCDIR)/nonstd/LIBC_INTERNAL.c INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/internal.h -$(INCDIR)/nonstd/io.h: mkh.sh $(SRCDIR)/nonstd/struct_io_options.c $(SRCDIR)/nonstd/flockfile.c $(SRCDIR)/nonstd/__printf.c $(SRCDIR)/nonstd/struct_FILE.c $(SRCDIR)/nonstd/funlockfile.c $(SRCDIR)/nonstd/ftrylockfile.c $(SRCDIR)/nonstd/getc_unlocked.c $(SRCDIR)/nonstd/__scanf.c $(SRCDIR)/nonstd/pid_t.ref $(SRCDIR)/nonstd/stdio.ref +$(INCDIR)/nonstd/io.h: mkh.sh $(SRCDIR)/nonstd/struct_io_options.c $(SRCDIR)/nonstd/flockfile.c $(SRCDIR)/nonstd/__printf.c $(SRCDIR)/nonstd/struct_FILE.c $(SRCDIR)/nonstd/funlockfile.c $(SRCDIR)/nonstd/ftrylockfile.c $(SRCDIR)/nonstd/getc_unlocked.c $(SRCDIR)/nonstd/__scanf.c $(SRCDIR)/nonstd/io-internal.ref $(SRCDIR)/nonstd/pid_t.ref $(SRCDIR)/nonstd/stdio.ref INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/io.h -$(INCDIR)/nonstd/locale.h: mkh.sh $(SRCDIR)/nonstd/struct_locale_t.c +$(INCDIR)/nonstd/lib.h: mkh.sh $(SRCDIR)/nonstd/lib-internal.ref + INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/lib.h + +$(INCDIR)/nonstd/locale.h: mkh.sh $(SRCDIR)/nonstd/struct_locale_t.c $(SRCDIR)/nonstd/__load_locale.c $(SRCDIR)/nonstd/locale-limits.ref $(SRCDIR)/nonstd/locale-internal.ref INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/locale.h -$(INCDIR)/nonstd/syscall.h: mkh.sh $(SRCDIR)/nonstd/SYSCALL_NUMBER.c $(SRCDIR)/nonstd/__syscall.c $(SRCDIR)/nonstd/__lookup.c $(SRCDIR)/nonstd/syscall_lookup_t.c $(SRCDIR)/nonstd/SYSCALL.c $(SRCDIR)/nonstd/nonstd-inernal.ref $(SRCDIR)/nonstd/ENOSYS.ref $(SRCDIR)/nonstd/errno.ref +$(INCDIR)/nonstd/syscall.h: mkh.sh $(SRCDIR)/nonstd/SYSCALL_NUMBER.c $(SRCDIR)/nonstd/__syscall.c $(SRCDIR)/nonstd/__lookup.c $(SRCDIR)/nonstd/syscall_lookup_t.c $(SRCDIR)/nonstd/SYSCALL.c $(SRCDIR)/nonstd/syscall-internal.ref $(SRCDIR)/nonstd/ENOSYS.ref $(SRCDIR)/nonstd/errno.ref INCDIR=$(INCDIR) sh mkh.sh $(INCDIR)/nonstd/syscall.h $(INCDIR)/poll.h: mkh.sh $(SRCDIR)/poll/POLLIN.c $(SRCDIR)/poll/POLLWRBAND.c $(SRCDIR)/poll/POLLPRI.c $(SRCDIR)/poll/POLLRDBAND.c $(SRCDIR)/poll/POLLNVAL.c $(SRCDIR)/poll/POLLWRNORM.c $(SRCDIR)/poll/struct_pollfd.c $(SRCDIR)/poll/POLLRDNORM.c $(SRCDIR)/poll/nfds_t.c $(SRCDIR)/poll/POLLERR.c $(SRCDIR)/poll/poll.c $(SRCDIR)/poll/POLLHUP.c $(SRCDIR)/poll/POLLOUT.c @@ -282,6 +285,7 @@ headers: \ $(INCDIR)/nonstd/ctype.h \ $(INCDIR)/nonstd/internal.h \ $(INCDIR)/nonstd/io.h \ + $(INCDIR)/nonstd/lib.h \ $(INCDIR)/nonstd/locale.h \ $(INCDIR)/nonstd/syscall.h \ $(INCDIR)/poll.h \ @@ -72,6 +72,9 @@ get_declaration () { ;; TYPE|TYPE_LONG|RECORD|FNTYPE) + base=$(basename $1 .c) + printf '#ifndef __TYPE_%s_DEFINED__\n#define __TYPE_%s_DEFINED__\n' "$base" "$base" + if grep -q '^#if' $1; then sed -ne '/^#if/,/#endif/p' $1 elif grep -qE '^(typedef|struct|union) .*{' $1; then @@ -81,6 +84,8 @@ get_declaration () { else grep -E '^(typedef|struct|union) ' $1 fi + + printf '#endif\n\n' ;; EXTERN) diff --git a/src/complex/cabs.c b/src/complex/cabs.c index 572163a6..3e2d1ac8 100644 --- a/src/complex/cabs.c +++ b/src/complex/cabs.c @@ -5,7 +5,7 @@ TYPE TGFN(cabs)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/cacos.c b/src/complex/cacos.c index 4dfeea3b..b669f478 100644 --- a/src/complex/cacos.c +++ b/src/complex/cacos.c @@ -5,7 +5,7 @@ TYPE complex TGFN(cacos)(TYPE complex z) { - return I; + return z; } /*d diff --git a/src/complex/cacosh.c b/src/complex/cacosh.c index 31908738..9f7d6aea 100644 --- a/src/complex/cacosh.c +++ b/src/complex/cacosh.c @@ -5,7 +5,7 @@ TYPE complex TGFN(cacosh)(TYPE complex z) { - return 0.0; + return z; } diff --git a/src/complex/carg.c b/src/complex/carg.c index 918e6f4d..092b1194 100644 --- a/src/complex/carg.c +++ b/src/complex/carg.c @@ -5,7 +5,7 @@ TYPE TGFN(carg)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/casin.c b/src/complex/casin.c index 9e13ce58..45084641 100644 --- a/src/complex/casin.c +++ b/src/complex/casin.c @@ -5,7 +5,7 @@ TYPE complex TGFN(casin)(TYPE complex z) { - return 0; + return z; } /*d diff --git a/src/complex/casinh.c b/src/complex/casinh.c index 0b1d1821..9251ce37 100644 --- a/src/complex/casinh.c +++ b/src/complex/casinh.c @@ -5,7 +5,7 @@ TYPE complex TGFN(casinh)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/catan.c b/src/complex/catan.c index 1cfe85b1..4ae60ce6 100644 --- a/src/complex/catan.c +++ b/src/complex/catan.c @@ -5,7 +5,7 @@ TYPE complex TGFN(catan)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/catanh.c b/src/complex/catanh.c index dc218e34..2be96dfc 100644 --- a/src/complex/catanh.c +++ b/src/complex/catanh.c @@ -5,7 +5,7 @@ TYPE complex TGFN(catanh)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/ccos.c b/src/complex/ccos.c index ff2ec58e..329c66e7 100644 --- a/src/complex/ccos.c +++ b/src/complex/ccos.c @@ -5,7 +5,7 @@ TYPE complex TGFN(ccos)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/ccosh.c b/src/complex/ccosh.c index 86c00405..0e05250a 100644 --- a/src/complex/ccosh.c +++ b/src/complex/ccosh.c @@ -5,7 +5,7 @@ TYPE complex TGFN(ccosh)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/cexp.c b/src/complex/cexp.c index ff74c58d..d343a02e 100644 --- a/src/complex/cexp.c +++ b/src/complex/cexp.c @@ -5,7 +5,7 @@ TYPE complex TGFN(cexp)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/clog.c b/src/complex/clog.c index 731a468d..ad8ec1da 100644 --- a/src/complex/clog.c +++ b/src/complex/clog.c @@ -5,7 +5,7 @@ TYPE complex TGFN(clog)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/cpow.c b/src/complex/cpow.c index 70494666..3989f6fb 100644 --- a/src/complex/cpow.c +++ b/src/complex/cpow.c @@ -5,7 +5,7 @@ TYPE complex TGFN(cpow)(TYPE complex x, TYPE complex y) { - return 0.0; + return x * y; } /*d diff --git a/src/complex/cproj.c b/src/complex/cproj.c index 6a84caf8..ce83a62c 100644 --- a/src/complex/cproj.c +++ b/src/complex/cproj.c @@ -5,7 +5,7 @@ TYPE complex TGFN(cproj)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/csin.c b/src/complex/csin.c index 6ca3c3a3..13006c01 100644 --- a/src/complex/csin.c +++ b/src/complex/csin.c @@ -5,7 +5,7 @@ TYPE complex TGFN(csin)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/csinh.c b/src/complex/csinh.c index 0b3e2c08..d1ad8626 100644 --- a/src/complex/csinh.c +++ b/src/complex/csinh.c @@ -5,7 +5,7 @@ TYPE complex TGFN(csinh)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/csqrt.c b/src/complex/csqrt.c index d0e273c9..f3a735ca 100644 --- a/src/complex/csqrt.c +++ b/src/complex/csqrt.c @@ -5,7 +5,7 @@ TYPE complex TGFN(csqrt)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/ctan.c b/src/complex/ctan.c index 2a2d77ef..31bbd8c4 100644 --- a/src/complex/ctan.c +++ b/src/complex/ctan.c @@ -5,7 +5,7 @@ TYPE complex TGFN(ctan)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/complex/ctanh.c b/src/complex/ctanh.c index d1e802e1..cf203dd5 100644 --- a/src/complex/ctanh.c +++ b/src/complex/ctanh.c @@ -5,7 +5,7 @@ TYPE complex TGFN(ctanh)(TYPE complex z) { - return 0.0; + return z; } /*d diff --git a/src/ctype/isblank.c b/src/ctype/isblank.c index 1a597f82..2b48b67f 100644 --- a/src/ctype/isblank.c +++ b/src/ctype/isblank.c @@ -2,7 +2,6 @@ #include "limits.h" #include "locale.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" #include "nonstd/assert.h" /** test whether a character is blank **/ @@ -12,7 +11,7 @@ int isblank(int c) unsigned int *map = __libc(CTYPE); - return map[c] & BLANK; + return map[c] & CT_BLANK; } /*** diff --git a/src/ctype/iscntrl.c b/src/ctype/iscntrl.c index 31804123..eead7f5f 100644 --- a/src/ctype/iscntrl.c +++ b/src/ctype/iscntrl.c @@ -2,7 +2,6 @@ #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) @@ -15,7 +14,7 @@ int iscntrl(int c) RETURN(0, ARGUMENT(c) is not a control character); */ - return map[c] == 0 || (map[c] == SPACE && c != ' '); + return map[c] == 0 || (map[c] == CT_SPACE && c != ' '); } /*** diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c index 8ad3be0b..206a09b7 100644 --- a/src/ctype/isgraph.c +++ b/src/ctype/isgraph.c @@ -2,7 +2,6 @@ #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) @@ -15,7 +14,7 @@ int isgraph(int c) RETURN(0, ARGUMENT(c) is not a graphic character); */ - return map[c] & ~SPACE; + return map[c] & ~CT_SPACE; } /*** diff --git a/src/ctype/islower.c b/src/ctype/islower.c index 082697dd..6b4764d8 100644 --- a/src/ctype/islower.c +++ b/src/ctype/islower.c @@ -1,7 +1,6 @@ #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 **/ @@ -14,7 +13,7 @@ int islower(int c) RETURN(NONZERO, ARGUMENT(c) is a lowercase letter); RETURN(0, ARGUMENT(c) is not a lowercase letter); */ - return map[c] & LOWER; + return map[c] & CT_LOWER; } /*** diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c index 58120351..19847118 100644 --- a/src/ctype/isprint.c +++ b/src/ctype/isprint.c @@ -2,7 +2,6 @@ #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) @@ -15,7 +14,7 @@ int isprint(int c) RETURN(0, ARGUMENT(c) is not a printable character); */ - return map[c] & ~SPACE || c == ' '; + return map[c] & ~CT_SPACE || c == ' '; } /*** diff --git a/src/ctype/ispunct.c b/src/ctype/ispunct.c index bad66523..8a0cd118 100644 --- a/src/ctype/ispunct.c +++ b/src/ctype/ispunct.c @@ -2,7 +2,6 @@ #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) @@ -15,7 +14,7 @@ int ispunct(int c) RETURN(0, ARGUMENT(c) is not a punctuation character); */ - return map[c] & PUNCT; + return map[c] & CT_PUNCT; } /*** diff --git a/src/ctype/isspace.c b/src/ctype/isspace.c index a83cb584..79aa9673 100644 --- a/src/ctype/isspace.c +++ b/src/ctype/isspace.c @@ -2,7 +2,6 @@ #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) @@ -15,7 +14,7 @@ int isspace(int c) RETURN(0, ARGUMENT(c) is not a white-space character); */ - return map[c] & SPACE; + return map[c] & CT_SPACE; } /*** diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c index 84247c28..0d3e7240 100644 --- a/src/ctype/isupper.c +++ b/src/ctype/isupper.c @@ -2,7 +2,6 @@ #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) @@ -15,7 +14,7 @@ int isupper(int c) RETURN(0, ARGUMENT(c) is not an uppercase letter); */ - return map[c] & UPPER; + return map[c] & CT_UPPER; } /*** diff --git a/src/ctype/isxdigit.c b/src/ctype/isxdigit.c index 37857d92..30ddd618 100644 --- a/src/ctype/isxdigit.c +++ b/src/ctype/isxdigit.c @@ -2,7 +2,6 @@ #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) @@ -14,7 +13,7 @@ int isxdigit(int c) RETURN(NONZERO, ARGUMENT(c) is a hexadecimal digit); RETURN(0, ARGUMENT(c) is not a hexadecimal digit); */ - return map[c] & XDIGIT; + return map[c] & CT_XDIGIT; } /*** diff --git a/src/ctype/tolower.c b/src/ctype/tolower.c index b684eb7a..793de6bb 100644 --- a/src/ctype/tolower.c +++ b/src/ctype/tolower.c @@ -2,7 +2,6 @@ #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) diff --git a/src/ctype/toupper.c b/src/ctype/toupper.c index f4611bc7..35b7c9e2 100644 --- a/src/ctype/toupper.c +++ b/src/ctype/toupper.c @@ -1,7 +1,7 @@ #include <ctype.h> #include "limits.h" #include "nonstd/assert.h" -#include "nonstd/internal.h" +#include "nonstd/ctype.h" /** convert a lowercase letter to uppercase **/ int toupper(int c) diff --git a/src/fenv/fegetenv.c b/src/fenv/fegetenv.c index b4795af7..16ffae99 100644 --- a/src/fenv/fegetenv.c +++ b/src/fenv/fegetenv.c @@ -2,6 +2,7 @@ int fegetenv(fenv_t *envp) { + (void)envp; return 0; } diff --git a/src/fenv/fegetexceptflag.c b/src/fenv/fegetexceptflag.c index 45e4bf98..ed41fb83 100644 --- a/src/fenv/fegetexceptflag.c +++ b/src/fenv/fegetexceptflag.c @@ -2,7 +2,8 @@ int fegetexceptflag(fexcept_t *flagp, int excepts) { - return excepts; + (void)flagp; (void)excepts; + return 0; } /*d diff --git a/src/fenv/feholdexcept.c b/src/fenv/feholdexcept.c index 11b46ede..7be0d7f7 100644 --- a/src/fenv/feholdexcept.c +++ b/src/fenv/feholdexcept.c @@ -2,6 +2,7 @@ int feholdexcept(fenv_t *envp) { + (void)envp; return 0; } diff --git a/src/fenv/fesetenv.c b/src/fenv/fesetenv.c index 1d6ea32a..b95bbae6 100644 --- a/src/fenv/fesetenv.c +++ b/src/fenv/fesetenv.c @@ -2,6 +2,7 @@ int fesetenv(const fenv_t *envp) { + (void)envp; return 0; } diff --git a/src/fenv/fesetexceptflag.c b/src/fenv/fesetexceptflag.c index 07fc7f5f..1c2a0ce9 100644 --- a/src/fenv/fesetexceptflag.c +++ b/src/fenv/fesetexceptflag.c @@ -2,6 +2,7 @@ int fesetexceptflag(const fexcept_t *flagp, int excepts) { + (void)flagp; (void)excepts; return 0; } diff --git a/src/fenv/feupdateenv.c b/src/fenv/feupdateenv.c index b11a20fc..ce979808 100644 --- a/src/fenv/feupdateenv.c +++ b/src/fenv/feupdateenv.c @@ -2,6 +2,7 @@ int feupdateenv(const fenv_t *envp) { + (void)envp; return 0; } diff --git a/src/limits/CHAR_MAX.c b/src/limits/CHAR_MAX.c index e746e32e..fc98c91b 100644 --- a/src/limits/CHAR_MAX.c +++ b/src/limits/CHAR_MAX.c @@ -1,8 +1,8 @@ #include <limits.h> -#ifdef __CHAR_IS_SIGNED -#define CHAR_MAX (127) -#else +#ifdef __CHAR_IS_UNSIGNED__ #define CHAR_MAX (255) +#else +#define CHAR_MAX (127) #endif /** char maximum **/ diff --git a/src/limits/CHAR_MIN.c b/src/limits/CHAR_MIN.c index 8db46640..791cbbc2 100644 --- a/src/limits/CHAR_MIN.c +++ b/src/limits/CHAR_MIN.c @@ -1,8 +1,8 @@ #include <limits.h> -#ifdef __CHAR_IS_SIGNED -#define CHAR_MIN (-128) -#else +#ifdef __CHAR_IS_UNSIGNED__ #define CHAR_MIN (0) +#else +#define CHAR_MIN (-128) #endif /** char minimum **/ diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c index 0f64b35e..ae1026da 100644 --- a/src/locale/setlocale.c +++ b/src/locale/setlocale.c @@ -1,62 +1,42 @@ #include <locale.h> #include "string.h" #include "stdlib.h" +#include "nonstd/locale.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; - } + struct __locale_t *l = __libc(GLOBAL_LOCALE); + int mask = 0; 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 */ + switch (category) { + case LC_ALL: return l->all; + case LC_COLLATE: return l->collate; + case LC_CTYPE: return l->ctype; + case LC_MONETARY: return l->monetary; + case LC_NUMERIC: return l->numeric; + case LC_TIME: return l->time; #ifdef LC_MESSAGES - setlocale(LC_MESSAGES, locale); + case LC_MESSAGES: return l->messages; #endif - setlocale(LC_COLLATE, locale); - setlocale(LC_CTYPE, locale); - setlocale(LC_MONETARY, locale); - setlocale(LC_NUMERIC, locale); - return setlocale(LC_TIME, locale); + default: return NULL; + } } - if (desired) { - free(desired); + switch (category) { + case LC_ALL: mask = LC_ALL_MASK; break; + case LC_COLLATE: mask = LC_COLLATE_MASK; break; + case LC_CTYPE: mask = LC_CTYPE_MASK; break; + case LC_MONETARY: mask = LC_MONETARY_MASK; break; + case LC_NUMERIC: mask = LC_NUMERIC_MASK; break; + case LC_TIME: mask = LC_TIME_MASK; break; + #ifdef LC_MESSAGES + case LC_MESSAGES: mask = LC_MESSAGES_MASK; break; + #endif + default: return NULL; } - if (!strcmp(locale, "")) { - desired = getenv(""); - } else { - desired = (char*)locale; - } - - return desired; + return __load_locale(l, mask, locale); } /** get or set program locale **/ diff --git a/src/math/acosh.c b/src/math/acosh.c index 291087b2..aeb15816 100644 --- a/src/math/acosh.c +++ b/src/math/acosh.c @@ -4,7 +4,7 @@ TYPE TGFN(acosh)(TYPE x) { - return 0.0; + return x; } /* diff --git a/src/math/asinh.c b/src/math/asinh.c index 08700a25..421f574d 100644 --- a/src/math/asinh.c +++ b/src/math/asinh.c @@ -4,7 +4,7 @@ TYPE TGFN(asinh)(TYPE x) { - return 0.0; + return x; } /* diff --git a/src/math/atanh.c b/src/math/atanh.c index e99a26b7..eef1cfc6 100644 --- a/src/math/atanh.c +++ b/src/math/atanh.c @@ -4,7 +4,7 @@ TYPE TGFN(atanh)(TYPE x) { - return 0.0; + return x; } /* diff --git a/src/math/copysign.c b/src/math/copysign.c index 6e5cb127..a462348b 100644 --- a/src/math/copysign.c +++ b/src/math/copysign.c @@ -4,7 +4,7 @@ TYPE TGFN(copysign)(TYPE x, TYPE y) { - return 0.0; + return x - y; } /* diff --git a/src/math/nan.c b/src/math/nan.c index c5615b98..bd0cbbc4 100644 --- a/src/math/nan.c +++ b/src/math/nan.c @@ -4,6 +4,7 @@ TYPE TGFN(nan)(const char *tagp) { + (void)tagp; return 0.0; } diff --git a/src/math/nearbyint.c b/src/math/nearbyint.c index c3994a62..d5d2cc21 100644 --- a/src/math/nearbyint.c +++ b/src/math/nearbyint.c @@ -4,7 +4,7 @@ TYPE TGFN(nearbyint)(TYPE x) { - return 0.0; + return x; } /* diff --git a/src/math/remquo.c b/src/math/remquo.c index 88e59c0f..7a117ba7 100644 --- a/src/math/remquo.c +++ b/src/math/remquo.c @@ -4,6 +4,7 @@ TYPE TGFN(remquo)(TYPE x, TYPE y, int *quo) { + (void)quo; return x - y; } diff --git a/src/math/tgamma.c b/src/math/tgamma.c index 25778059..b80584ac 100644 --- a/src/math/tgamma.c +++ b/src/math/tgamma.c @@ -4,7 +4,7 @@ TYPE TGFN(tgamma)(TYPE x) { - return 0.0; + return x; } /* diff --git a/src/math/trunc.c b/src/math/trunc.c index 77671f5d..4b1081a6 100644 --- a/src/math/trunc.c +++ b/src/math/trunc.c @@ -4,7 +4,7 @@ TYPE TGFN(trunc)(TYPE x) { - return 0.0; + return x; } /* diff --git a/src/nonstd/LIBC_INTERNAL.c b/src/nonstd/LIBC_INTERNAL.c index af964cd7..03495623 100644 --- a/src/nonstd/LIBC_INTERNAL.c +++ b/src/nonstd/LIBC_INTERNAL.c @@ -4,6 +4,7 @@ typedef enum { ERRNO, THREAD_LOCALE, GLOBAL_LOCALE, + LOAD_LOCALE, SYSCALL_LOOKUP, PRINTF, SCANF, @@ -11,7 +12,7 @@ typedef enum { CTYPE, TOLOWER, TOUPPER, - FILE_TAIL, + FILE_STREAMS, ATEXIT, RAND } LIBC_INTERNAL; diff --git a/src/nonstd/__libc.c b/src/nonstd/__libc.c index d48d6714..354dee9b 100644 --- a/src/nonstd/__libc.c +++ b/src/nonstd/__libc.c @@ -1,19 +1,21 @@ #include "sys/types.h" #include <nonstd/internal.h> -#include "locale.h" #include "nonstd/locale.h" +#include "nonstd/io.h" #include "_printf.h" +#include "_scanf.h" +#include "_locale.h" #include "_syscall.h" void *__libc(LIBC_INTERNAL variable) { extern void *__libc_per_thread(LIBC_INTERNAL __variable); + static struct __locale_t locale; + static struct __FILE file_streams[FOPEN_MAX]; void *r = (void*)0; - static struct __locale_t locale; - switch (variable) { case ERRNO: return __libc_per_thread(ERRNO); @@ -45,6 +47,14 @@ void *__libc(LIBC_INTERNAL variable) r = (void*)(__printf); break; + case FILE_STREAMS: + r = file_streams; + break; + + case LOAD_LOCALE: + r = (void*)(__load_locale); + break; + default: break; } diff --git a/src/nonstd/__libc_start.c b/src/nonstd/__libc_start.c index e10e081e..c1cf7803 100644 --- a/src/nonstd/__libc_start.c +++ b/src/nonstd/__libc_start.c @@ -3,18 +3,37 @@ #include "nonstd/io.h" +#ifdef _POSIX_SOURCE +#include "unistd.h" +#else +#include "nonstd/syscall.h" +#define isatty(fd) __syscall(__lookup("tty"), fd) +#endif + void __libc_start(int argc, char **argv) { - struct __FILE sin, sout, serr; + struct __FILE *files = __libc(FILE_STREAMS); + + stdin = files + 0; + stdin->fd = 0; + freopen(NULL, "r", stdin); + setvbuf(stdin, NULL, isatty(0) ? _IOLBF : _IOFBF, BUFSIZ); + + stdout = files + 1; + stdout->fd = 1; + freopen(NULL, "w", stdout); + setvbuf(stdin, NULL, isatty(1) ? _IOLBF : _IOFBF, BUFSIZ); - sin.fd = 0; - stdin = &sin; + stderr = files + 2; + stderr->fd = 2; + freopen(NULL, "w", stderr); + setvbuf(stderr, NULL, _IONBF, 0); - sout.fd = 1; - stdout = &sout; + stdin->next = stdout; + stdout->next = stderr; - serr.fd = 2; - stderr = &serr; + stdout->prev = stdin; + stderr->prev = stdout; #if defined _POSIX_SOURCE setlocale(LC_ALL, "POSIX"); diff --git a/src/nonstd/__load_locale.c b/src/nonstd/__load_locale.c new file mode 100644 index 00000000..2233e6b8 --- /dev/null +++ b/src/nonstd/__load_locale.c @@ -0,0 +1,4 @@ +#include <nonstd/locale.h> + +#define __load_locale(_loc, _mask, _name) \ + ((char * (*)(struct __locale_t *, int, const char *))__libc(LOAD_LOCALE))(_loc, _mask, _name) diff --git a/src/nonstd/_locale.h b/src/nonstd/_locale.h new file mode 100644 index 00000000..7bb676ed --- /dev/null +++ b/src/nonstd/_locale.h @@ -0,0 +1,134 @@ +#include <locale.h> +#include <limits.h> +#include <stdio.h> +#include <string.h> + +#include "nonstd/locale.h" +#include "nonstd/ctype.h" + +/* +#define LC_COLLATE_MASK (1<<0) +#define LC_CTYPE_MASK (1<<1) +#define LC_MONETARY_MASK (1<<2) +#define LC_NUMERIC_MASK (1<<3) +#define LC_TIME_MASK (1<<4) +#define LC_MESSAGES_MASK (1<<5) +#define LC_ALL_MASK (0xff) +*/ + +static char * (__load_locale)(struct __locale_t *loc, int mask, const char *name) +{ + char localepath[FILENAME_MAX] = "/lib/locale/"; + strcat(localepath, name); + + FILE *localefile = fopen(localepath, "rb"); + if (localefile == NULL && strcmp(name, "C") && strcmp(name, "POSIX")) { + return NULL; + } + + if (mask & LC_COLLATE_MASK) { + strcpy(loc->collate, name); + + /* read from file */ + loc->lc_collate = NULL; + } + + if (mask & LC_CTYPE_MASK) { + strcpy(loc->ctype, name); + + if (localefile == NULL) { + int i; + + for (i = 0; i < 32; i++) { + loc->lc_ctype.ctattr[i] = CT_CNTRL; + } + for (i = 'a'; i < 'z'; i++) { + loc->lc_ctype.ctattr[i] = CT_LOWER; + } + for (i = 'A'; i < 'Z'; i++) { + loc->lc_ctype.ctattr[i] = CT_UPPER; + } + for (i = '0'; i < '9'; i++) { + loc->lc_ctype.ctattr[i] = CT_DIGIT | CT_XDIGIT; + } + /* others */ + for (i = 0; i < CHAR_MAX; i++) { + loc->lc_ctype.ctoupper[i] = ('a' <= i && i <= 'z') ? i + 32 : i; + } + + for (i = 0; i < CHAR_MAX; i++) { + loc->lc_ctype.ctolower[i] = ('A' <= i && i <= 'Z') ? i - 32 : i; + } + } else { + /* read from file */ + /* + loc->lc_ctype.ctattr + loc->lc_ctype.ctoupper + loc->lc_ctype.ctolower + */ + } + } + + if (mask & LC_MONETARY_MASK) { + strcpy(loc->monetary, name); + + if (localefile == NULL) { + loc->mn.mon_decimal_point = ""; + loc->mn.mon_thousands_sep = ""; + loc->mn.mon_grouping = ""; + loc->mn.positive_sign = ""; + loc->mn.negative_sign = ""; + loc->mn.currency_symbol = ""; + loc->mn.frac_digits = CHAR_MAX; + loc->mn.p_cs_precedes = CHAR_MAX; + loc->mn.n_cs_precedes = CHAR_MAX; + loc->mn.p_sep_by_space = CHAR_MAX; + loc->mn.n_sep_by_space = CHAR_MAX; + loc->mn.p_sign_posn = CHAR_MAX; + loc->mn.n_sign_posn = CHAR_MAX; + loc->mn.int_curr_symbol = ""; + loc->mn.int_frac_digits = CHAR_MAX; + loc->mn.int_p_cs_precedes = CHAR_MAX; + loc->mn.int_n_cs_precedes = CHAR_MAX; + loc->mn.int_p_sep_by_space = CHAR_MAX; + loc->mn.int_n_sep_by_space = CHAR_MAX; + loc->mn.int_p_sign_posn = CHAR_MAX; + loc->mn.int_n_sign_posn = CHAR_MAX; + } else { + /* + loc->mn.monetary fields; + */ + } + } + + if (mask & LC_NUMERIC_MASK) { + strcpy(loc->numeric, name); + + if (localefile == NULL) { + loc->mn.decimal_point = "."; + loc->mn.thousands_sep = ""; + loc->mn.grouping = ""; + } else { + /* + loc->mn.numeric fields + */ + } + } + + if (mask & LC_TIME_MASK) { + strcpy(loc->time, name); + + /* read from file */ + /* loc->lc_time */ + } + + if (mask & LC_MESSAGES_MASK) { + strcpy(loc->messages, name); + + /* read */ + loc->lc_messages.yesexpr = NULL; + loc->lc_messages.noexpr = NULL; + } + + return (char*)name; +} diff --git a/src/nonstd/ctype-internal.ref b/src/nonstd/ctype-internal.ref new file mode 100644 index 00000000..3412e61c --- /dev/null +++ b/src/nonstd/ctype-internal.ref @@ -0,0 +1,2 @@ +#include <nonstd/ctype.h> +REFERENCE(<nonstd/internal.h>) diff --git a/src/nonstd/ctype_t.c b/src/nonstd/ctype_t.c index 468214b1..dad5568f 100644 --- a/src/nonstd/ctype_t.c +++ b/src/nonstd/ctype_t.c @@ -1,15 +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), + CT_ALPHA = (1 << 0), + CT_CNTRL = (1 << 1), + CT_DIGIT = (1 << 2), + CT_GRAPH = (1 << 3), + CT_LOWER = (1 << 4), + CT_PRINT = (1 << 5), + CT_PUNCT = (1 << 6), + CT_SPACE = (1 << 7), + CT_UPPER = (1 << 8), + CT_XDIGIT = (1 << 9), + CT_BLANK = (1 << 10), } ctype_t; diff --git a/src/nonstd/io-internal.ref b/src/nonstd/io-internal.ref new file mode 100644 index 00000000..4c06d2f9 --- /dev/null +++ b/src/nonstd/io-internal.ref @@ -0,0 +1,2 @@ +#include <nonstd/io.h> +REFERENCE(<nonstd/internal.h>) diff --git a/src/nonstd/lib-internal.ref b/src/nonstd/lib-internal.ref new file mode 100644 index 00000000..3361d2f6 --- /dev/null +++ b/src/nonstd/lib-internal.ref @@ -0,0 +1,2 @@ +#include <nonstd/lib.h> +REFERENCE(<nonstd/internal.h>) diff --git a/src/nonstd/locale-internal.ref b/src/nonstd/locale-internal.ref new file mode 100644 index 00000000..d795ee8f --- /dev/null +++ b/src/nonstd/locale-internal.ref @@ -0,0 +1,2 @@ +#include <nonstd/locale.h> +REFERENCE(<nonstd/internal.h>) diff --git a/src/nonstd/locale-limits.ref b/src/nonstd/locale-limits.ref new file mode 100644 index 00000000..705296b4 --- /dev/null +++ b/src/nonstd/locale-limits.ref @@ -0,0 +1,2 @@ +#include <nonstd/locale.h> +REFERENCE(<limits.h>) diff --git a/src/nonstd/locale-locale.ref b/src/nonstd/locale-locale.ref new file mode 100644 index 00000000..98478b9f --- /dev/null +++ b/src/nonstd/locale-locale.ref @@ -0,0 +1,2 @@ +#include <nonstd/locale.h> +REFERENCE(<locale.h>) diff --git a/src/nonstd/struct_locale_t.c b/src/nonstd/struct_locale_t.c index 1981bd8d..1bc8e932 100644 --- a/src/nonstd/struct_locale_t.c +++ b/src/nonstd/struct_locale_t.c @@ -1,22 +1,31 @@ #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; + char all[UCHAR_MAX]; + + char ctype[UCHAR_MAX]; + struct { + unsigned int ctattr[UCHAR_MAX + 1]; + unsigned char ctoupper[UCHAR_MAX + 1]; + unsigned char ctolower[UCHAR_MAX + 1]; + } lc_ctype; + + char collate[UCHAR_MAX]; + struct collation { + char * sequence; + int weight; + } *lc_collate; + + char messages[UCHAR_MAX]; struct { char *yesexpr; char *noexpr; } lc_messages; + char *monetary; char *numeric; struct lconv mn; + char *time; struct { char *abday[7]; diff --git a/src/nonstd/nonstd-inernal.ref b/src/nonstd/syscall-internal.ref index 839537f1..839537f1 100644 --- a/src/nonstd/nonstd-inernal.ref +++ b/src/nonstd/syscall-internal.ref diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c index c7514d10..c4b5ad58 100644 --- a/src/stdio/fflush.c +++ b/src/stdio/fflush.c @@ -1,6 +1,5 @@ #include <stdio.h> #include "nonstd/io.h" -#include "nonstd/internal.h" /** flush buffered writes **/ int fflush(FILE *stream) @@ -8,7 +7,7 @@ int fflush(FILE *stream) flockfile(stream); if (stream == NULL) { FILE *p; - for (p = __libc(FILE_TAIL); p != NULL; p = p->prev) { + for (p = __libc(FILE_STREAMS); p != NULL; p = p->prev) { fflush(p); } } diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 935885d9..1b415969 100644 --- a/src/stdio/fopen.c +++ b/src/stdio/fopen.c @@ -1,29 +1,48 @@ #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; + struct __FILE *base = __libc(FILE_STREAMS); + struct __FILE *f = base; + + /* find the next available stream */ + while (f->next != NULL) { + f = f->next; + } + + /* use a stream from the guaranteed space if possible */ + /* otherwise, allocate a new stream */ + if (f < base + FOPEN_MAX) { + f->next = f + 1; + } else { + f->next = malloc(sizeof(*f->next)); } - if (__libc(FILE_TAIL)) { - f->prev = __libc(FILE_TAIL); - f->prev->next = f; + /* if we had to allocate, but that failed, we're out of memory */ + if (f->next == NULL) { + return NULL; } - /* __libc(FILE_TAIL) = f; */ + /* open the new stream */ + f->next->prev = f; + f = f->next; + f->fd = -1; + if (freopen(filename, mode, f) == NULL) { + if (f < base + FOPEN_MAX) { + } else { + free(f); + } + return NULL; + } /* RETURN_SUCCESS(a pointer to the new file stream); RETURN_FAILURE(CONSTANT(NULL)); */ + return f; } diff --git a/src/stdio/fprintf.c b/src/stdio/fprintf.c index 053277d7..e6651076 100644 --- a/src/stdio/fprintf.c +++ b/src/stdio/fprintf.c @@ -1,7 +1,6 @@ #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, ...) diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c index adbb753c..9e027cf5 100644 --- a/src/stdio/fscanf.c +++ b/src/stdio/fscanf.c @@ -1,6 +1,5 @@ #include <stdio.h> #include "stdarg.h" -#include "nonstd/internal.h" #include "nonstd/io.h" /** read formatted input from a file stream **/ diff --git a/src/stdio/printf.c b/src/stdio/printf.c index 57684158..0a95fbeb 100644 --- a/src/stdio/printf.c +++ b/src/stdio/printf.c @@ -1,6 +1,5 @@ #include <stdio.h> #include "stdarg.h" -#include "nonstd/internal.h" #include "nonstd/io.h" /** write formatted output **/ diff --git a/src/stdio/rename.c b/src/stdio/rename.c index 10ad7283..068cd73d 100644 --- a/src/stdio/rename.c +++ b/src/stdio/rename.c @@ -1,7 +1,6 @@ #include <stdio.h> #include "errno.h" #include "nonstd/syscall.h" -#include "nonstd/internal.h" /** rename a file **/ int rename(const char *old, const char *new) diff --git a/src/stdio/scanf.c b/src/stdio/scanf.c index 5fbe51ec..cc392373 100644 --- a/src/stdio/scanf.c +++ b/src/stdio/scanf.c @@ -1,6 +1,5 @@ #include <stdio.h> #include "stdarg.h" -#include "nonstd/internal.h" #include "nonstd/io.h" /** read formatted input **/ diff --git a/src/stdio/snprintf.c b/src/stdio/snprintf.c index bc6df080..acf234b1 100644 --- a/src/stdio/snprintf.c +++ b/src/stdio/snprintf.c @@ -1,7 +1,19 @@ #include <stdio.h> +#include "stdarg.h" +#include "nonstd/io.h" int snprintf(char * restrict s, size_t n, const char * restrict format, ...) { + int ret = 0; + va_list ap; + struct io_options opt = {0}; + opt.fnname = __func__; + opt.string = s; + opt.maxlen = n; + va_start(ap, format); + ret = __printf(&opt, format, ap); + va_end(ap); + return ret; } /* diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c index babd4ba3..2872331a 100644 --- a/src/stdio/sprintf.c +++ b/src/stdio/sprintf.c @@ -1,7 +1,6 @@ #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, ...) diff --git a/src/stdio/sscanf.c b/src/stdio/sscanf.c index f6637476..02939338 100644 --- a/src/stdio/sscanf.c +++ b/src/stdio/sscanf.c @@ -1,7 +1,6 @@ #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, ...) diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index c6a35edc..450d1383 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -1,7 +1,6 @@ #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) diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index 44ce6ea2..6c0f97ee 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -1,7 +1,14 @@ #include <stdio.h> +#include "nonstd/io.h" int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg) { + int ret = 0; + struct io_options opt = {0}; + opt.fnname = __func__; + opt.stream = stream; + ret = __scanf(&opt, format, arg); + return ret; } /* diff --git a/src/stdio/vprintf.c b/src/stdio/vprintf.c index eb9b4d30..29c1b062 100644 --- a/src/stdio/vprintf.c +++ b/src/stdio/vprintf.c @@ -1,7 +1,6 @@ #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) diff --git a/src/stdio/vsnprintf.c b/src/stdio/vsnprintf.c index 7c5a1e03..f54a15a1 100644 --- a/src/stdio/vsnprintf.c +++ b/src/stdio/vsnprintf.c @@ -1,8 +1,16 @@ #include <stdio.h> #include "stdarg.h" +#include "nonstd/io.h" -int vsnprintf(char * restrict s, size_t n, va_list ap) +int vsnprintf(char * restrict s, size_t n, const char *format, va_list arg) { + int ret = 0; + struct io_options opt = {0}; + opt.fnname = "fprintf"; + opt.string = s; + opt.maxlen = n; + ret = __printf(&opt, format, arg); + return ret; } /* diff --git a/src/stdio/vsprintf.c b/src/stdio/vsprintf.c index 4a6ec2b8..43caff52 100644 --- a/src/stdio/vsprintf.c +++ b/src/stdio/vsprintf.c @@ -1,7 +1,6 @@ #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) diff --git a/src/stdio/vsscanf.c b/src/stdio/vsscanf.c index 534f30ea..d5322078 100644 --- a/src/stdio/vsscanf.c +++ b/src/stdio/vsscanf.c @@ -1,8 +1,15 @@ #include <stdio.h> #include "stdarg.h" +#include "nonstd/io.h" int vsscanf(const char * restrict s, const char * restrict format, va_list arg) { + int ret = 0; + struct io_options opt = {0}; + opt.fnname = __func__; + opt.string = (char*)s; + ret = __scanf(&opt, format, arg); + return ret; } /* diff --git a/src/stdlib/atexit.c b/src/stdlib/atexit.c index 180dc5e2..aeb9172c 100644 --- a/src/stdlib/atexit.c +++ b/src/stdlib/atexit.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include "errno.h" -#include "nonstd/internal.h" +#include "nonstd/lib.h" /** register a function to run at program exit **/ diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c index f69f01c7..501131e4 100644 --- a/src/stdlib/exit.c +++ b/src/stdlib/exit.c @@ -1,7 +1,6 @@ #include <stdlib.h> #include "limits.h" #include "stddef.h" -#include "nonstd/internal.h" #include "nonstd/syscall.h" /** cause normal program termination **/ diff --git a/src/stdlib/rand.c b/src/stdlib/rand.c index 459332ce..f1a3e3e1 100644 --- a/src/stdlib/rand.c +++ b/src/stdlib/rand.c @@ -1,5 +1,5 @@ #include <stdlib.h> -#include "nonstd/internal.h" +#include "nonstd/lib.h" #include "_rand.h" /** get a pseudo-random number **/ diff --git a/src/stdlib/srand.c b/src/stdlib/srand.c index 66ce786e..97ed2fec 100644 --- a/src/stdlib/srand.c +++ b/src/stdlib/srand.c @@ -1,5 +1,5 @@ #include <stdlib.h> -#include "nonstd/internal.h" +#include "nonstd/lib.h" /** seed the pseudo-random number generator **/ diff --git a/src/stdlib/strtof.c b/src/stdlib/strtof.c index b3da169c..4056d578 100644 --- a/src/stdlib/strtof.c +++ b/src/stdlib/strtof.c @@ -2,6 +2,8 @@ float strtof(const char * restrict nptr, char ** restrict endptr) { + (void)nptr; (void)endptr; + return 0; } /* diff --git a/src/stdlib/strtold.c b/src/stdlib/strtold.c index 185f359e..eeb0b8b0 100644 --- a/src/stdlib/strtold.c +++ b/src/stdlib/strtold.c @@ -2,6 +2,8 @@ long double strtold(const char * restrict nptr, char ** restrict endptr) { + (void)nptr; (void)endptr; + return 0; } /* diff --git a/src/string/_strtok.h b/src/string/_strtok.h index 09c0ba96..56ad0dca 100644 --- a/src/string/_strtok.h +++ b/src/string/_strtok.h @@ -1 +1,2 @@ - + (void)state; (void)current; + (void)s1; (void)s2; diff --git a/src/time/strftime.c b/src/time/strftime.c index abf56bc5..61527ca9 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -1,7 +1,6 @@ #include <time.h> #include "stdio.h" #include "nonstd/assert.h" -#include "nonstd/internal.h" #include "locale.h" #include "nonstd/locale.h" diff --git a/src/time/time.c b/src/time/time.c index 355748b9..8af4131b 100644 --- a/src/time/time.c +++ b/src/time/time.c @@ -1,6 +1,5 @@ #include <time.h> #include "errno.h" -#include "nonstd/internal.h" #include "nonstd/syscall.h" /** get current time **/ diff --git a/src/wchar/vfwprintf.c b/src/wchar/vfwprintf.c index fbff917f..df9ab381 100644 --- a/src/wchar/vfwprintf.c +++ b/src/wchar/vfwprintf.c @@ -2,22 +2,16 @@ #include "stdio.h" #include "stdarg.h" #include "stdlib.h" +#include "nonstd/io.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; + int ret = 0; + struct io_options opt = {0}; + opt.fnname = "vfwprintf"; + opt.stream = stream; + ret = __printf(&opt, (const char*)format, arg); + return ret; } /* diff --git a/src/wchar/vfwscanf.c b/src/wchar/vfwscanf.c index 75451ac6..d2e90c5f 100644 --- a/src/wchar/vfwscanf.c +++ b/src/wchar/vfwscanf.c @@ -1,8 +1,15 @@ #include "stdio.h" #include <wchar.h> +#include "nonstd/io.h" int vfwscanf(FILE * restrict stream, const wchar_t * restrict format, va_list arg) { + int ret = 0; + struct io_options opt = {0}; + opt.fnname = __func__; + opt.stream = stream; + ret = __scanf(&opt, (const char*)format, arg); + return ret; } /* diff --git a/src/wchar/vswscanf.c b/src/wchar/vswscanf.c index b0896b75..b0f1271a 100644 --- a/src/wchar/vswscanf.c +++ b/src/wchar/vswscanf.c @@ -1,7 +1,14 @@ #include <wchar.h> +#include "nonstd/io.h" int vswscanf(const wchar_t * restrict s, const wchar_t * restrict format, va_list arg) { + int ret = 0; + struct io_options opt = {0}; + opt.fnname = __func__; + opt.string = (char*)s; + ret = __scanf(&opt, (const char*)format, arg); + return ret; } /* diff --git a/src/wchar/wcstof.c b/src/wchar/wcstof.c index c9de199b..75aafbbf 100644 --- a/src/wchar/wcstof.c +++ b/src/wchar/wcstof.c @@ -2,6 +2,8 @@ float wcstof(const wchar_t * restrict nptr, wchar_t ** restrict endptr) { + (void)nptr; (void)endptr; + return 0; } /* diff --git a/src/wchar/wcstold.c b/src/wchar/wcstold.c index 32001008..b105606f 100644 --- a/src/wchar/wcstold.c +++ b/src/wchar/wcstold.c @@ -2,6 +2,8 @@ long double wcstold(const wchar_t * restrict nptr, wchar_t ** restrict endptr) { + (void)nptr; (void)endptr; + return 0; } /* diff --git a/src/wchar/wmemmove.c b/src/wchar/wmemmove.c index 11fd35dc..75b58f87 100644 --- a/src/wchar/wmemmove.c +++ b/src/wchar/wmemmove.c @@ -1,12 +1,27 @@ #include <wchar.h> #include "stdlib.h" +#include "nonstd/assert.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); + ASSERT_NONNULL(s1); + ASSERT_NONNULL(s2); + + if (s1 < s2) { + return wmemcpy(s1, s2, n); + } + + /* reverse memcpy() */ + while (n > 0) { + s1[n] = s2[n]; + n--; + } + /* last byte */ + s1[n] = s2[n]; + + /* + RETURN_ALWAYS(ARGUMENT(s1)); + */ return s1; } diff --git a/src/wctype/wctrans.c b/src/wctype/wctrans.c index 54a6e211..eb51e112 100644 --- a/src/wctype/wctrans.c +++ b/src/wctype/wctrans.c @@ -9,9 +9,9 @@ wctrans_t wctrans(const char * property) ASSERT_NONNULL(property); if (!strcmp(property, "tolower")) { - return LOWER; + return CT_LOWER; } else if (!strcmp(property, "toupper")) { - return UPPER; + return CT_UPPER; } return 0; diff --git a/src/wctype/wctype.c b/src/wctype/wctype.c index 1b27af1d..82a6ac5b 100644 --- a/src/wctype/wctype.c +++ b/src/wctype/wctype.c @@ -9,27 +9,29 @@ wctype_t wctype(const char * property) ASSERT_NONNULL(property); if (!strcmp(property, "alnum")) { - return ALPHA | DIGIT; + return CT_ALPHA | CT_DIGIT; } else if (!strcmp(property, "alpha")) { - return ALPHA; + return CT_ALPHA; + } else if (!strcmp(property, "blank")) { + return CT_BLANK; } else if (!strcmp(property, "cntrl")) { - return CNTRL; + return CT_CNTRL; } else if (!strcmp(property, "digit")) { - return DIGIT; + return CT_DIGIT; } else if (!strcmp(property, "graph")) { - return GRAPH; + return CT_GRAPH; } else if (!strcmp(property, "lower")) { - return LOWER; + return CT_LOWER; } else if (!strcmp(property, "print")) { - return PRINT; + return CT_PRINT; } else if (!strcmp(property, "punct")) { - return PUNCT; + return CT_PUNCT; } else if (!strcmp(property, "space")) { - return SPACE; + return CT_SPACE; } else if (!strcmp(property, "upper")) { - return UPPER; + return CT_UPPER; } else if (!strcmp(property, "xdigit")) { - return XDIGIT; + return CT_XDIGIT; } return 0; |
