scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit d9be6267deff0c8d91702a8a62ddf0dfb03ac713
parent c6c3d1d60e49d18e9cd530c776df7778ec71d83b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  3 Dec 2018 10:11:22 +0000

[lib/c] Synchronize lib/c

Diffstat:
Mlib/c/arch/Makefile | 2+-
Mlib/c/arch/amd64/dragonfly/.gitignore | 3++-
Mlib/c/arch/amd64/dragonfly/Makefile | 14++++++++------
Mlib/c/arch/amd64/linux/.gitignore | 4++--
Mlib/c/arch/amd64/netbsd/.gitignore | 4+++-
Mlib/c/arch/amd64/openbsd/.gitignore | 4+++-
Mlib/c/arch/arm64/linux/.gitignore | 3++-
Mlib/c/arch/arm64/linux/Makefile | 4+++-
Mlib/c/arch/arm64/linux/_cerrno.s | 2+-
Mlib/c/arch/arm64/linux/syscall.lst | 1+
Alib/c/arch/mkerrstr | 24++++++++++++++++++++++++
Mlib/c/arch/posix/getenv.c | 14+++++---------
Mlib/c/arch/rules.mk | 7++-----
Mlib/c/ctype/ctype.c | 4+---
Mlib/c/stdlib/strtoull.c | 2+-
Mlib/c/string/strerror.c | 7+++----
Mroot/include/scc/bits/amd64/arch/stdint.h | 13-------------
Mroot/include/scc/bits/arm64/arch/limits.h | 18+++++++++---------
Mroot/include/scc/bits/arm64/arch/stdint.h | 21++++-----------------
Mroot/include/scc/bits/dragonfly/sys/signal.h | 15+++++++++++++++
Mroot/include/scc/bits/linux/sys/signal.h | 2+-
Mroot/include/scc/bits/netbsd/sys/signal.h | 15+++++++++++++++
Mroot/include/scc/bits/openbsd/sys/signal.h | 15+++++++++++++++
Mroot/include/scc/ctype.h | 2+-
Mroot/include/scc/errno.h | 4----
Aroot/include/scc/float.h | 1+
26 files changed, 123 insertions(+), 82 deletions(-)

