shithub: scc

Download patch

ref: 07c3fc899a4788187f52b99961c7ae1777201d5b
parent: 4eaac6bfb11cc84259e8b418d4babffdf1c637eb
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Dec 3 05:11:22 EST 2018

[lib/c] Synchronize lib/c

--- 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)
--- 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
--- 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 @@
         _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 @@
 
 clean:
 	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
-	rm -f syscall
+	rm -f syscall _sys_errlist.c
--- a/lib/c/arch/amd64/linux/.gitignore
+++ b/lib/c/arch/amd64/linux/.gitignore
@@ -1,4 +1,5 @@
 _Exit.s
+_brk.s
 _close.s
 _getpid.s
 _kill.s
@@ -5,7 +6,6 @@
 _lseek.s
 _open.s
 _read.s
-_write.s
-_brk.s
 _sigaction.s
 _sys_errlist.c
+_write.s
--- 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
--- 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
--- 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
--- 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 @@
         raise.o \
         signal.o \
         time.o \
+        _sys_errlist.o \
 
 all: syscall
 	$(MAKE) objs
@@ -32,4 +34,4 @@
 
 clean:
 	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
-	rm -f syscall
+	rm -f syscall _sys_errlist.c
--- a/lib/c/arch/arm64/linux/_cerrno.s
+++ b/lib/c/arch/arm64/linux/_cerrno.s
@@ -8,6 +8,6 @@
 
 1:	neg	x0,x0
 	adr	x1,errno
-	str	w1,[x0]
+	str	w0,[x1]
 	mov	x0,#-1
 	ret
--- 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
--- /dev/null
+++ b/lib/c/arch/mkerrstr
@@ -1,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
--- a/lib/c/arch/posix/getenv.c
+++ b/lib/c/arch/posix/getenv.c
@@ -7,16 +7,12 @@
 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;
 }
--- 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)
--- 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 */
--- a/lib/c/stdlib/strtoull.c
+++ b/lib/c/stdlib/strtoull.c
@@ -11,7 +11,7 @@
 {
 	int d, sign = 1;
 	unsigned long long n;
-	static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+	static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 	const char *t, *p;
 
 	while (isspace(*s))
--- 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];
 }
--- 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;
--- 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
--- 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
@@ -58,19 +58,6 @@
 #define PTRDIFF_MAX INT64_MAX
 
 #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;
--- a/root/include/scc/bits/dragonfly/sys/signal.h
+++ b/root/include/scc/bits/dragonfly/sys/signal.h
@@ -4,9 +4,24 @@
 #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
--- a/root/include/scc/bits/linux/sys/signal.h
+++ b/root/include/scc/bits/linux/sys/signal.h
@@ -20,7 +20,7 @@
 #define SIGCHLD    17
 #define SIGCONT    18
 #define SIGSTOP    19
-#define SIGSSTP    20
+#define SIGTSTP    20
 #define SIGTTIN    21
 #define SIGTTOU    22
 
--- a/root/include/scc/bits/netbsd/sys/signal.h
+++ b/root/include/scc/bits/netbsd/sys/signal.h
@@ -4,9 +4,24 @@
 #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
--- a/root/include/scc/bits/openbsd/sys/signal.h
+++ b/root/include/scc/bits/openbsd/sys/signal.h
@@ -4,9 +4,24 @@
 #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
--- a/root/include/scc/ctype.h
+++ b/root/include/scc/ctype.h
@@ -26,7 +26,7 @@
 #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))
--- 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
--- /dev/null
+++ b/root/include/scc/float.h
@@ -1,0 +1,1 @@
+/* TODO: Placeholder for compatibility with libraries that need to include it */