diff --git a/lib/c/arch/Makefile b/lib/c/arch/Makefile @@ -2,7 +2,7 @@ PROJECTDIR =../../.. include $(PROJECTDIR)/scripts/rules.mk -DIRS = amd64 arm64 +DIRS = amd64 arm32 arm64 all: +@cd $(ARCH) && $(MAKE) diff --git a/lib/c/arch/amd64/dragonfly/.gitignore b/lib/c/arch/amd64/dragonfly/.gitignore @@ -1,9 +1,10 @@ _Exit.s -_close.s _brk.s +_close.s _getpid.s _kill.s _lseek.s _open.s _read.s +_sys_errlist.c _write.s diff --git a/lib/c/arch/amd64/dragonfly/Makefile b/lib/c/arch/amd64/dragonfly/Makefile @@ -1,6 +1,7 @@ .POSIX: PROJECTDIR =../../../../.. include $(PROJECTDIR)/scripts/rules.mk +include ../../rules.mk OBJS = _Exit.o \ _close.o \ @@ -13,11 +14,12 @@ OBJS = _Exit.o \ _brk.o \ _getheap.o \ _sigaction.o\ - _tzone.o\ - getenv.o\ - raise.o\ - signal.o\ - time.o\ + _tzone.o \ + getenv.o \ + raise.o \ + signal.o \ + time.o \ + _sys_errlist.o \ all: syscall $(MAKE) objs @@ -30,4 +32,4 @@ syscall: syscall.lst clean: rm -f `awk '/[0-9]* _/ {print $$2".s"}' syscall.lst` - rm -f syscall + rm -f syscall _sys_errlist.c diff --git a/lib/c/arch/amd64/linux/.gitignore b/lib/c/arch/amd64/linux/.gitignore @@ -1,11 +1,11 @@ _Exit.s +_brk.s _close.s _getpid.s _kill.s _lseek.s _open.s _read.s -_write.s -_brk.s _sigaction.s _sys_errlist.c +_write.s diff --git a/lib/c/arch/amd64/netbsd/.gitignore b/lib/c/arch/amd64/netbsd/.gitignore @@ -1,9 +1,11 @@ _Exit.s -_close.s _brk.s +_close.s _getpid.s +_gettimeofday.s _kill.s _lseek.s _open.s _read.s +_sys_errlist.c _write.s diff --git a/lib/c/arch/amd64/openbsd/.gitignore b/lib/c/arch/amd64/openbsd/.gitignore @@ -1,9 +1,11 @@ _Exit.s -_close.s _brk.s +_close.s _getpid.s _kill.s _lseek.s _open.s _read.s +_sigaction.s +_sys_errlist.c _write.s diff --git a/lib/c/arch/arm64/linux/.gitignore b/lib/c/arch/arm64/linux/.gitignore @@ -1,9 +1,10 @@ _Exit.s -_close.s _brk.s +_close.s _getpid.s _kill.s _lseek.s _openat.s _read.s +_sys_errlist.c _write.s diff --git a/lib/c/arch/arm64/linux/Makefile b/lib/c/arch/arm64/linux/Makefile @@ -1,6 +1,7 @@ .POSIX: PROJECTDIR =../../../../.. include $(PROJECTDIR)/scripts/rules.mk +include ../../rules.mk OBJS = _Exit.o \ _close.o \ @@ -20,6 +21,7 @@ OBJS = _Exit.o \ raise.o \ signal.o \ time.o \ + _sys_errlist.o \ all: syscall $(MAKE) objs @@ -32,4 +34,4 @@ syscall: syscall.lst clean: rm -f `awk '/[0-9]* _/ {print $$2".s"}' syscall.lst` - rm -f syscall + rm -f syscall _sys_errlist.c diff --git a/lib/c/arch/arm64/linux/_cerrno.s b/lib/c/arch/arm64/linux/_cerrno.s @@ -8,6 +8,6 @@ _cerrno: 1: neg x0,x0 adr x1,errno - str w1,[x0] + str w0,[x1] mov x0,#-1 ret diff --git a/lib/c/arch/arm64/linux/syscall.lst b/lib/c/arch/arm64/linux/syscall.lst @@ -7,4 +7,5 @@ 172 _getpid 129 _kill 62 _lseek +134 _sigaction 214 _brk diff --git a/lib/c/arch/mkerrstr b/lib/c/arch/mkerrstr @@ -0,0 +1,24 @@ +#!/bin/sh + +trap 'r=$?; rm -f $$.tmp; exit $r' EXIT HUP INT QUIT TERM + +awk ' +/^#define[ \t]*E/{ + str = "" + for (i = 5; i < NF; i++) + str = str " " $i + sub(/^ /, "", str) + errstr[$2] = str + if ($3 > max) + max = $3; +} + +END { + print "#include <errno.h>\n" + print "char *const _sys_errlist[] = {" + for (i in errstr) + printf "\t%-20.20s = \"%s\",\n", "[" i "]", errstr[i] + + print "};" + print "const int _sys_nerr =", max";" +}' $@ > $$.tmp && mv $$.tmp _sys_errlist.c diff --git a/lib/c/arch/posix/getenv.c b/lib/c/arch/posix/getenv.c @@ -7,16 +7,12 @@ extern char **_environ; char * getenv(const char *name) { - char **p; + char **p, *s; size_t len = strlen(name); - for (p = _environ; *p; ++p) { - if (!memcmp(name, *p, len) && (*p)[len] == '=') - break; + for (p = _environ; s = *p; ++p) { + if (!strncmp(name, s, len) && s[len] == '=') + return s + len + 1; } - - if (!*p) - return NULL; - - return &(*p)[len]; + return NULL; } diff --git a/lib/c/arch/rules.mk b/lib/c/arch/rules.mk @@ -1,7 +1,4 @@ SYSERRNO = $(INCDIR)/bits/$(SYS)/sys/errno.h -$(SYSERRNO): errno.lst - ../../generrno.sh -o $@ errno.lst - -_sys_errlist.c: errno.lst $(SYSERRNO) - ../../generrstr.sh errno.lst +_sys_errlist.c: $(SYSERRNO) + ../../mkerrstr $(SYSERRNO) diff --git a/lib/c/ctype/ctype.c b/lib/c/ctype/ctype.c @@ -1,9 +1,7 @@ #include <ctype.h> -int __ctmp; - /* __ctype is shifted by one to match EOF */ -unsigned char __ctype[257] = { +const unsigned char __ctype[257] = { 0, /* EOF */ _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ diff --git a/lib/c/stdlib/strtoull.c b/lib/c/stdlib/strtoull.c @@ -11,7 +11,7 @@ strtoull(const char *s, char **end, int base) { int d, sign = 1; unsigned long long n; - static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *t, *p; while (isspace(*s)) diff --git a/lib/c/string/strerror.c b/lib/c/string/strerror.c @@ -5,8 +5,7 @@ char * strerror(int errnum) { - if (errnum < _sys_nerr) - return _sys_errlist[errnum]; - else - return "Unknown error"; + if (errnum > _sys_nerr) + errnum = EUNKNOWN; + return _sys_errlist[errnum]; } diff --git a/root/include/scc/bits/amd64/arch/stdint.h b/root/include/scc/bits/amd64/arch/stdint.h @@ -65,19 +65,6 @@ #define WCHAR_MIN INT32_MIN #define WCHAR_MAX INT32_MAX -#define INT8_C(x) x -#define INT16_C(x) x -#define INT32_C(x) x -#define INT64_C(x) x ## L - -#define UINT8_C(x) x -#define UINT16_C(x) x -#define UINT32_C(x) x ## U -#define UINT64_C(x) x ## UL - -#define INTMAX_C(x) x ## L -#define UINTMAX_C(x) x ## UL - typedef signed char int8_t; typedef short int16_t; typedef int int32_t; diff --git a/root/include/scc/bits/arm64/arch/limits.h b/root/include/scc/bits/arm64/arch/limits.h @@ -3,16 +3,16 @@ #define SCHAR_MIN (-SCHAR_MIN - 1) #define CHAR_MAX 0x7F #define CHAR_MIN (-CHAR_MAX - 1) -#define UCHAR_MAX 0xFFU +#define UCHAR_MAX 0xFF #define SHRT_MAX 0x7FFF #define SHRT_MIN (-SHRT_MAX - 1) -#define USHRT_MAX 0xFFFFU +#define USHRT_MAX 0xFFFF #define INT_MAX 0x7FFFFFFF #define INT_MIN (-INT_MAX - 1) -#define UINT_MAX 0xFFFFFFFFU -#define LONG_MAX 0x7FFFFFFFFFFFFFFFL -#define LONG_MIN (-LONG_MAX - 1L) -#define ULONG_MAX 0xFFFFFFFFFFFFFFFFUL -#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL -#define LLONG_MIN (-LLONG_MAX - 1LL) -#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL +#define UINT_MAX 0xFFFFFFFF +#define LONG_MAX 0x7FFFFFFFFFFFFFFF +#define LONG_MIN (-LONG_MAX - 1) +#define ULONG_MAX 0xFFFFFFFFFFFFFFFF +#define LLONG_MAX 0x7FFFFFFFFFFFFFFF +#define LLONG_MIN (-LLONG_MAX - 1) +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF diff --git a/root/include/scc/bits/arm64/arch/stdint.h b/root/include/scc/bits/arm64/arch/stdint.h @@ -8,11 +8,11 @@ #define INT32_MAX 0x7FFFFFFF #define INT32_MIN (-INT32_MAX - 1) -#define UINT32_MAX 0xFFFFFFFFU +#define UINT32_MAX 0xFFFFFFFF -#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL -#define INT64_MIN (-INT64_MAX - 1LL) -#define UINT64_MAX 0xFFFFFFFFFFFFFFFFULL +#define INT64_MAX 0x7FFFFFFFFFFFFFFF +#define INT64_MIN (-INT64_MAX - 1) +#define UINT64_MAX 0xFFFFFFFFFFFFFFFF #define INT_LEAST8_MIN INT8_MIN #define INT_LEAST8_MAX INT8_MAX @@ -59,19 +59,6 @@ #define SIZE_MAX UINT64_MAX -#define INT8_C(x) x -#define INT16_C(x) x -#define INT32_C(x) x -#define INT64_C(x) x ## LL - -#define UINT8_C(x) x -#define UINT16_C(x) x -#define UINT32_C(x) x ## U -#define UINT64_C(x) x ## ULL - -#define INTMAX_C(x) x ## L -#define UINTMAX_C(x) x ## ULL - typedef signed char int8_t; typedef short int16_t; typedef int int32_t; diff --git a/root/include/scc/bits/dragonfly/sys/signal.h b/root/include/scc/bits/dragonfly/sys/signal.h @@ -4,9 +4,24 @@ typedef int sig_atomic_t; #define SIG_DFL ((void (*)(int)) 0) #define SIG_IGN ((void (*)(int)) 1) +#define SIGHUP 1 #define SIGINT 2 +#define SIGQUIT 3 #define SIGILL 4 #define SIGABRT 6 #define SIGFPE 8 +#define SIGKILL 9 #define SIGSEGV 11 +#define SIGPIPE 13 +#define SIGALRM 14 #define SIGTERM 15 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGUSR1 30 +#define SIGUSR2 31 + +#define __NR_SIGNALS 32 diff --git a/root/include/scc/bits/linux/sys/signal.h b/root/include/scc/bits/linux/sys/signal.h @@ -20,7 +20,7 @@ typedef int sig_atomic_t; #define SIGCHLD 17 #define SIGCONT 18 #define SIGSTOP 19 -#define SIGSSTP 20 +#define SIGTSTP 20 #define SIGTTIN 21 #define SIGTTOU 22 diff --git a/root/include/scc/bits/netbsd/sys/signal.h b/root/include/scc/bits/netbsd/sys/signal.h @@ -4,9 +4,24 @@ typedef int sig_atomic_t; #define SIG_DFL ((void (*)(int)) 0) #define SIG_IGN ((void (*)(int)) 1) +#define SIGHUP 1 #define SIGINT 2 +#define SIGQUIT 3 #define SIGILL 4 #define SIGABRT 6 #define SIGFPE 8 +#define SIGKILL 9 #define SIGSEGV 11 +#define SIGPIPE 13 +#define SIGALRM 14 #define SIGTERM 15 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGUSR1 30 +#define SIGUSR2 31 + +#define __NR_SIGNALS 32 diff --git a/root/include/scc/bits/openbsd/sys/signal.h b/root/include/scc/bits/openbsd/sys/signal.h @@ -4,9 +4,24 @@ typedef int sig_atomic_t; #define SIG_DFL ((void (*)(int)) 0) #define SIG_IGN ((void (*)(int)) 1) +#define SIGHUP 1 #define SIGINT 2 +#define SIGQUIT 3 #define SIGILL 4 #define SIGABRT 6 #define SIGFPE 8 +#define SIGKILL 9 #define SIGSEGV 11 +#define SIGPIPE 13 +#define SIGALRM 14 #define SIGTERM 15 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGUSR1 30 +#define SIGUSR2 31 + +#define __NR_SIGNALS 32 diff --git a/root/include/scc/ctype.h b/root/include/scc/ctype.h @@ -26,7 +26,7 @@ extern int toupper(int c); #define _X 0x40 /* hex char */ #define _SP 0x80 /* hard space (0x20) */ -extern unsigned char __ctype[]; +extern const unsigned char __ctype[]; #define isalnum(c) ((__ctype+1)[c] & (_U|_L|_D)) #define isalpha(c) ((__ctype+1)[c] & (_U|_L)) diff --git a/root/include/scc/errno.h b/root/include/scc/errno.h @@ -3,8 +3,4 @@ #include <sys/errno.h> -extern int errno; -extern char *_sys_errlist[]; -extern int _sys_nerr; - #endif diff --git a/root/include/scc/float.h b/root/include/scc/float.h @@ -0,0 +1 @@ +/* TODO: Placeholder for compatibility with libraries that need to include it */