shithub: scc

Download patch

ref: c7b8a9f86b3e6aecc69448a6aa724938a57c9de2
parent: bd41c3ee99a819ae92887538049cdef0ad482763
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Nov 8 11:54:32 EST 2018

[libc] Rewrite build system of libc

--- /dev/null
+++ b/lib/c/.gitignore
@@ -1,0 +1,1 @@
+objlst
--- a/lib/c/Makefile
+++ b/lib/c/Makefile
@@ -1,9 +1,29 @@
 .POSIX:
+PROJECTDIR =../..
+include $(PROJECTDIR)/scripts/rules.mk
 
-PROJECTDIR = ../..
-include $(PROJECTDIR)/rules.mk
+TARGET = $(PROJECTDIR)/lib/libc.a
+DIRS = arch\
+       assert\
+       ctype\
+       locale\
+       stdio\
+       stdlib\
+       string\
+       time\
 
-DIRS = target
+all: $(DIRS)
+	+@$(MAKE) $(TARGET)
 
-all dep clean distclean:
+$(DIRS): FORCE
+	+@cd $@ && $(MAKE)
+
+objlst: FORCE
+	./mklst $(TARGET)
+
+$(TARGET): objlst
+	xargs $(AR) $(ARFLAGS) $@ < objlst
+
+clean:
 	$(FORALL)
+	rm -f objlst
--- a/lib/c/__abs.c
+++ /dev/null
@@ -1,4 +1,0 @@
-#define __USE_MACROS
-#include <stdlib.h>
-
-int __abs;
--- a/lib/c/__assert.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-void __assert(char *exp, char *file, long line)
-{
-	fprintf(stderr, "%s:%ld: assertion failed '%s'\n", file, line, exp);
-	abort();
-}
--- a/lib/c/__getc.c
+++ /dev/null
@@ -1,45 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include "syscall.h"
-#undef getc
-
-int
-__getc(FILE *fp)
-{
-	int cnt;
-
-	if (fp->flags & (_IOEOF | _IOERR))
-		return EOF;
-
-	if ((fp->flags & (_IOREAD | _IORW)) == 0) {
-		fp->flags |= _IOERR;
-		errno = EBADF;
-		return EOF;
-	}
-
-	if (fp->flags & _IOSTRG) {
-		fp->flags |= _IOEOF;
-		return EOF;
-	}
-
-	if (fp->buf == NULL) {
-		if ((fp->buf = malloc(BUFSIZ)) == NULL) {
-			errno = ENOMEM;
-			return EOF;
-		}
-		fp->len = BUFSIZ;
-		fp->flags |= _IOALLOC;
-		fp->lp = fp->rp = fp->wp = fp->buf;
-	}
-
-	if ((cnt = _read(fp->fd, fp->buf, fp->len)) <= 0) {
-		fp->flags |= (cnt == 0) ? _IOEOF : _IOERR;
-		return EOF;
-	}
-
-	fp->flags |= _IOREAD;
-	fp->rp = fp->buf;
-	fp->wp = fp->buf + cnt;
-
-	return *fp->rp++;
-}
--- a/lib/c/__labs.c
+++ /dev/null
@@ -1,4 +1,0 @@
-#define __USE_MACROS
-#include <stdlib.h>
-
-long __labs;
--- a/lib/c/__llabs.c
+++ /dev/null
@@ -1,4 +1,0 @@
-#define __USE_MACROS
-#include <stdlib.h>
-
-long long __llabs;
--- a/lib/c/__putc.c
+++ /dev/null
@@ -1,85 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-extern int _flsbuf(FILE *fp);
-
-int
-fflush(FILE *fp)
-{
-	int err;
-
-	if (fp)
-		return _flsbuf(fp);
-
-	err = 0;
-	for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) {
-		if ((fp->flags & _IOWRITE) == 0 && _flsbuf(fp))
-			err = EOF;
-	}
-	return err;
-}
-
-static void
-cleanup(void)
-{
-	fflush(NULL);
-}
-
-int
-__putc(int ch, FILE *fp)
-{
-	static int first = 1;
-
-	if (fp->flags & _IOERR)
-		return EOF;
-
-	if (fp->flags & _IOREAD) {
-		fp->flags |= _IOERR;
-		errno = EBADF;
-		return EOF;
-	}
-
-	if (fp->flags & _IOSTRG) {
-		fp->flags |= _IOERR;
-		return EOF;
-	}
-
-	if (fp->buf == NULL) {
-		if ((fp->buf = malloc(BUFSIZ)) == NULL) {
-			errno = ENOMEM;
-			return EOF;
-		}
-		fp->len = BUFSIZ;
-		fp->flags |= _IOALLOC;
-		fp->lp = fp->rp = fp->wp = fp->buf;
-	}
-
-	if (first) {
-		if (atexit(cleanup)) {
-			fp->flags |= _IOERR;
-			errno = ENOMEM;
-			return EOF;
-		}
-		first = 0;
-	}
-
-	if (fp->flags & _IOLBF) {
-		if (fp->lp == fp->rp && _flsbuf(fp))
-			return EOF;
-		*fp->lp++ = ch;
-		if (ch == '\n' && _flsbuf(fp))
-			return EOF;
-	} else if (fp->flags & _IOFBF) {
-		if (fp->wp == fp->rp && _flsbuf(fp))
-			return EOF;
-		*fp->wp++ = ch;
-	} else {
-		*fp->wp++ = ch;
-		if (_flsbuf(fp))
-			return EOF;
-	}
-
-	fp->flags |= _IOWRITE;
-	return ch & 0xFF;
-}
--- a/lib/c/_daysyear.c
+++ /dev/null
@@ -1,30 +1,0 @@
-#include <time.h>
-#include "libc.h"
-
-int _daysmon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-int
-_daysyear(int year)
-{
-	if (year%4 != 0)
-		return 365;
-	if (year%100 == 0 && year%400 != 0)
-		return 365;
-	return 366;
-}
-
-/*
- * Happy New Year!!!!
- */
-int
-_newyear(int year)
-{
-	int day;
-
-	year += 1900 - 1;
-	day = 1 + year + year/4;
-	day -= year/100;
-	day += year/400;
-
-	return day % 7;
-}
--- a/lib/c/_flsbuf.c
+++ /dev/null
@@ -1,21 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include "syscall.h"
-
-int
-_flsbuf(FILE *fp)
-{
-	unsigned char *p;
-	size_t cnt;
-
-	p = (fp->flags & _IOLBF) ? fp->lp : fp->wp;
-	cnt = p - fp->buf;
-
-	if (_write(fp->fd, fp->buf, cnt) != cnt) {
-		fp->flags |= _IOERR;
-		return EOF;
-	}
-	fp->lp = fp->rp = fp->wp = fp->buf;
-
-	return 0;
-}
--- a/lib/c/_fpopen.c
+++ /dev/null
@@ -1,75 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys.h>
-#include "syscall.h"
-#include "libc.h"
-#undef fopen
-
-FILE *
-_fpopen(const char * restrict fname,
-        const char * restrict mode,
-        FILE * restrict fp)
-{
-	int i, flags, fd, rw, bin;
-
-	flags = rw = bin = 0;
-
-	if (mode[0] == '\0')
-		goto einval;
-
-	for (i = 1; mode[i]; ++i) {
-		switch (mode[i]) {
-		case '+':
-			if (rw)
-				goto einval;
-			rw = 1;
-			break;
-		case 'b':
-			if (bin)
-				goto einval;
-			bin = 1;
-			break;
-		default:
-			goto einval;
-		}
-	}
-
-	switch (mode[0]) {
-	case 'a':
-		flags |= O_APPEND | O_CREAT;
-		goto wrflags;
-	case 'w':
-		flags |= O_TRUNC | O_CREAT;
-	wrflags:
-		flags |= (rw) ? O_RDWR : O_WRONLY;
-		break;
-	case 'r':
-		flags = (rw) ? O_RDWR : O_RDONLY;
-		break;
-	default:
-	einval:
-		errno = EINVAL;
-		return NULL;
-	}
-
-	if ((fd = _open(fname, flags)) < 0)
-		return NULL;
-
-	fp->buf = NULL;
-	fp->fd = fd;
-
-	if (!bin)
-		fp->flags |= _IOTXT;
-
-	if (flags & O_RDWR)
-		fp->flags |= _IORW;
-	else if (flags & O_RDONLY)
-		fp->flags |= _IOREAD;
-	else
-		fp->flags |= _IOWRITE;
-
-	fp->lp = fp->rp = fp->wp = NULL;
-
-	return fp;
-}
--- a/lib/c/abort.c
+++ /dev/null
@@ -1,10 +1,0 @@
-#include <signal.h>
-#include <stdlib.h>
-#undef abort
-
-void
-abort(void)
-{
-	raise(SIGABRT);
-	_Exit(127);
-}
--- a/lib/c/abs.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdlib.h>
-#undef abs
-
-int
-abs(int n)
-{
-	return (n < 0) ? -n : n;
-}
--- /dev/null
+++ b/lib/c/arch/.gitignore
@@ -1,0 +1,1 @@
+syscall
--- /dev/null
+++ b/lib/c/arch/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+DIRS = amd64 arm64
+
+all:
+	+@cd $(ARCH) && $(MAKE)
+
+clean:
+	$(FORALL)
--- /dev/null
+++ b/lib/c/arch/amd64/Makefile
@@ -1,0 +1,14 @@
+.POSIX:
+PROJECTDIR =../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS = longjmp.o setjmp.o
+DIRS = netbsd openbsd dragonfly linux
+
+all: $(OBJS) $(SYS)
+
+$(SYS): FORCE
+	+@cd $@ && $(MAKE)
+
+clean:
+	$(FORALL)
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/.gitignore
@@ -1,0 +1,9 @@
+_Exit.s
+_close.s
+_brk.s
+_getpid.s
+_kill.s
+_lseek.s
+_open.s
+_read.s
+_write.s
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/Makefile
@@ -1,0 +1,33 @@
+.POSIX:
+PROJECTDIR =../../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS  = _Exit.o \
+        _close.o \
+        _getpid.o \
+        _kill.o \
+        _lseek.o \
+        _open.o \
+        _read.o \
+        _write.o \
+        _brk.o \
+        _getheap.o \
+        _sigaction.o\
+        _tzone.o\
+        getenv.o\
+        raise.o\
+        signal.o\
+        time.o\
+
+all: syscall
+	$(MAKE) objs
+
+objs: $(OBJS)
+
+syscall: syscall.lst
+	./gensys.sh syscall.lst
+	touch syscall
+
+clean:
+	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f syscall
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/_getheap.s
@@ -1,0 +1,6 @@
+	.file	"_getheap.s"
+
+	.globl	_getheap
+_getheap:
+	movq	$end,%rax
+	retq
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/_sigaction.c
@@ -1,0 +1,14 @@
+#include <stddef.h>
+#include <sys.h>
+
+extern int _sigaction2(int sig,
+                       struct sigaction *new, struct sigaction *old,
+                       int siginfo[], int num);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+	extern int _setcontext[];
+
+	return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/_tzone.c
@@ -1,0 +1,1 @@
+#include "../../posix/_tzone.c"
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/gensys.sh
@@ -1,0 +1,26 @@
+#!/bin/sh
+
+#
+# This job is very easy because app and kernel ABI are identical
+# until the 4th parameter, so we only have to set the syscall
+# number in rax
+
+sed 's/[ 	]*#.*//
+     /^$/d' syscall.lst |
+while read num name
+do
+cat <<EOF > $name.s
+	.file	"$name.s"
+
+	.globl	$name
+$name:
+	movq	\$$num,%rax
+	syscall
+	jb	1f
+	retq
+
+1:	movl	%eax,(errno)
+	movl	\$-1,%eax
+	retq
+EOF
+done
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/getenv.c
@@ -1,0 +1,1 @@
+#include "../../posix/getenv.c"
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/raise.c
@@ -1,0 +1,1 @@
+#include "../../posix/raise.c"
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/signal.c
@@ -1,0 +1,1 @@
+#include "../../posix/signal.c"
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/syscall.lst
@@ -1,0 +1,10 @@
+#number	name
+1	_Exit
+3	_read
+4	_write
+5	_open
+6	_close
+17      _brk
+20	_getpid
+37	_kill
+199	_lseek
--- /dev/null
+++ b/lib/c/arch/amd64/dragonfly/time.c
@@ -1,0 +1,1 @@
+#include "../../posix/time.c"
--- /dev/null
+++ b/lib/c/arch/amd64/linux/.gitignore
@@ -1,0 +1,11 @@
+_Exit.s
+_close.s
+_getpid.s
+_kill.s
+_lseek.s
+_open.s
+_read.s
+_write.s
+_brk.s
+_sigaction.s
+_sys_errlist.c
--- /dev/null
+++ b/lib/c/arch/amd64/linux/Makefile
@@ -1,0 +1,37 @@
+.POSIX:
+PROJECTDIR =../../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+include ../../rules.mk
+
+OBJS  = _Exit.o \
+        _close.o \
+        _getpid.o \
+        _kill.o \
+        _lseek.o \
+        _open.o \
+        _sigaction.o \
+        _read.o \
+        _write.o \
+        _brk.o \
+        _getheap.o \
+        _cerrno.o \
+        _sigaction.o \
+        _tzone.o \
+        getenv.o \
+        raise.o \
+        signal.o \
+        time.o \
+        _sys_errlist.o \
+
+all: syscall
+	$(MAKE) objs
+
+objs: $(OBJS)
+
+syscall: syscall.lst
+	./gensys.sh syscall.lst
+	touch syscall
+
+clean:
+	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f syscall _sys_errlist.c
--- /dev/null
+++ b/lib/c/arch/amd64/linux/_cerrno.s
@@ -1,0 +1,12 @@
+	.file	"_cerrno.s"
+	.globl	_cerrno
+
+_cerrno:
+	cmpq	$0,%rax
+	js	1f
+	retq
+
+1:	neg	%rax
+	mov	%eax,(errno)
+	mov	$-1,%eax
+	retq
--- /dev/null
+++ b/lib/c/arch/amd64/linux/_getheap.s
@@ -1,0 +1,6 @@
+	.file	"_getheap.s"
+
+	.globl	_getheap
+_getheap:
+	movq	$0,%rax
+	jmp	_brk
--- /dev/null
+++ b/lib/c/arch/amd64/linux/_sigaction.c
@@ -1,0 +1,14 @@
+#include <stddef.h>
+#include <sys.h>
+
+extern int _sigaction2(int sig,
+                       struct sigaction *new, struct sigaction *old,
+                       int siginfo[], int num);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+	extern int _setcontext[];
+
+	return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- /dev/null
+++ b/lib/c/arch/amd64/linux/_tzone.c
@@ -1,0 +1,1 @@
+#include "../../posix/_tzone.c"
--- /dev/null
+++ b/lib/c/arch/amd64/linux/errno.lst
@@ -1,0 +1,131 @@
+EPERM		 1	 Operation not permitted 
+ENOENT		 2	 No such file or directory 
+ESRCH		 3	 No such process 
+EINTR		 4	 Interrupted system call 
+EIO		 5	 I/O error 
+ENXIO		 6	 No such device or address 
+E2BIG		 7	 Argument list too long 
+ENOEXEC		 8	 Exec format error 
+EBADF		 9	 Bad file number 
+ECHILD		10	 No child processes 
+EAGAIN		11	 Try again 
+ENOMEM		12	 Out of memory 
+EACCES		13	 Permission denied 
+EFAULT		14	 Bad address 
+ENOTBLK		15	 Block device required 
+EBUSY		16	 Device or resource busy 
+EEXIST		17	 File exists 
+EXDEV		18	 Cross-device link 
+ENODEV		19	 No such device 
+ENOTDIR		20	 Not a directory 
+EISDIR		21	 Is a directory 
+EINVAL		22	 Invalid argument 
+ENFILE		23	 File table overflow 
+EMFILE		24	 Too many open files 
+ENOTTY		25	 Not a typewriter 
+ETXTBSY		26	 Text file busy 
+EFBIG		27	 File too large 
+ENOSPC		28	 No space left on device 
+ESPIPE		29	 Illegal seek 
+EROFS		30	 Read-only file system 
+EMLINK		31	 Too many links 
+EPIPE		32	 Broken pipe 
+EDOM		33	 Math argument out of domain of func 
+ERANGE		34	 Math result not representable 
+EDEADLK		35	 Resource deadlock would occur 
+ENAMETOOLONG	36	 File name too long 
+ENOLCK		37	 No record locks available 
+ENOSYS		38	 Invalid system call number 
+ENOTEMPTY	39	 Directory not empty 
+ELOOP		40	 Too many symbolic links encountered 
+ENOMSG		42	 No message of desired type 
+EIDRM		43	 Identifier removed 
+ECHRNG		44	 Channel number out of range 
+EL2NSYNC	45	 Level 2 not synchronized 
+EL3HLT		46	 Level 3 halted 
+EL3RST		47	 Level 3 reset 
+ELNRNG		48	 Link number out of range 
+EUNATCH		49	 Protocol driver not attached 
+ENOCSI		50	 No CSI structure available 
+EL2HLT		51	 Level 2 halted 
+EBADE		52	 Invalid exchange 
+EBADR		53	 Invalid request descriptor 
+EXFULL		54	 Exchange full 
+ENOANO		55	 No anode 
+EBADRQC		56	 Invalid request code 
+EBADSLT		57	 Invalid slot 
+EBFONT		59	 Bad font file format 
+ENOSTR		60	 Device not a stream 
+ENODATA		61	 No data available 
+ETIME		62	 Timer expired 
+ENOSR		63	 Out of streams resources 
+ENONET		64	 Machine is not on the network 
+ENOPKG		65	 Package not installed 
+EREMOTE		66	 Object is remote 
+ENOLINK		67	 Link has been severed 
+EADV		68	 Advertise error 
+ESRMNT		69	 Srmount error 
+ECOMM		70	 Communication error on send 
+EPROTO		71	 Protocol error 
+EMULTIHOP	72	 Multihop attempted 
+EDOTDOT		73	 RFS specific error 
+EBADMSG		74	 Not a data message 
+EOVERFLOW	75	 Value too large for defined data type 
+ENOTUNIQ	76	 Name not unique on network 
+EBADFD		77	 File descriptor in bad state 
+EREMCHG		78	 Remote address changed 
+ELIBACC		79	 Can not access a needed shared library 
+ELIBBAD		80	 Accessing a corrupted shared library 
+ELIBSCN		81	 .lib section in a.out corrupted 
+ELIBMAX		82	 Attempting to link in too many shared libraries 
+ELIBEXEC	83	 Cannot exec a shared library directly 
+EILSEQ		84	 Illegal byte sequence 
+ERESTART	85	 Interrupted system call should be restarted 
+ESTRPIPE	86	 Streams pipe error 
+EUSERS		87	 Too many users 
+ENOTSOCK	88	 Socket operation on non-socket 
+EDESTADDRREQ	89	 Destination address required 
+EMSGSIZE	90	 Message too long 
+EPROTOTYPE	91	 Protocol wrong type for socket 
+ENOPROTOOPT	92	 Protocol not available 
+EPROTONOSUPPORT	93	 Protocol not supported 
+ESOCKTNOSUPPORT	94	 Socket type not supported 
+EOPNOTSUPP	95	 Operation not supported on transport endpoint 
+EPFNOSUPPORT	96	 Protocol family not supported 
+EAFNOSUPPORT	97	 Address family not supported by protocol 
+EADDRINUSE	98	 Address already in use 
+EADDRNOTAVAIL	99	 Cannot assign requested address 
+ENETDOWN	100	 Network is down 
+ENETUNREACH	101	 Network is unreachable 
+ENETRESET	102	 Network dropped connection because of reset 
+ECONNABORTED	103	 Software caused connection abort 
+ECONNRESET	104	 Connection reset by peer 
+ENOBUFS		105	 No buffer space available 
+EISCONN		106	 Transport endpoint is already connected 
+ENOTCONN	107	 Transport endpoint is not connected 
+ESHUTDOWN	108	 Cannot send after transport endpoint shutdown 
+ETOOMANYREFS	109	 Too many references: cannot splice 
+ETIMEDOUT	110	 Connection timed out 
+ECONNREFUSED	111	 Connection refused 
+EHOSTDOWN	112	 Host is down 
+EHOSTUNREACH	113	 No route to host 
+EALREADY	114	 Operation already in progress 
+EINPROGRESS	115	 Operation now in progress 
+ESTALE		116	 Stale file handle 
+EUCLEAN		117	 Structure needs cleaning 
+ENOTNAM		118	 Not a XENIX named type file 
+ENAVAIL		119	 No XENIX semaphores available 
+EISNAM		120	 Is a named type file 
+EREMOTEIO	121	 Remote I/O error 
+EDQUOT		122	 Quota exceeded 
+ENOMEDIUM	123	 No medium found 
+EMEDIUMTYPE	124	 Wrong medium type 
+ECANCELED	125	 Operation Canceled 
+ENOKEY		126	 Required key not available 
+EKEYEXPIRED	127	 Key has expired 
+EKEYREVOKED	128	 Key has been revoked 
+EKEYREJECTED	129	 Key was rejected by service 
+EOWNERDEAD	130	 Owner died 
+ENOTRECOVERABLE	131	 State not recoverable 
+ERFKILL		132	 Operation not possible due to RF-kill 
+EHWPOISON	133	 Memory page has hardware error 
--- /dev/null
+++ b/lib/c/arch/amd64/linux/gensys.sh
@@ -1,0 +1,21 @@
+#!/bin/sh
+
+#
+# This job is very easy because app and kernel ABI are identical
+# until the 4th parameter, so we only have to set the syscall
+# number in rax
+
+sed 's/[ 	]*#.*//
+     /^$/d' syscall.lst |
+while read num name
+do
+cat <<EOF > $name.s
+	.file	"$name.s"
+
+	.globl	$name
+$name:
+	movq	\$$num,%rax
+	syscall
+	jmp	_cerrno
+EOF
+done
--- /dev/null
+++ b/lib/c/arch/amd64/linux/getenv.c
@@ -1,0 +1,1 @@
+#include "../../posix/getenv.c"
--- /dev/null
+++ b/lib/c/arch/amd64/linux/raise.c
@@ -1,0 +1,1 @@
+#include "../../posix/raise.c"
--- /dev/null
+++ b/lib/c/arch/amd64/linux/signal.c
@@ -1,0 +1,1 @@
+#include "../../posix/signal.c"
--- /dev/null
+++ b/lib/c/arch/amd64/linux/syscall.lst
@@ -1,0 +1,11 @@
+#number	name
+0	_read
+1	_write
+2	_open
+3	_close
+8	_lseek
+12      _brk
+13	_sigaction
+39	_getpid
+60	_Exit
+62	_kill
--- /dev/null
+++ b/lib/c/arch/amd64/linux/time.c
@@ -1,0 +1,1 @@
+#include "../../posix/time.c"
--- /dev/null
+++ b/lib/c/arch/amd64/longjmp.s
@@ -1,0 +1,20 @@
+	.file	"longjmp"
+
+	.text
+	.globl	longjmp
+longjmp:
+	mov	%rsi,%rax
+	test	%rax,%rax
+	jnz	1f
+	inc	%rax
+1:
+	mov	(%rdi),%rbx
+	mov	8(%rdi),%rbp
+	mov	16(%rdi),%r12
+	mov	24(%rdi),%r13
+	mov	32(%rdi),%r14
+	mov	40(%rdi),%r15
+	mov	48(%rdi),%rdx
+	mov	%rdx,%rsp
+	mov	56(%rdi),%rdx
+	jmp	*%rdx
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/.gitignore
@@ -1,0 +1,9 @@
+_Exit.s
+_close.s
+_brk.s
+_getpid.s
+_kill.s
+_lseek.s
+_open.s
+_read.s
+_write.s
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/Makefile
@@ -1,0 +1,36 @@
+.POSIX:
+PROJECTDIR =../../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS  = _Exit.o \
+        _close.o \
+        _getpid.o \
+        _kill.o \
+        _lseek.o \
+        _open.o \
+        _read.o \
+        _write.o \
+        _brk.o \
+        _getheap.o \
+        _setcontext.o \
+        _sigaction.o \
+        _sigaction2.o \
+        _sigaction.o\
+        _tzone.o\
+        getenv.o\
+        raise.o\
+        signal.o\
+        time.o\
+
+all: syscall
+	$(MAKE) objs
+
+objs: $(OBJS)
+
+syscall: syscall.lst
+	./gensys.sh syscall.lst
+	touch syscall
+
+clean:
+	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f syscall
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/_getheap.s
@@ -1,0 +1,6 @@
+	.file	"_getheap.s"
+
+	.globl	_getheap
+_getheap:
+	movq	$end,%rax
+	retq
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/_setcontext.s
@@ -1,0 +1,14 @@
+
+	.text
+	.globl	_Exit
+	.globl	_setcontext
+
+_setcontext:
+	movq	%r15,%rdi
+	movq	$0x134,%rax
+	syscall
+
+	# Something was wrong, finish the program. We can't call
+	# abort here because it could generate a loop
+	movq	$-1,%rdi
+	jmp	_Exit
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/_sigaction.c
@@ -1,0 +1,14 @@
+#include <stddef.h>
+#include <sys.h>
+
+extern int _sigaction2(int sig,
+                       struct sigaction *new, struct sigaction *old,
+                       int siginfo[], int num);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+	extern int _setcontext[];
+
+	return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/_sigaction2.s
@@ -1,0 +1,12 @@
+
+# This syscall cannot be autogenerated because it receives more than
+# 4 arguments
+
+	.text
+	.globl	_sigaction2
+
+_sigaction2:
+	mov	$0x154,%eax
+	mov	%rcx,%r10
+	syscall
+	retq
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/_tzone.c
@@ -1,0 +1,1 @@
+#include "../../posix/_tzone.c"
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/gensys.sh
@@ -1,0 +1,26 @@
+#!/bin/sh
+
+#
+# This job is very easy because app and kernel ABI are identical
+# until the 4th parameter, so we only have to set the syscall
+# number in rax
+
+sed 's/[ 	]*#.*//
+     /^$/d' syscall.lst |
+while read num name
+do
+cat <<EOF > $name.s
+	.file	"$name.s"
+
+	.globl	$name
+$name:
+	movq	\$$num,%rax
+	syscall
+	jb	1f
+	retq
+
+1:	movl	%eax,(errno)
+	movl	\$-1,%eax
+	retq
+EOF
+done
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/getenv.c
@@ -1,0 +1,1 @@
+#include "../../posix/getenv.c"
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/raise.c
@@ -1,0 +1,1 @@
+#include "../../posix/raise.c"
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/signal.c
@@ -1,0 +1,1 @@
+#include "../../posix/signal.c"
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/syscall.lst
@@ -1,0 +1,11 @@
+#number	name
+1	_Exit
+3	_read
+4	_write
+5	_open
+6	_close
+17      _brk
+20	_getpid
+37	_kill
+199	_lseek
+418	_gettimeofday
--- /dev/null
+++ b/lib/c/arch/amd64/netbsd/time.c
@@ -1,0 +1,1 @@
+#include "../../posix/time.c"
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/.gitignore
@@ -1,0 +1,9 @@
+_Exit.s
+_close.s
+_brk.s
+_getpid.s
+_kill.s
+_lseek.s
+_open.s
+_read.s
+_write.s
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/Makefile
@@ -1,0 +1,35 @@
+.POSIX:
+PROJECTDIR =../../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+include ../../rules.mk
+
+OBJS  = _Exit.o \
+        _close.o \
+        _getpid.o \
+        _kill.o \
+        _lseek.o \
+        _open.o \
+        _read.o \
+        _write.o \
+        _brk.o \
+        _getheap.o \
+        _sigaction.o\
+        _tzone.o \
+        getenv.o \
+        raise.o \
+        signal.o \
+        time.o \
+        _sys_errlist.o \
+
+all: syscall
+	$(MAKE) objs
+
+objs: $(OBJS)
+
+syscall: syscall.lst
+	./gensys.sh syscall.lst
+	touch syscall
+
+clean:
+	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f syscall _sys_errlist.c
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/_getheap.s
@@ -1,0 +1,6 @@
+	.file	"_getheap.s"
+
+	.globl	_getheap
+_getheap:
+	movq	$end,%rax
+	retq
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/_sigaction.c
@@ -1,0 +1,14 @@
+#include <stddef.h>
+#include <sys.h>
+
+extern int _sigaction2(int sig,
+                       struct sigaction *new, struct sigaction *old,
+                       int siginfo[], int num);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+	extern int _setcontext[];
+
+	return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/_tzone.c
@@ -1,0 +1,1 @@
+#include "../../posix/_tzone.c"
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/errno.lst
@@ -1,0 +1,96 @@
+EPERM		1	 Operation not permitted 
+ENOENT		2	 No such file or directory 
+ESRCH		3	 No such process 
+EINTR		4	 Interrupted system call 
+EIO		5	 Input/output error 
+ENXIO		6	 Device not configured 
+E2BIG		7	 Argument list too long 
+ENOEXEC		8	 Exec format error 
+EBADF		9	 Bad file descriptor 
+ECHILD		10	 No child processes 
+EDEADLK		11	 Resource deadlock avoided 
+ENOMEM		12	 Cannot allocate memory 
+EACCES		13	 Permission denied 
+EFAULT		14	 Bad address 
+ENOTBLK		15	 Block device required 
+EBUSY		16	 Device busy 
+EEXIST		17	 File exists 
+EXDEV		18	 Cross-device link 
+ENODEV		19	 Operation not supported by device 
+ENOTDIR		20	 Not a directory 
+EISDIR		21	 Is a directory 
+EINVAL		22	 Invalid argument 
+ENFILE		23	 Too many open files in system 
+EMFILE		24	 Too many open files 
+ENOTTY		25	 Inappropriate ioctl for device 
+ETXTBSY		26	 Text file busy 
+EFBIG		27	 File too large 
+ENOSPC		28	 No space left on device 
+ESPIPE		29	 Illegal seek 
+EROFS		30	 Read-only file system 
+EMLINK		31	 Too many links 
+EPIPE		32	 Broken pipe 
+EDOM		33	 Numerical argument out of domain 
+ERANGE		34	 Result too large 
+EAGAIN		35	 Resource temporarily unavailable 
+EINPROGRESS	36	 Operation now in progress 
+EALREADY	37	 Operation already in progress 
+ENOTSOCK	38	 Socket operation on non-socket 
+EDESTADDRREQ	39	 Destination address required 
+EMSGSIZE	40	 Message too long 
+EPROTOTYPE	41	 Protocol wrong type for socket 
+ENOPROTOOPT	42	 Protocol not available 
+EPROTONOSUPPORT	43	 Protocol not supported 
+ESOCKTNOSUPPORT	44	 Socket type not supported 
+EOPNOTSUPP	45	 Operation not supported 
+EPFNOSUPPORT	46	 Protocol family not supported 
+EAFNOSUPPORT	47	 Address family not supported by protocol family 
+EADDRINUSE	48	 Address already in use 
+EADDRNOTAVAIL	49	 Can't assign requested address 
+ENETDOWN	50	 Network is down 
+ENETUNREACH	51	 Network is unreachable 
+ENETRESET	52	 Network dropped connection on reset 
+ECONNABORTED	53	 Software caused connection abort 
+ECONNRESET	54	 Connection reset by peer 
+ENOBUFS		55	 No buffer space available 
+EISCONN		56	 Socket is already connected 
+ENOTCONN	57	 Socket is not connected 
+ESHUTDOWN	58	 Can't send after socket shutdown 
+ETOOMANYREFS	59	 Too many references: can't splice 
+ETIMEDOUT	60	 Operation timed out 
+ECONNREFUSED	61	 Connection refused 
+ELOOP		62	 Too many levels of symbolic links 
+ENAMETOOLONG	63	 File name too long 
+EHOSTDOWN	64	 Host is down 
+EHOSTUNREACH	65	 No route to host 
+ENOTEMPTY	66	 Directory not empty 
+EPROCLIM	67	 Too many processes 
+EUSERS		68	 Too many users 
+EDQUOT		69	 Disk quota exceeded 
+ESTALE		70	 Stale NFS file handle 
+EREMOTE		71	 Too many levels of remote in path 
+EBADRPC		72	 RPC struct is bad 
+ERPCMISMATCH	73	 RPC version wrong 
+EPROGUNAVAIL	74	 RPC program not available 
+EPROGMISMATCH	75	 Program version wrong 
+EPROCUNAVAIL	76	 Bad procedure for program 
+ENOLCK		77	 No locks available 
+ENOSYS		78	 Function not implemented 
+EFTYPE		79	 Inappropriate file type or format 
+EAUTH		80	 Authentication error 
+ENEEDAUTH	81	 Need authenticator 
+EIPSEC		82	 IPsec processing failure 
+ENOATTR		83	 Attribute not found 
+EILSEQ		84	 Illegal byte sequence 
+ENOMEDIUM	85	 No medium found 
+EMEDIUMTYPE	86	 Wrong medium type 
+EOVERFLOW	87	 Value too large to be stored in data type 
+ECANCELED	88	 Operation canceled 
+EIDRM		89	 Identifier removed 
+ENOMSG		90	 No message of desired type 
+ENOTSUP		91	 Not supported 
+EBADMSG		92	 Bad message 
+ENOTRECOVERABLE	93	 State not recoverable 
+EOWNERDEAD	94	 Previous owner died 
+EPROTO		95	 Protocol error 
+ELAST		95	 Must be equal largest errno 
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/gensys.sh
@@ -1,0 +1,26 @@
+#!/bin/sh
+
+#
+# This job is very easy because app and kernel ABI are identical
+# until the 4th parameter, so we only have to set the syscall
+# number in rax
+
+sed 's/[ 	]*#.*//
+     /^$/d' syscall.lst |
+while read num name
+do
+cat <<EOF > $name.s
+	.file	"$name.s"
+
+	.globl	$name
+$name:
+	movq	\$$num,%rax
+	syscall
+	jb	1f
+	retq
+
+1:	movl	%eax,(errno)
+	movl	\$-1,%eax
+	retq
+EOF
+done
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/getenv.c
@@ -1,0 +1,1 @@
+#include "../../posix/getenv.c"
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/raise.c
@@ -1,0 +1,1 @@
+#include "../../posix/raise.c"
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/signal.c
@@ -1,0 +1,1 @@
+#include "../../posix/signal.c"
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/syscall.lst
@@ -1,0 +1,11 @@
+#number	name
+1	_Exit
+3	_read
+4	_write
+5	_open
+6	_close
+17      _brk
+20	_getpid
+46	_sigaction
+122	_kill
+198	_lseek
--- /dev/null
+++ b/lib/c/arch/amd64/openbsd/time.c
@@ -1,0 +1,1 @@
+#include "../../posix/time.c"
--- /dev/null
+++ b/lib/c/arch/amd64/setjmp.s
@@ -1,0 +1,17 @@
+	.file	"setjmp.s"
+
+	.text
+	.globl	setjmp
+setjmp:
+	mov	%rbx,(%rdi)
+	mov	%rbp,8(%rdi)
+	mov	%r12,16(%rdi)
+	mov	%r13,24(%rdi)
+	mov	%r14,32(%rdi)
+	mov	%r15,40(%rdi)
+	lea	8(%rsp),%rdx
+	mov	%rdx,48(%rdi)
+	mov	(%rsp),%rdx
+	mov	%rdx,56(%rdi)
+	xor	%rax,%rax
+	ret
--- /dev/null
+++ b/lib/c/arch/arm64/Makefile
@@ -1,0 +1,14 @@
+.POSIX:
+PROJECTDIR =../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS = longjmp.o setjmp.o
+DIRS = linux
+
+all: $(OBJS) $(SYS)
+
+$(SYS): FORCE
+	+@cd $@ && $(MAKE)
+
+clean:
+	$(FORALL)
--- /dev/null
+++ b/lib/c/arch/arm64/linux/.gitignore
@@ -1,0 +1,9 @@
+_Exit.s
+_close.s
+_brk.s
+_getpid.s
+_kill.s
+_lseek.s
+_openat.s
+_read.s
+_write.s
--- /dev/null
+++ b/lib/c/arch/arm64/linux/Makefile
@@ -1,0 +1,35 @@
+.POSIX:
+PROJECTDIR =../../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS  = _Exit.o \
+        _close.o \
+        _brk.o \
+        _getpid.o \
+        _kill.o \
+        _lseek.o \
+        _openat.o \
+        _read.o \
+        _write.o \
+        _getheap.o \
+        _cerrno.o \
+        _open.o \
+        _sigaction.o \
+        _tzone.o \
+        getenv.o \
+        raise.o \
+        signal.o \
+        time.o \
+
+all: syscall
+	$(MAKE) objs
+
+objs: $(OBJS)
+
+syscall: syscall.lst
+	./gensys.sh syscall.lst
+	touch syscall
+
+clean:
+	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f syscall
--- /dev/null
+++ b/lib/c/arch/arm64/linux/_cerrno.s
@@ -1,0 +1,13 @@
+	.file	"_cerrno.s"
+	.globl	_cerrno
+
+_cerrno:
+	cmp	x0,#0
+	b.lt	1f
+	ret
+
+1:	neg	x0,x0
+	adr	x1,errno
+	str	w1,[x0]
+	mov	x0,#-1
+	ret
--- /dev/null
+++ b/lib/c/arch/arm64/linux/_getheap.s
@@ -1,0 +1,6 @@
+	.file	"_getheap.s"
+
+	.globl	_getheap
+_getheap:
+	mov	x0,#0
+	b	_brk
--- /dev/null
+++ b/lib/c/arch/arm64/linux/_open.c
@@ -1,0 +1,13 @@
+#include <stddef.h>
+
+#include "../../../syscall.h"
+
+#define AT_FDCWD  -100
+
+extern int _openat(int fd, const char *fname, int flags);
+
+int
+_open(const char *fname, int flags)
+{
+	return _openat(AT_FDCWD, fname, flags);
+}
--- /dev/null
+++ b/lib/c/arch/arm64/linux/_sigaction.c
@@ -1,0 +1,14 @@
+#include <stddef.h>
+#include <sys.h>
+
+extern int _sigaction2(int sig,
+                       struct sigaction *new, struct sigaction *old,
+                       int siginfo[], int num);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+	extern int _setcontext[];
+
+	return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- /dev/null
+++ b/lib/c/arch/arm64/linux/_tzone.c
@@ -1,0 +1,1 @@
+#include "../../posix/_tzone.c"
--- /dev/null
+++ b/lib/c/arch/arm64/linux/gensys.sh
@@ -1,0 +1,21 @@
+#!/bin/sh
+
+#
+# This job is very easy because app and kernel ABI are identical
+# until the 4th parameter, so we only have to set the syscall
+# number in rax
+
+sed 's/[ 	]*#.*//
+     /^$/d' syscall.lst |
+while read num name
+do
+cat <<EOF > $name.s
+	.file	"$name.s"
+
+	.globl	$name
+$name:
+	mov	x8,#$num
+	svc	0
+	b	_cerrno
+EOF
+done
--- /dev/null
+++ b/lib/c/arch/arm64/linux/getenv.c
@@ -1,0 +1,1 @@
+#include "../../posix/getenv.c"
--- /dev/null
+++ b/lib/c/arch/arm64/linux/raise.c
@@ -1,0 +1,1 @@
+#include "../../posix/raise.c"
--- /dev/null
+++ b/lib/c/arch/arm64/linux/signal.c
@@ -1,0 +1,1 @@
+#include "../../posix/signal.c"
--- /dev/null
+++ b/lib/c/arch/arm64/linux/syscall.lst
@@ -1,0 +1,10 @@
+#number name
+56	_openat
+57	_close
+63	_read
+64	_write
+93	_Exit
+172	_getpid
+129	_kill
+62	_lseek
+214	_brk
--- /dev/null
+++ b/lib/c/arch/arm64/linux/time.c
@@ -1,0 +1,1 @@
+#include "../../posix/time.c"
--- /dev/null
+++ b/lib/c/arch/arm64/longjmp.s
@@ -1,0 +1,22 @@
+	.file   "longjmp.s"
+
+	.text
+	.globl	longjmp
+longjmp:
+	ldp x19, x20, [x0,#0]
+	ldp x21, x22, [x0,#16]
+	ldp x23, x24, [x0,#32]
+	ldp x25, x26, [x0,#48]
+	ldp x27, x28, [x0,#64]
+	ldp x29, x30, [x0,#80]
+	ldr x2, [x0,#104]
+	mov sp, x2
+	ldp d8 , d9, [x0,#112]
+	ldp d10, d11, [x0,#128]
+	ldp d12, d13, [x0,#144]
+	ldp d14, d15, [x0,#160]
+
+	mov x0, x1
+	cbnz x1, 1f
+	mov x0, #1
+1:	br x30
--- /dev/null
+++ b/lib/c/arch/arm64/setjmp.s
@@ -1,0 +1,20 @@
+	.file   "setjmp.s"
+
+	.text
+	.globl	setjmp
+setjmp:
+	// IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
+	stp x19, x20, [x0,#0]
+	stp x21, x22, [x0,#16]
+	stp x23, x24, [x0,#32]
+	stp x25, x26, [x0,#48]
+	stp x27, x28, [x0,#64]
+	stp x29, x30, [x0,#80]
+	mov x2, sp
+	str x2, [x0,#104]
+	stp  d8,  d9, [x0,#112]
+	stp d10, d11, [x0,#128]
+	stp d12, d13, [x0,#144]
+	stp d14, d15, [x0,#160]
+	mov x0, #0
+	ret
--- /dev/null
+++ b/lib/c/arch/generrno.sh
@@ -1,0 +1,35 @@
+#!/bin/sh
+
+trap 'r=$?; rm -f $$.tmp; exit $r' EXIT HUP QUIT INT TERM
+
+for i
+do
+	case $i in
+	-o)
+		out=$2
+		shift 2
+		;;
+	--)
+		shift
+		break
+		;;
+	-*)
+		echo usage: generrno.sh [-o output] file ...
+		exit 1
+		;;
+	*)
+		break
+		;;
+	esac
+done
+
+awk '
+/^E/ && $2 > 0 {
+	errno[$1] = $2
+}
+
+END {
+	for (i in errno)
+		print "#define", i, errno[i] | "sort -n -k3"
+	close("sort -n -k3")
+}' $@ > $$.tmp && mv $$.tmp ${out:-errno.h}
--- /dev/null
+++ b/lib/c/arch/generrstr.sh
@@ -1,0 +1,23 @@
+#!/bin/sh
+
+trap 'r=$?; rm -f $$.tmp; exit $r' EXIT HUP INT QUIT TERM
+
+awk '
+/^E/ && $2 > 0 {
+	str = ""
+	for (i = 3; i <= NF; i++)
+		str = str " " $i
+	sub(/^ /, "", str)
+	errstr[$1] = str
+	if ($2 > max)
+		max = $2;
+}
+
+END {
+	print "#include <errno.h>\n"
+	print "char *_sys_errlist[] = {"
+	for (i in errstr)
+		printf "\t%-20.20s = \"%s\",\n", "[" i "]", errstr[i]
+	print "};"
+	print "int _sys_nerr =", $2 + 1 ";"
+}' $@ > $$.tmp && mv $$.tmp _sys_errlist.c
--- /dev/null
+++ b/lib/c/arch/posix/_tzone.c
@@ -1,0 +1,27 @@
+#include <stdlib.h>
+#include <time.h>
+#include "../../libc.h"
+
+struct tzone *
+_tzone(struct tm *tm)
+{
+	static struct tzone tz;
+	static int first = 1;
+
+	if (!first)
+		return &tz;
+
+	tz.name = getenv("TZ");
+	if (!tz.name || *tz.name == '\0') {
+		tz.name = NULL;
+		tz.gmtoff = 0;
+		tz.isdst = 0;
+	} else {
+		/* TODO: parse TZ string */
+		tz.gmtoff = 0;
+		tz.isdst = 0;
+	}
+	first = 0;
+
+	return &tz;
+}
--- /dev/null
+++ b/lib/c/arch/posix/getenv.c
@@ -1,0 +1,22 @@
+#include <stdlib.h>
+#include <string.h>
+#undef getenv
+
+extern char **_environ;
+
+char *
+getenv(const char *name)
+{
+	char **p;
+	size_t len = strlen(name);
+
+	for (p = _environ; *p; ++p) {
+		if (!memcmp(name, *p, len) && (*p)[len] == '=')
+			break;
+	}
+
+	if (!*p) 
+		return NULL;
+
+	return &(*p)[len];
+}
--- /dev/null
+++ b/lib/c/arch/posix/geterrno.sh
@@ -1,0 +1,8 @@
+#!/bin/sh
+
+awk '/define[ 	]*E/ && $3 ~ /[0-9]+/ && $3 > 0 {
+	sub(/\#define[ 	]*/, "")
+	sub(/\/\*/, "")
+	sub(/\*\//, "")
+	print
+}' /usr/include/sys/errno.h
--- /dev/null
+++ b/lib/c/arch/posix/raise.c
@@ -1,0 +1,11 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys.h>
+
+#undef raise
+
+int
+raise(int signum)
+{
+	return _kill(_getpid(), signum);
+}
--- /dev/null
+++ b/lib/c/arch/posix/signal.c
@@ -1,0 +1,17 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys.h>
+#undef signal
+
+void
+(*signal(int signum, void (*func)(int)))(int)
+{
+	struct sigaction sa = {
+		.sa_handler = func,
+	};
+
+	if (_sigaction(signum, &sa, &sa) < 0)
+		return SIG_ERR;
+
+	return sa.sa_handler;
+}
--- /dev/null
+++ b/lib/c/arch/posix/time.c
@@ -1,0 +1,21 @@
+#include <time.h>
+
+struct timeval {
+	time_t tv_sec;
+	int tv_usec; /* TODO use a arch type */
+};
+
+int
+_gettimeofday(struct timeval * restrict tp, void * restrict tzp);
+
+time_t
+time(time_t *t)
+{
+	struct timeval tv;
+
+	if (_gettimeofday(&tv, NULL) == -1)
+		return -1;
+	if (t)
+		*t =tv.tv_sec;
+	return tv.tv_sec;
+}
--- /dev/null
+++ b/lib/c/arch/rules.mk
@@ -1,0 +1,7 @@
+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
--- a/lib/c/asctime.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <time.h>
-#undef asctime
-
-#include <stdio.h> // TODO: remove me!
-char *
-asctime(const struct tm *tm)
-{
-	static char buf[30];
-
-	strftime(buf, sizeof(buf), "%c\n", tm);
-	return buf;
-}
--- /dev/null
+++ b/lib/c/assert/Makefile
@@ -1,0 +1,10 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = __assert.o\
+       assert.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/assert/__assert.c
@@ -1,0 +1,9 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void __assert(char *exp, char *file, long line)
+{
+	fprintf(stderr, "%s:%ld: assertion failed '%s'\n", file, line, exp);
+	abort();
+}
--- /dev/null
+++ b/lib/c/assert/assert.c
@@ -1,0 +1,13 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#undef assert
+
+void
+assert(int exp)
+{
+	if (exp)
+		return;
+	fputs("assert failed\n", stderr);
+	abort();
+}
--- a/lib/c/atexit.c
+++ /dev/null
@@ -1,17 +1,0 @@
-#include <stdlib.h>
-#include <errno.h>
-#undef atexit
-
-extern void (*_exitf[_ATEXIT_MAX])(void);
-extern unsigned _exitn;
-
-int
-atexit(void (*fun)(void))
-{
-	if (_exitn == _ATEXIT_MAX) {
-		errno = ENOMEM;
-		return -1;
-	}
-	_exitf[_exitn++] = fun;
-	return 0;
-}
--- a/lib/c/atoi.c
+++ /dev/null
@@ -1,25 +1,0 @@
-#include <ctype.h>
-#include <stdlib.h>
-#undef atoi
-
-int
-atoi(const char *s)
-{
-	int n, sign = -1;
-
-	while (isspace(*s))
-		++s;
-
-	switch (*s) {
-	case '-':
-		sign = 1;
-	case '+':
-		++s;
-	}
-
-	/* Compute n as a negative number to avoid overflow on INT_MIN */
-	for (n = 0; isdigit(*s); ++s)
-		n = 10*n - (*s - '0');
-
-	return sign * n;
-}
--- a/lib/c/atol.c
+++ /dev/null
@@ -1,26 +1,0 @@
-#include <ctype.h>
-#include <stdlib.h>
-#undef atol
-
-long
-atol(const char *s)
-{
-	int sign = -1;
-	long n;
-
-	while (isspace(*s))
-		++s;
-
-	switch (*s) {
-	case '-':
-		sign = 1;
-	case '+':
-		++s;
-	}
-
-	/* Compute n as a negative number to avoid overflow on LONG_MIN */
-	for (n = 0; isdigit(*s); ++s)
-		n = 10*n - (*s - '0');
-
-	return sign * n;
-}
--- a/lib/c/atoll.c
+++ /dev/null
@@ -1,26 +1,0 @@
-#include <ctype.h>
-#include <stdlib.h>
-#undef atoll
-
-long long
-atoll(const char *s)
-{
-	int sign = -1;
-	long long n;
-
-	while (isspace(*s))
-		++s;
-
-	switch (*s) {
-	case '-':
-		sign = 1;
-	case '+':
-		++s;
-	}
-
-	/* Compute n as a negative number to avoid overflow on LLONG_MIN */
-	for (n = 0; isdigit(*s); ++s)
-		n = 10*n - (*s - '0');
-
-	return sign * n;
-}
--- a/lib/c/bsearch.c
+++ /dev/null
@@ -1,26 +1,0 @@
-#include <stdlib.h>
-
-void *
-bsearch(const void *key, const void *ary, size_t n, size_t size,
-        int (*cmp)(const void *, const void *))
-{
-	int t;
-	size_t mid, low, high;
-	char *cur, *base = ary;
-
-	low = 0;
-	high = n - 1;
-	while (low <= high) {
-		mid = low + (high - low) / 2;
-		cur = base + mid*size;
-
-		if ((t = (*cmp)(key, cur)) == 0)
-			return cur;
-		else if (t > 0)
-			low = mid + 1;
-		else
-			high = mid - 1;
-	}
-
-	return NULL;
-}
--- a/lib/c/calloc.c
+++ /dev/null
@@ -1,18 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-#undef calloc
-
-void *
-calloc(size_t nmemb, size_t size)
-{
-	size_t nbytes;
-	void *mem;
-
-	if (!nmemb || !size || nmemb > (size_t)-1/size)
-                return NULL;
-
-	nbytes = nmemb * size;
-	if ((mem = malloc(nbytes)) == NULL)
-		return NULL;
-	return memset(mem, 0, nbytes);
-}
--- a/lib/c/clearerr.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef clearerr
-
-void
-clearerr(FILE *fp)
-{
-	fp->flags &= ~(_IOERR | _IOEOF);
-}
--- a/lib/c/ctime.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <time.h>
-#undef ctime
-
-char *
-ctime(const time_t *t)
-{
-	return asctime(localtime(t));
-}
--- a/lib/c/ctype.c
+++ /dev/null
@@ -1,25 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-
-int __ctmp;
-
-/* __ctype is shifted by one to match EOF */
-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 */
-	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 16-23 */
-	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 24-31 */
-	_S|_SP,_P,_P,_P,_P,_P,_P,_P,                    /* 32-39 */
-	_P,_P,_P,_P,_P,_P,_P,_P,                        /* 40-47 */
-	_D,_D,_D,_D,_D,_D,_D,_D,                        /* 48-55 */
-	_D,_D,_P,_P,_P,_P,_P,_P,                        /* 56-63 */
-	_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,      /* 64-71 */
-	_U,_U,_U,_U,_U,_U,_U,_U,                        /* 72-79 */
-	_U,_U,_U,_U,_U,_U,_U,_U,                        /* 80-87 */
-	_U,_U,_U,_P,_P,_P,_P,_P,                        /* 88-95 */
-	_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,      /* 96-103 */
-	_L,_L,_L,_L,_L,_L,_L,_L,                        /* 104-111 */
-	_L,_L,_L,_L,_L,_L,_L,_L,                        /* 112-119 */
-	_L,_L,_L,_P,_P,_P,_P,_C,                        /* 120-127 */
-};
--- /dev/null
+++ b/lib/c/ctype/Makefile
@@ -1,0 +1,24 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = ctype.o\
+       isalnum.o\
+       isalpha.o\
+       isascii.o\
+       isblank.o\
+       iscntrl.o\
+       isdigit.o\
+       isgraph.o\
+       islower.o\
+       isprint.o\
+       ispunct.o\
+       isspace.o\
+       isupper.o\
+       isxdigit.o\
+       tolower.o\
+       toupper.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/ctype/ctype.c
@@ -1,0 +1,24 @@
+#include <ctype.h>
+
+int __ctmp;
+
+/* __ctype is shifted by one to match EOF */
+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 */
+	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 16-23 */
+	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 24-31 */
+	_S|_SP,_P,_P,_P,_P,_P,_P,_P,                    /* 32-39 */
+	_P,_P,_P,_P,_P,_P,_P,_P,                        /* 40-47 */
+	_D,_D,_D,_D,_D,_D,_D,_D,                        /* 48-55 */
+	_D,_D,_P,_P,_P,_P,_P,_P,                        /* 56-63 */
+	_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,      /* 64-71 */
+	_U,_U,_U,_U,_U,_U,_U,_U,                        /* 72-79 */
+	_U,_U,_U,_U,_U,_U,_U,_U,                        /* 80-87 */
+	_U,_U,_U,_P,_P,_P,_P,_P,                        /* 88-95 */
+	_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,      /* 96-103 */
+	_L,_L,_L,_L,_L,_L,_L,_L,                        /* 104-111 */
+	_L,_L,_L,_L,_L,_L,_L,_L,                        /* 112-119 */
+	_L,_L,_L,_P,_P,_P,_P,_C,                        /* 120-127 */
+};
--- /dev/null
+++ b/lib/c/ctype/isalnum.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isalnum
+
+int
+isalnum(int c)
+{
+	return (__ctype+1)[c] & (_U|_L|_D);
+}
--- /dev/null
+++ b/lib/c/ctype/isalpha.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isalpha
+
+int
+isalpha(int c)
+{
+	return (__ctype+1)[c] & (_U|_L);
+}
--- /dev/null
+++ b/lib/c/ctype/isascii.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isascii
+
+int
+isascii(int c)
+{
+	return c <= 0x7f;
+}
--- /dev/null
+++ b/lib/c/ctype/isblank.c
@@ -1,0 +1,7 @@
+#include <ctype.h>
+
+int
+isblank(int c)
+{
+	return (c == ' ') || (c == '\t');
+}
--- /dev/null
+++ b/lib/c/ctype/iscntrl.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef iscntrl
+
+int
+iscntrl(int c)
+{
+	return (__ctype+1)[c] & (_C);
+}
--- /dev/null
+++ b/lib/c/ctype/isdigit.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isdigit
+
+int
+isdigit(int c)
+{
+	return (__ctype+1)[c] & (_D);
+}
--- /dev/null
+++ b/lib/c/ctype/isgraph.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isgraph
+
+int
+isgraph(int c)
+{
+	return (__ctype+1)[c] & (_P|_U|_L|_D);
+}
--- /dev/null
+++ b/lib/c/ctype/islower.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef islower
+
+int
+islower(int c)
+{
+	return (__ctype+1)[c] & _L;
+}
--- /dev/null
+++ b/lib/c/ctype/isprint.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isprint
+
+int
+isprint(int c)
+{
+	return (__ctype+1)[c] & (_P|_U|_L|_D|_SP);
+}
--- /dev/null
+++ b/lib/c/ctype/ispunct.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef ispunct
+
+int
+ispunct(int c)
+{
+	return (__ctype+1)[c] & (_P);
+}
--- /dev/null
+++ b/lib/c/ctype/isspace.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isspace
+
+int
+isspace(int c)
+{
+	return (__ctype+1)[c] & _S;
+}
--- /dev/null
+++ b/lib/c/ctype/isupper.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isupper
+
+int
+isupper(int c)
+{
+	return (__ctype+1)[c] & _U;
+}
--- /dev/null
+++ b/lib/c/ctype/isxdigit.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef isxdigit
+
+int
+isxdigit(int c)
+{
+	return (__ctype+1)[c] & (_D|_X);
+}
--- /dev/null
+++ b/lib/c/ctype/tolower.c
@@ -1,0 +1,9 @@
+#define __USE_MACROS
+#include <ctype.h>
+#undef tolower
+
+int
+tolower(int c)
+{
+	return (isupper(c)) ? c | 0x20 : c;
+}
--- /dev/null
+++ b/lib/c/ctype/toupper.c
@@ -1,0 +1,8 @@
+#include <ctype.h>
+#undef toupper
+
+int
+toupper(int c)
+{
+	return (islower(c)) ? c & ~0x20 : c;
+}
--- a/lib/c/difftime.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <time.h>
-#undef difftime
-
-double
-difftime(time_t t1, time_t t2)
-{
-	return (double) (t1 - t2);
-}
--- a/lib/c/errno.c
+++ /dev/null
@@ -1,1 +1,0 @@
-int errno;
--- a/lib/c/exit.c
+++ /dev/null
@@ -1,13 +1,0 @@
-#include <stdlib.h>
-#undef exit
-
-void (*_exitf[_ATEXIT_MAX])(void);
-unsigned _exitn;
-
-void
-exit(int status)
-{
-	while (_exitn > 0)
-		(*_exitf[--_exitn])();
-	_Exit(status);
-}
--- a/lib/c/fclose.c
+++ /dev/null
@@ -1,34 +1,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include "syscall.h"
-#undef fclose
-
-extern int _flsbuf(FILE *fp);
-
-int
-fclose(FILE *fp)
-{
-	int r = EOF;
-
-	if ((fp->flags & _IOSTRG) == 0 &&
-	    fp->flags & (_IOWRITE | _IOREAD | _IORW)) {
-		r = 0;
-		if (_flsbuf(fp) == EOF)
-			r = EOF;
-		if (_close(fp->fd) < 0)
-			r = EOF;
-	}
-
-	if (fp->flags & _IOALLOC) {
-		free(fp->buf);
-		fp->buf = NULL;
-	}
-
-	fp->flags &= ~(_IOWRITE | _IOREAD | _IORW |
-	               _IOERR | _IOEOF |
-	               _IOALLOC |
-	               _IOTXT |
-	               _IOSTRG);
-
-	return r;
-}
--- a/lib/c/feof.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef feof
-
-int
-feof(FILE *fp)
-{
-	return fp->flags & _IOEOF;
-}
--- a/lib/c/ferror.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef ferror
-
-int
-ferror(FILE *fp)
-{
-	return fp->flags & _IOERR;
-}
--- a/lib/c/fgetc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef fgetc
-
-int
-fgetc(FILE *fp)
-{
-	return getc(fp);
-}
--- a/lib/c/fgets.c
+++ /dev/null
@@ -1,19 +1,0 @@
-#include <stdio.h>
-#undef fgets
-
-char *
-fgets(char *s, int n, FILE *fp)
-{
-	int ch;
-	char *t = s;
-
-	while (--n > 0 && (ch = getc(fp)) != EOF) {
-		if ((*t++ = ch) == '\n')
-			break;
-	}
-	if (ch == EOF && s == t)
-		return NULL;
-	*t = '\0';
-
-	return s;
-}
--- a/lib/c/fopen.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-
-#include "syscall.h"
-#include "libc.h"
-#undef fopen
-
-
-FILE *
-fopen(const char * restrict name, const char * restrict mode)
-{
-	FILE *fp;
-
-	for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) {
-		if ((fp->flags & (_IOREAD | _IOWRITE | _IORW)) == 0)
-			break;
-	}
-	if (fp == &__iob[FOPEN_MAX]) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	return _fpopen(name, mode, fp);
-}
--- a/lib/c/fprintf.c
+++ /dev/null
@@ -1,15 +1,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#undef fprintf
-
-int
-fprintf(FILE * restrict fp, const char * restrict fmt, ...)
-{
-	va_list va;
-	int cnt;
-
-	va_start(va, fmt);
-	cnt = vfprintf(fp, fmt, va);
-	va_end(va);
-	return cnt;
-}
--- a/lib/c/fputc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef fputc
-
-int
-fputc(int c, FILE *fp)
-{
-	return putc(c, fp);
-}
--- a/lib/c/fputs.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <stdio.h>
-#undef fputs
-
-int
-fputs(const char * restrict bp, FILE * restrict fp)
-{
-	int r, ch;
-
-	while (ch = *bp++)
-		r = putc(ch, fp);
-	return r;
-}
--- a/lib/c/fread.c
+++ /dev/null
@@ -1,25 +1,0 @@
-#include <stdio.h>
-#undef fread
-
-size_t
-fread(void * restrict ptr, size_t size, size_t nmemb,
-      FILE * restrict fp)
-{
-	unsigned char *bp = ptr;
-	size_t n, i;
-	int c;
-
-	if (size == 0)
-		return 0;
-
-	for (n = 0; n < nmemb; n++) {
-		i = size;
-		do {
-			if ((c = getc(fp)) == EOF)
-				return n;
-			*bp++ = c;
-		} while (--i);
-	}
-
-	return n;
-}
--- a/lib/c/freopen.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <stdio.h>
-
-#include "syscall.h"
-#include "libc.h"
-#undef freopen
-
-FILE *
-freopen(const char * restrict name, const char * restrict mode,
-        FILE * restrict fp)
-{
-	if (fclose(fp) == EOF)
-		return NULL;
-	return _fpopen(name, mode, fp);
-}
--- a/lib/c/fseek.c
+++ /dev/null
@@ -1,28 +1,0 @@
-#include <stdio.h>
-#include "syscall.h"
-#undef fseek
-
-extern int _flsbuf(FILE *fp);
-
-int
-fseek(FILE *fp, long off, int whence)
-{
-	if (fp->flags & _IOERR)
-		return EOF;
-
-	if ((fp->flags & _IOWRITE) && _flsbuf(fp))
-		return -1;
-	else if (whence == SEEK_CUR && (fp->flags & _IOREAD))
-		off -= fp->wp - fp->rp;
-
-	if (_lseek(fp->fd, off, whence) < 0) {
-		fp->flags |= _IOERR;
-		return EOF;
-	}
-
-	if (fp->flags & _IORW)
-		fp->flags &= ~(_IOREAD | _IOWRITE);
-	fp->flags &= ~_IOEOF;
-
-	return 0;
-}
--- a/lib/c/ftell.c
+++ /dev/null
@@ -1,27 +1,0 @@
-#include <stdio.h>
-#include "syscall.h"
-#undef ftell
-
-long
-ftell(FILE *fp)
-{
-	long off;
-	unsigned char *p;
-
-	if (fp->flags & _IOERR)
-		return EOF;
-
-	if ((off = _lseek(fp->fd, 0, SEEK_CUR)) < 0) {
-		fp->flags |= _IOERR;
-		return EOF;
-	}
-
-	if (fp->flags & _IOREAD)
-		return off - (fp->wp - fp->rp);
-
-	if (fp->flags & _IOWRITE) {
-		p = (fp->flags & _IOLBF) ? fp->lp : fp->wp;
-		return off + (p - fp->buf);
-	}
-	return off;
-}
--- a/lib/c/fwrite.c
+++ /dev/null
@@ -1,24 +1,0 @@
-#include <stdio.h>
-#undef fwrite
-
-size_t
-fwrite(const void * restrict ptr, size_t size, size_t nmemb,
-       FILE * restrict fp)
-{
-	const unsigned char *bp = ptr;
-	size_t n, i;
-
-	if (size == 0)
-		return 0;
-
-	for (n = 0; n < nmemb; n++) {
-		i = size;
-		do
-			putc(*bp++, fp);
-		while (--i);
-		if (ferror(fp))
-			break;
-	}
-
-	return n;
-}
--- a/lib/c/getc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef getc
-
-int
-getc(FILE *fp)
-{
-	return (fp->rp >= fp->wp) ?  __getc(fp) : *fp->rp++;
-}
--- a/lib/c/getchar.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef getchar
-
-int
-getchar(void)
-{
-	return getc(stdin);
-}
--- a/lib/c/gets.c
+++ /dev/null
@@ -1,17 +1,0 @@
-#include <stdio.h>
-#undef gets
-
-char *
-gets(char *s)
-{
-	int ch;
-	char *t = s;
-
-	while ((ch = getc(stdin)) != EOF && ch != '\n')
-		*t++ = ch;
-	if (ch == EOF && s == t)
-		return NULL;
-	*t = '\0';
-
-	return s;
-}
--- a/lib/c/gmtime.c
+++ /dev/null
@@ -1,35 +1,0 @@
-#include <time.h>
-#include "libc.h"
-#undef gmtime
-
-struct tm *
-gmtime(const time_t *t)
-{
-        static struct tm tm;
-        time_t sec, min, hour, year, day;
-	int i;
-
-        tm.tm_sec = *t % SECDAY;
-	tm.tm_min = tm.tm_sec / 60;
-	tm.tm_sec %= 60;
-	tm.tm_hour = tm.tm_min / 60;
-	tm.tm_min %= 60;
-	day = *t / SECDAY;
-
-	tm.tm_wday = (day + THU) % 7; /* 1/1/1970 was Thursday */
-
-	for (i = EPOCH; day >= _daysyear(i); ++i)
-		day -= _daysyear(i);
-        tm.tm_year = i - 1900;
-	tm.tm_yday = day;
-
-	_daysmon[FEB] = FEBDAYS(tm.tm_year);
-	for (i = JAN; day > _daysmon[i]; i++)
-		day -= _daysmon[i];
-	tm.tm_mon = i;
-	tm.tm_mday = day + 1;
-
-	tm.tm_isdst = 0;
-
-        return &tm;
-}
--- a/lib/c/isalnum.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isalnum
-
-int
-isalnum(int c)
-{
-	return (__ctype+1)[c] & (_U|_L|_D);
-}
--- a/lib/c/isalpha.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isalpha
-
-int
-isalpha(int c)
-{
-	return (__ctype+1)[c] & (_U|_L);
-}
--- a/lib/c/isascii.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <ctype.h>
-#undef isascii
-
-int
-isascii(int c)
-{
-	return c <= 0x7f;
-}
--- a/lib/c/isblank.c
+++ /dev/null
@@ -1,7 +1,0 @@
-#include <ctype.h>
-
-int
-isblank(int c)
-{
-	return (c == ' ') || (c == '\t');
-}
--- a/lib/c/iscntrl.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef iscntrl
-
-int
-iscntrl(int c)
-{
-	return (__ctype+1)[c] & (_C);
-}
--- a/lib/c/isdigit.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isdigit
-
-int
-isdigit(int c)
-{
-	return (__ctype+1)[c] & (_D);
-}
--- a/lib/c/isgraph.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isgraph
-
-int
-isgraph(int c)
-{
-	return (__ctype+1)[c] & (_P|_U|_L|_D);
-}
--- a/lib/c/islower.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef islower
-
-int
-islower(int c)
-{
-	return (__ctype+1)[c] & _L;
-}
--- a/lib/c/isprint.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isprint
-
-int
-isprint(int c)
-{
-	return (__ctype+1)[c] & (_P|_U|_L|_D|_SP);
-}
--- a/lib/c/ispunct.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef ispunct
-
-int
-ispunct(int c)
-{
-	return (__ctype+1)[c] & (_P);
-}
--- a/lib/c/isspace.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isspace
-
-int
-isspace(int c)
-{
-	return (__ctype+1)[c] & _S;
-}
--- a/lib/c/isupper.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isupper
-
-int
-isupper(int c)
-{
-	return (__ctype+1)[c] & _U;
-}
--- a/lib/c/isxdigit.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef isxdigit
-
-int
-isxdigit(int c)
-{
-	return (__ctype+1)[c] & (_D|_X);
-}
--- a/lib/c/labs.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdlib.h>
-#undef labs
-
-long
-labs(long n)
-{
-	return (n < 0) ? -n : n;
-}
--- a/lib/c/libc.h
+++ b/lib/c/libc.h
@@ -33,5 +33,10 @@
 extern struct tzone *_tzone(struct tm *tm);
 extern int _daysyear(int year);
 extern int _newyear(int year);
+extern void *_getheap(void);
+#ifdef FILE
+extern int _flsbuf(FILE *fp);
+extern void _allocbuf(FILE *fp);
+#endif
 
 extern int _daysmon[12];
--- a/lib/c/llabs.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdlib.h>
-#undef llabs
-
-long long
-llabs(long long n)
-{
-	return (n < 0) ? -n : n;
-}
--- /dev/null
+++ b/lib/c/locale/Makefile
@@ -1,0 +1,10 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = localeconv.o\
+       setlocale.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/locale/localeconv.c
@@ -1,0 +1,29 @@
+#include <locale.h>
+#include <limits.h>
+#undef localeconv
+
+struct lconv *
+localeconv(void)
+{
+	static struct lconv lc = { 
+		.decimal_point = ".",
+		.thousands_sep = "",
+		.grouping = "",
+		.mon_decimal_point = "",
+		.mon_thousands_sep = "",
+		.mon_grouping = "",
+		.positive_sign = "",
+		.negative_sign = "",
+		.currency_symbol = "",
+		.int_curr_symbol = "",
+		.frac_digits = CHAR_MAX,
+		.p_cs_precedes = CHAR_MAX,
+		.n_cs_precedes = CHAR_MAX,
+		.p_sep_by_space = CHAR_MAX,
+		.p_sign_posn = CHAR_MAX,
+		.n_sep_by_space = CHAR_MAX,
+		.n_sign_posn = CHAR_MAX,
+		.int_frac_digits = CHAR_MAX,
+	};
+	return &lc;
+}
--- /dev/null
+++ b/lib/c/locale/setlocale.c
@@ -1,0 +1,16 @@
+#include <locale.h>
+#include <stddef.h>
+#undef setlocale
+
+char *
+setlocale(int category, const char *locale)
+{
+	if (category > LC_TIME || category < LC_ALL)
+		return NULL;
+	if (!locale ||
+	    locale[0] == '\0' ||
+	    locale[0] == 'C' && locale[1] == '\0') {
+		return "C";
+	}
+	return NULL;
+}
--- a/lib/c/localeconv.c
+++ /dev/null
@@ -1,29 +1,0 @@
-#include <locale.h>
-#include <limits.h>
-#undef localeconv
-
-struct lconv *
-localeconv(void)
-{
-	static struct lconv lc = { 
-		.decimal_point = ".",
-		.thousands_sep = "",
-		.grouping = "",
-		.mon_decimal_point = "",
-		.mon_thousands_sep = "",
-		.mon_grouping = "",
-		.positive_sign = "",
-		.negative_sign = "",
-		.currency_symbol = "",
-		.int_curr_symbol = "",
-		.frac_digits = CHAR_MAX,
-		.p_cs_precedes = CHAR_MAX,
-		.n_cs_precedes = CHAR_MAX,
-		.p_sep_by_space = CHAR_MAX,
-		.p_sign_posn = CHAR_MAX,
-		.n_sep_by_space = CHAR_MAX,
-		.n_sign_posn = CHAR_MAX,
-		.int_frac_digits = CHAR_MAX,
-	};
-	return &lc;
-}
--- a/lib/c/localtime.c
+++ /dev/null
@@ -1,21 +1,0 @@
-#include <time.h>
-#include "libc.h"
-#undef localtime
-
-struct tm *
-localtime(const time_t *timep)
-{
-	struct tzone *tz;
-	struct tm *tm;
-	time_t t = *timep;
-
-	t += tz->gmtoff * 60;
-	t += tz->isdst * 60;
-	tm = gmtime(&t);
-	tz = _tzone(tm);
-	tm->tm_zone = tz->name;
-	tm->tm_isdst = tz->isdst;
-	tm->tm_gmtoff = tz->gmtoff;
-
-	return tm;
-}
--- a/lib/c/malloc.c
+++ /dev/null
@@ -1,152 +1,0 @@
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "malloc.h"
-#include "syscall.h"
-
-#define MAXADDR ((char *)-1)
-#define ERRADDR ((char *)-1)
-
-extern char end[];
-static Header base = { .h.next = &base };
-static Header *freep = &base;
-static char *heap = end;
-
-/*
- * Run over the free list looking for the nearest previous
- * block. There are two possible results: end of the list
- * or an intermediary block.
- */
-void *
-_prevchunk(Header *hp)
-{
-	Header *p;
-
-	for (p = freep; ;p = p->h.next) {
-		/* hp between p and p->h.next? */
-		if (p < hp && hp < p->h.next)
-			break;
-		/* p before hp and hp at the end of list? */
-		if (p->h.next <= p && (hp < p->h.next || hp > p))
-			break;
-	}
-	return p;
-}
-
-/*
- * Get the previous block and try to merge
- * with next and previous blocks
- */
-void
-free(void *mem)
-{
-	Header *hp, *prev;
-
-	if (!mem)
-		return;
-
-	hp = (Header *) mem - 1;
-	prev = _prevchunk(hp);
-
-	/* join to next */
-	if (hp + hp->h.size == prev->h.next) {
-		hp->h.size += prev->h.next->h.size;
-		hp->h.next = prev->h.next->h.next;
-	} else {
-		hp->h.next = prev->h.next;
-	}
-
-	/* join to previous */
-	if (prev + prev->h.size == hp) {
-		prev->h.size += hp->h.size;
-		prev->h.next = hp->h.next;
-	} else {
-		prev->h.next = hp;
-	}
-
-	freep = prev;
-}
-
-static void *
-sbrk(uintptr_t inc)
-{
-	char *new, *old = heap;
-
-	if (old >= MAXADDR - inc)
-		return ERRADDR;
-
-	new = old + inc;
-	if (_brk(new) < 0)
-		return ERRADDR;
-	heap = new;
-
-	return old;
-}
-
-static Header *
-morecore(size_t nunits)
-{
-	char *rawmem;
-	Header *hp;
-
-	if (nunits < NALLOC)
-		nunits = NALLOC;
-
-	rawmem = sbrk(nunits * sizeof(Header));
-	if (rawmem == ERRADDR)
-		return NULL;
-
-	hp = (Header*)rawmem;
-	hp->h.size = nunits;
-
-	/* integrate new memory into the list */
-	free(hp + 1);
-
-	return freep;
-}
-
-/*
- * Run over the list of free blocks trying to find a block
- * big enough for nbytes. If the block fit perfectly with
- * the required size then we only have to unlink
- * the block. Otherwise we have to split the block and
- * return the right part. If we run over the full list
- * without a fit then we have to require more memory
- *
- *              ______________________________________
- * ___________./______________________________________\_____
- * ...| in   |   |     | in  |  |.....| in   |  |    | |....
- * ...| use  |   |     | use |  |.....| use  |  |    | |....
- * ___|______|___|.____|_____|._|_____|______|._|.___|.|____
- *            \__/ \_________/ \_____________/ \/ \__/
- */
-void *
-malloc(size_t nbytes)
-{
-	Header *cur, *prev;
-	size_t nunits;
-
-	/* 1 unit for header plus enough units to fit nbytes */
-	nunits = (nbytes+sizeof(Header)-1) / sizeof(Header) + 1;
-
-	for (prev = freep; ; prev = cur) {
-		cur = prev->h.next;
-		if (cur->h.size >= nunits) {
-			if (cur->h.size == nunits) {
-				prev->h.next = cur->h.next;
-			} else {
-				cur->h.size -= nunits;
-				cur += cur->h.size;
-				cur->h.size = nunits;
-			}
-			freep = prev;
-			return cur + 1;
-		}
-
-		if (cur == freep) {
-			if ((cur = morecore(nunits)) == NULL)
-				return NULL;
-		}
-	}
-}
--- a/lib/c/malloc.h
+++ /dev/null
@@ -1,16 +1,0 @@
-#include <stdlib.h>
-
-/* minimum amount of required units */
-#define NALLOC 10000
-
-typedef union header Header;
-union header {
-	struct hdr {
-		Header *next;
-		size_t size;
-	} h;
-	/* most restrictive type fixes the union size for alignment */
-	_ALIGNTYPE most;
-};
-
-extern void *_prevchunk(Header *hp);
--- a/lib/c/memchr.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <string.h>
-#undef memchr
-
-void *
-memchr(const void *s, int c, size_t n)
-{
-	const unsigned char *bp = s;
-
-	while (n > 0 && *bp++ != c)
-		--n;
-	return (n == 0) ? NULL : bp-1;
-}
--- a/lib/c/memcmp.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <string.h>
-#undef memcmp
-
-int
-memcmp(const void *s1, const void *s2, size_t n)
-{
-	const char *s = s1;
-	const char *t = s2;
-
-	for ( ; n > 0 && *s == *t; --n)
-		++s, ++t;
-
-	return (n > 0) ? *(unsigned char *) s - *(unsigned char *) t : 0;
-}
--- a/lib/c/memcpy.c
+++ /dev/null
@@ -1,13 +1,0 @@
-#include <string.h>
-#undef memcpy
-
-void *
-memcpy(void * restrict dst, const void * restrict src, size_t n)
-{
-	char *s1 = dst;
-	const char *s2 = src;
-
-	while (n-- > 0)
-		*s1++ = *s2++;
-	return dst;
-}
--- a/lib/c/memmove.c
+++ /dev/null
@@ -1,18 +1,0 @@
-#include <string.h>
-#undef memmove
-
-void *
-memmove(void *dst, const void *src, size_t n)
-{
-	char *d = dst, *s = (char *) src;
-
-	if (d < s) {
-		while (n-- > 0)
-			*d++ = *s++;
-	} else {
-		s += n-1, d += n-1;
-		while (n-- > 0)
-			*d-- = *s--;
-	}
-	return dst;
-}
--- a/lib/c/memset.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <string.h>
-#undef memset
-
-void *
-memset(void *s, int c, size_t n)
-{
-	char *m = s;
-
-	while (n-- > 0)
-		*m++ = c;
-	return s;
-}
--- /dev/null
+++ b/lib/c/mklst
@@ -1,0 +1,12 @@
+#!/bin/sh
+
+set -e
+trap 'r=$?;rm -f $$.tmp;exit $r' EXIT HUP QUIT INT TERM
+archive=${1?'First parameter must be the archive name'}
+
+if test -f $archive
+then
+	newer="-newer $archive" 
+fi
+
+find . -name '*.o' $newer > $$.tmp && mv $$.tmp objlst
--- a/lib/c/mktime.c
+++ /dev/null
@@ -1,112 +1,0 @@
-#include <limits.h>
-#include <time.h>
-#include "libc.h"
-#undef mktime
-
-static int
-norm(int *val, int *next, int qty)
-{
-	int v = *val, n = *next, d;
-
-	if (v < 0) {
-		d = -v / qty + 1;
-		v += d * qty;
-		if (n > INT_MAX - d)
-			return 0;
-		n += d;
-	}
-	if (v >= qty) {
-		d = v / qty;
-		v -= d * qty;
-		if (n < INT_MIN + d)
-			return 0;
-		n -= d;
-	}
-
-	*val = v;
-	*next = n;
-	return 1;
-}
-
-static int
-normalize(struct tm *tm)
-{
-	int mon, day, year;
-	struct tm aux = *tm;
-
-	if (!norm(&tm->tm_sec, &tm->tm_min, 60)   ||
-	    !norm(&tm->tm_min, &tm->tm_hour, 60)  ||
-	    !norm(&tm->tm_hour, &tm->tm_mday, 24) ||
-	    !norm(&tm->tm_mon, &tm->tm_year, 12)) {
-		return 0;
-	}
-
-	day = tm->tm_mday;
-	year = EPOCH + tm->tm_year;
-	_daysmon[FEB] = FEBDAYS(year);
-
-	for (mon = tm->tm_mon; day < 1; --mon) {
-		day += _daysmon[mon];
-		if (mon == JAN) {
-			if (year == EPOCH)
-				return -1;
-			year--;
-			_daysmon[FEB] = FEBDAYS(year);
-			mon = DEC+1;
-		}
-	}
-
-	for (; day > _daysmon[mon]; ++mon) {
-		day -= _daysmon[mon];
-		if (mon == DEC) {
-			if (year == _MAXYEAR)
-				return -1;
-			year++;
-			_daysmon[FEB] = FEBDAYS(year);
-			mon = JAN-1;
-		}
-	}
-
-	tm->tm_mon = mon;
-	tm->tm_year = year - EPOCH;
-	tm->tm_mday = day;
-	tm->tm_wday = (_newyear(tm->tm_year) + tm->tm_yday) % 7;
-
-	return 1;
-}
-
-time_t
-mktime(struct tm *tm)
-{
-	int i, year, dst;
-	time_t t;
-	struct tm *aux;
-
-	if (!normalize(tm))
-		return -1;
-
-	t = 0;
-	year = tm->tm_year + 1900;
-	for (i = EPOCH; i < year; i++)
-		t += _daysyear(i) * SECDAY;
-
-	for (i = 0; i < tm->tm_mon; i++)
-		t += _daysmon[i] * SECDAY;
-
-	t += tm->tm_sec;
-	t += tm->tm_min * SECMIN;
-	t += tm->tm_hour * SECHOUR;
-	t += (tm->tm_mday-1) * SECDAY;
-
-	aux = localtime(&t);
-
-	dst = 0;
-	if (tm->tm_isdst == 0 && aux->tm_isdst == 1)
-		dst = -SECHOUR;
-	else if (tm->tm_isdst == 1 && aux->tm_isdst == 0)
-		dst = +SECHOUR;
-
-	t += aux->tm_gmtoff + dst;
-
-	return t;
-}
--- a/lib/c/perror.c
+++ /dev/null
@@ -1,16 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#undef perror
-
-void
-perror(const char *msg)
-{
-	if (msg && *msg) {
-		fputs(msg, stderr);
-		putc(':', stderr);
-		putc(' ', stderr);
-	}
-	fputs(strerror(errno), stderr);
-	putc('\n', stderr);
-}
--- a/lib/c/printf.c
+++ /dev/null
@@ -1,15 +1,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#undef printf
-
-int
-printf(const char * restrict fmt, ...)
-{
-	int cnt;
-	va_list va;
-
-	va_start(va, fmt);
-	cnt = vfprintf(stdout, fmt, va);
-	va_end(va);
-	return cnt;
-}
--- a/lib/c/putc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef putc
-
-int
-putc(int ch, FILE *fp)
-{
-	return (fp->wp >= fp->rp) ? __putc(ch,fp) : (*fp->wp++ = ch);
-}
--- a/lib/c/putchar.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef putchar
-
-int
-putchar(int ch)
-{
-	return putc(ch, stdout);
-}
--- a/lib/c/puts.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <stdio.h>
-#undef puts
-
-int
-puts(const char *str)
-{
-	int ch;
-
-	while (ch = *str++)
-		putchar(ch);
-	return putchar('\n');
-}
--- a/lib/c/qsort.c
+++ /dev/null
@@ -1,68 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-#undef qsort
-
-/*
- * This implementation of qsort is based in the paper
- * "Engineering a Sort Function", by Jon L.Bentley and M. Douglas McIlroy.
- * A lot of different optimizations were removed to make the code simpler.
- */
-
-struct qsort {
-	size_t es;
-	int (*cmp)(const void *, const void *);
-};
-
-static void
-swap(char *i, char *j, size_t n)
-{
-	do {
-		char c = *i;
-		*i++ = *j;
-		*j++ = c;
-	} while (--n > 0);
-}
-
-static void
-xqsort(char *a, size_t n, struct qsort *qs)
-{
-	size_t j, es = qs->es;
-	char *pi, *pj, *pn;
-
-	if (n <= 1)
-		return;
-
-	pi = a;
-	pn = pj = a + n*es;
-
-	swap(a, a + n/2 * es,  es);
-	for (;;) {
-		do {
-			pi += es;
-		} while  (pi < pn && qs->cmp(pi, a) < 0);
-
-		do {
-			pj -= es;
-		} while (pj > a && qs->cmp(pj, a) > 0);
-
-		if (pj < pi)
-			break;
-		swap(pi, pj, es);
-	}
-	swap(a, pj, es);
-
-	j = (pj - a) / es;
-	xqsort(a, j, qs);
-	xqsort(a + (j+1)*es, n-j-1, qs);
-}
-
-void
-qsort(void *base, size_t nmemb, size_t size,
-      int (*f)(const void *, const void *))
-{
-	struct qsort qs;
-
-	qs.cmp = f;
-	qs.es = size;
-	xqsort(base, nmemb, &qs);
-}
--- a/lib/c/rand.c
+++ /dev/null
@@ -1,18 +1,0 @@
-#include <stdlib.h>
-#undef rand
-#undef srand
-
-static unsigned long next;
-
-void
-srand(unsigned seed)
-{
-	next = seed;
-}
-
-int
-rand(void)  /* RAND_MAX assumed to be 32767. */
-{
-	next = next * 1103515245 + 12345;
-	return (unsigned)(next/65536) % 32768;
-}
--- a/lib/c/realloc.c
+++ /dev/null
@@ -1,68 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include "malloc.h"
-#undef realloc
-
-void *
-realloc(void *ptr, size_t nbytes)
-{
-	Header *oh, *prev, *next, *new;
-	size_t nunits, avail, onbytes, n;
-
-	if (!nbytes)
-		return NULL;
-
-	if (!ptr)
-		return malloc(nbytes);
-
-	nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
-	oh = (Header*)ptr - 1;
-
-	if (oh->h.size == nunits)
-		return ptr;
-
-	new = oh + nunits;
-
-	if (nunits < oh->h.size - 1) {
-		new->h.size = oh->h.size - nunits;
-		oh->h.size = nunits;
-		free(new + 1);
-		return oh;
-	}
-
-	prev = _prevchunk(oh);
-
-	if (oh + oh->h.size == prev->h.next) {
-		/*
-		 * if there is free space adjacent
-		 * to the current memory
-		 */
-		next = prev->h.next;
-		avail = oh->h.size + next->h.size;
-
-		if (avail == nunits) {
-			oh->h.size = nunits;
-			prev->h.next = next->h.next;
-			return oh;
-		}
-
-		if (avail > nunits) {
-			oh->h.size = nunits;
-			prev->h.next = new;
-			new->h.next = next;
-			new->h.size = avail - nunits;
-			return oh;
-		}
-	}
-
-	onbytes = (oh->h.size - 1) * sizeof(Header);
-	if ((new = malloc(nbytes)) == NULL)
-		return NULL;
-
-	n = (onbytes > nbytes) ? nbytes : onbytes;
-	memcpy(new, ptr, n);
-	free(ptr);
-
-	return new;
-}
--- a/lib/c/rewind.c
+++ /dev/null
@@ -1,10 +1,0 @@
-#include <stdio.h>
-#undef rewind
-
-void
-rewind(FILE *fp)
-{
-	fp->flags &= ~_IOERR;
-	fseek(fp, 0, SEEK_SET);
-	clearerr(fp);
-}
--- a/lib/c/setbuf.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include <stdio.h>
-#undef setbuf
-
-void
-setbuf(FILE * restrict fp, char * restrict buf)
-{
-	setvbuf(fp, buf, (buf) ? _IOFBF : _IONBF, BUFSIZ);
-}
--- a/lib/c/setlocale.c
+++ /dev/null
@@ -1,16 +1,0 @@
-#include <locale.h>
-#include <stddef.h>
-#undef setlocale
-
-char *
-setlocale(int category, const char *locale)
-{
-	if (category > LC_TIME || category < LC_ALL)
-		return NULL;
-	if (!locale ||
-	    locale[0] == '\0' ||
-	    locale[0] == 'C' && locale[1] == '\0') {
-		return "C";
-	}
-	return NULL;
-}
--- a/lib/c/setvbuf.c
+++ /dev/null
@@ -1,46 +1,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#undef setvbuf
-
-extern int _flsbuf(FILE *fp);
-
-int
-setvbuf(FILE * restrict fp, char * restrict buf, int mode, size_t size)
-{
-	int flags;
-
-	if (_flsbuf(fp) == EOF)
-		return EOF;
-
-	switch (mode) {
-	case _IONBF:
-		size = sizeof(fp->unbuf);
-		buf = fp->unbuf;
-		break;
-	case _IOLBF:
-	case _IOFBF:
-		if (size == 0) {
-			if ((buf = malloc(BUFSIZ)) == NULL) {
-				errno = ENOMEM;
-				return EOF;
-			}
-			size = BUFSIZ;
-		}
-		break;
-	default:
-		errno = EINVAL;
-		return EOF;
-	}
-
-	flags = fp->flags;
-	if (flags & _IOALLOC)
-		free(fp->buf);
-	flags &= ~(_IONBF | _IOLBF | _IOFBF | _IOALLOC | _IOALLOC);
-	flags |= mode;
-	fp->flags = flags;
-	fp->buf = buf;
-	fp->len = size;
-
-	return 0;
-}
--- a/lib/c/snprintf.c
+++ /dev/null
@@ -1,17 +1,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#undef snprintf
-
-int
-snprintf(char * restrict s, size_t siz, const char * restrict fmt, ...)
-{
-	int r;
-	va_list va;
-
-	va_list va_arg;
-	va_start(va, fmt);
-	r = vsnprintf(s, siz, fmt, va);
-	va_end(va);
-
-	return r;
-}
--- a/lib/c/sprintf.c
+++ /dev/null
@@ -1,16 +1,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#undef sprintf
-
-int
-sprintf(char * restrict s, const char * restrict fmt, ...)
-{
-	int r;
-
-	va_list va;
-	va_start(va, fmt);
-	r = vsprintf(s, fmt, va);
-	va_end(va);
-
-	return r;
-}
--- a/lib/c/stdio.c
+++ /dev/null
@@ -1,20 +1,0 @@
-#include <stdio.h>
-
-FILE __iob[FOPEN_MAX] = {
-	{
-		.fd = 0,
-		.flags = _IOREAD,
-	},
-	{
-		.fd = 1,
-		.flags = _IOWRITE | _IOLBF,
-	},
-	{
-		.fd = 2,
-		.buf = stderr->unbuf,
-		.len = sizeof(stderr->unbuf),
-		.flags = _IOWRITE | _IONBF,
-		.rp = stderr->unbuf,
-		.wp = stderr->unbuf,
-	},
-};
--- /dev/null
+++ b/lib/c/stdio/Makefile
@@ -1,0 +1,47 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = __getc.o\
+       __putc.o\
+       _flsbuf.o\
+       _fpopen.o\
+       clearerr.o\
+       fclose.o\
+       feof.o\
+       ferror.o\
+       fgetc.o\
+       fgets.o\
+       fopen.o\
+       fprintf.o\
+       fputc.o\
+       fputs.o\
+       fread.o\
+       freopen.o\
+       fseek.o\
+       ftell.o\
+       fwrite.o\
+       getc.o\
+       getchar.o\
+       gets.o\
+       perror.o\
+       printf.o\
+       putc.o\
+       putchar.o\
+       puts.o\
+       rewind.o\
+       setbuf.o\
+       setvbuf.o\
+       snprintf.o\
+       sprintf.o\
+       __iob.o\
+       tmpnam.o\
+       vfprintf.o\
+       vsnprintf.o\
+       vsprintf.o\
+       vprintf.o\
+       _allocbuf.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/stdio/__getc.c
@@ -1,0 +1,39 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "../libc.h"
+#include "../syscall.h"
+
+int
+__getc(FILE *fp)
+{
+	int cnt;
+
+	if (fp->flags & (_IOEOF | _IOERR))
+		return EOF;
+
+	if ((fp->flags & (_IOREAD | _IORW)) == 0) {
+		fp->flags |= _IOERR;
+		errno = EBADF;
+		return EOF;
+	}
+
+	if (fp->flags & _IOSTRG) {
+		fp->flags |= _IOEOF;
+		return EOF;
+	}
+
+	if (fp->buf == NULL && _allocbuf(fp))
+		return EOF;
+
+	if ((cnt = _read(fp->fd, fp->buf, fp->len)) <= 0) {
+		fp->flags |= (cnt == 0) ? _IOEOF : _IOERR;
+		return EOF;
+	}
+
+	fp->flags |= _IOREAD;
+	fp->rp = fp->buf;
+	fp->wp = fp->buf + cnt;
+
+	return *fp->rp++;
+}
--- /dev/null
+++ b/lib/c/stdio/__iob.c
@@ -1,0 +1,20 @@
+#include <stdio.h>
+
+FILE __iob[FOPEN_MAX] = {
+	{
+		.fd = 0,
+		.flags = _IOREAD,
+	},
+	{
+		.fd = 1,
+		.flags = _IOWRITE | _IOLBF,
+	},
+	{
+		.fd = 2,
+		.buf = stderr->unbuf,
+		.len = sizeof(stderr->unbuf),
+		.flags = _IOWRITE | _IONBF,
+		.rp = stderr->unbuf,
+		.wp = stderr->unbuf,
+	},
+};
--- /dev/null
+++ b/lib/c/stdio/__putc.c
@@ -1,0 +1,78 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "../libc.h"
+
+int
+fflush(FILE *fp)
+{
+	int err;
+
+	if (fp)
+		return _flsbuf(fp);
+
+	err = 0;
+	for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) {
+		if ((fp->flags & _IOWRITE) == 0 && _flsbuf(fp))
+			err = EOF;
+	}
+	return err;
+}
+
+static void
+cleanup(void)
+{
+	fflush(NULL);
+}
+
+int
+__putc(int ch, FILE *fp)
+{
+	static int first = 1;
+
+	if (fp->flags & _IOERR)
+		return EOF;
+
+	if (fp->flags & _IOREAD) {
+		fp->flags |= _IOERR;
+		errno = EBADF;
+		return EOF;
+	}
+
+	if (fp->flags & _IOSTRG) {
+		fp->flags |= _IOERR;
+		return EOF;
+	}
+
+	if (fp->buf == NULL && _allocbuf(fp))
+			return EOF;
+
+	if (first) {
+		if (atexit(cleanup)) {
+			fp->flags |= _IOERR;
+			errno = ENOMEM;
+			return EOF;
+		}
+		first = 0;
+	}
+
+	if (fp->flags & _IOLBF) {
+		if (fp->wp == fp->lp && _flsbuf(fp))
+			return EOF;
+		*fp->wp++ = ch;
+		if (ch == '\n' && _flsbuf(fp))
+			return EOF;
+	} else if (fp->flags & _IOFBF) {
+		if (_flsbuf(fp))
+			return EOF;
+		*fp->wp++ = ch;
+		fp->rp = fp->buf + fp->len;
+	} else {
+		*fp->wp++ = ch;
+		if (_flsbuf(fp))
+			return EOF;
+	}
+
+	fp->flags |= _IOWRITE;
+	return ch & 0xFF;
+}
--- /dev/null
+++ b/lib/c/stdio/_allocbuf.c
@@ -1,0 +1,21 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "../libc.h"
+
+int
+_allocbuf(FILE *fp)
+{
+	char *bp;
+
+	if ((bp = malloc(BUFSIZ)) == NULL) {
+		fp->flags |= _IOERR;
+		errno = ENOMEM;
+		return EOF;
+	}
+	fp->len = BUFSIZ;
+	fp->rp = fp->wp = fp->buf = bp;
+	fp->lp = bp + BUFSIZ;
+
+	return 0;
+}
--- /dev/null
+++ b/lib/c/stdio/_flsbuf.c
@@ -1,0 +1,23 @@
+#include <errno.h>
+#include <stdio.h>
+
+#include "../libc.h"
+#include "../syscall.h"
+
+int
+_flsbuf(FILE *fp)
+{
+	size_t cnt;
+
+	if (fp->flags&_IOREAD)
+		return 0;
+
+	cnt = fp->wp - fp->buf;
+	if (cnt > 0 && _write(fp->fd, fp->buf, cnt) != cnt) {
+		fp->flags |= _IOERR;
+		return EOF;
+	}
+	fp->wp = fp->buf;
+
+	return 0;
+}
--- /dev/null
+++ b/lib/c/stdio/_fpopen.c
@@ -1,0 +1,75 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys.h>
+#include "../syscall.h"
+#include "../libc.h"
+#undef fopen
+
+FILE *
+_fpopen(const char * restrict fname,
+        const char * restrict mode,
+        FILE * restrict fp)
+{
+	int i, flags, fd, rw, bin;
+
+	flags = rw = bin = 0;
+
+	if (mode[0] == '\0')
+		goto einval;
+
+	for (i = 1; mode[i]; ++i) {
+		switch (mode[i]) {
+		case '+':
+			if (rw)
+				goto einval;
+			rw = 1;
+			break;
+		case 'b':
+			if (bin)
+				goto einval;
+			bin = 1;
+			break;
+		default:
+			goto einval;
+		}
+	}
+
+	switch (mode[0]) {
+	case 'a':
+		flags |= O_APPEND | O_CREAT;
+		goto wrflags;
+	case 'w':
+		flags |= O_TRUNC | O_CREAT;
+	wrflags:
+		flags |= (rw) ? O_RDWR : O_WRONLY;
+		break;
+	case 'r':
+		flags = (rw) ? O_RDWR : O_RDONLY;
+		break;
+	default:
+	einval:
+		errno = EINVAL;
+		return NULL;
+	}
+
+	if ((fd = _open(fname, flags)) < 0)
+		return NULL;
+
+	fp->buf = NULL;
+	fp->fd = fd;
+
+	if (!bin)
+		fp->flags |= _IOTXT;
+
+	if (flags & O_RDWR)
+		fp->flags |= _IORW;
+	else if (flags & O_RDONLY)
+		fp->flags |= _IOREAD;
+	else
+		fp->flags |= _IOWRITE;
+
+	fp->lp = fp->rp = fp->wp = NULL;
+
+	return fp;
+}
--- /dev/null
+++ b/lib/c/stdio/clearerr.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef clearerr
+
+void
+clearerr(FILE *fp)
+{
+	fp->flags &= ~(_IOERR | _IOEOF);
+}
--- /dev/null
+++ b/lib/c/stdio/fclose.c
@@ -1,0 +1,32 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "../syscall.h"
+#undef fclose
+
+int
+fclose(FILE *fp)
+{
+	int r = EOF;
+
+	if ((fp->flags & _IOSTRG) == 0 &&
+	    fp->flags & (_IOWRITE | _IOREAD | _IORW)) {
+		r = 0;
+		if (_flsbuf(fp) == EOF)
+			r = EOF;
+		if (_close(fp->fd) < 0)
+			r = EOF;
+	}
+
+	if (fp->flags & _IOALLOC) {
+		free(fp->buf);
+		fp->buf = NULL;
+	}
+
+	fp->flags &= ~(_IOWRITE | _IOREAD | _IORW |
+	               _IOERR | _IOEOF |
+	               _IOALLOC |
+	               _IOTXT |
+	               _IOSTRG);
+
+	return r;
+}
--- /dev/null
+++ b/lib/c/stdio/feof.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef feof
+
+int
+feof(FILE *fp)
+{
+	return fp->flags & _IOEOF;
+}
--- /dev/null
+++ b/lib/c/stdio/ferror.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef ferror
+
+int
+ferror(FILE *fp)
+{
+	return fp->flags & _IOERR;
+}
--- /dev/null
+++ b/lib/c/stdio/fgetc.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef fgetc
+
+int
+fgetc(FILE *fp)
+{
+	return getc(fp);
+}
--- /dev/null
+++ b/lib/c/stdio/fgets.c
@@ -1,0 +1,19 @@
+#include <stdio.h>
+#undef fgets
+
+char *
+fgets(char *s, int n, FILE *fp)
+{
+	int ch;
+	char *t = s;
+
+	while (--n > 0 && (ch = getc(fp)) != EOF) {
+		if ((*t++ = ch) == '\n')
+			break;
+	}
+	if (ch == EOF && s == t)
+		return NULL;
+	*t = '\0';
+
+	return s;
+}
--- /dev/null
+++ b/lib/c/stdio/fopen.c
@@ -1,0 +1,23 @@
+#include <errno.h>
+#include <stdio.h>
+
+#include "../syscall.h"
+#include "../libc.h"
+#undef fopen
+
+
+FILE *
+fopen(const char * restrict name, const char * restrict mode)
+{
+	FILE *fp;
+
+	for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) {
+		if ((fp->flags & (_IOREAD | _IOWRITE | _IORW)) == 0)
+			break;
+	}
+	if (fp == &__iob[FOPEN_MAX]) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	return _fpopen(name, mode, fp);
+}
--- /dev/null
+++ b/lib/c/stdio/fprintf.c
@@ -1,0 +1,15 @@
+#include <stdarg.h>
+#include <stdio.h>
+#undef fprintf
+
+int
+fprintf(FILE * restrict fp, const char * restrict fmt, ...)
+{
+	va_list va;
+	int cnt;
+
+	va_start(va, fmt);
+	cnt = vfprintf(fp, fmt, va);
+	va_end(va);
+	return cnt;
+}
--- /dev/null
+++ b/lib/c/stdio/fputc.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef fputc
+
+int
+fputc(int c, FILE *fp)
+{
+	return putc(c, fp);
+}
--- /dev/null
+++ b/lib/c/stdio/fputs.c
@@ -1,0 +1,12 @@
+#include <stdio.h>
+#undef fputs
+
+int
+fputs(const char * restrict bp, FILE * restrict fp)
+{
+	int r, ch;
+
+	while (ch = *bp++)
+		r = putc(ch, fp);
+	return r;
+}
--- /dev/null
+++ b/lib/c/stdio/fread.c
@@ -1,0 +1,25 @@
+#include <stdio.h>
+#undef fread
+
+size_t
+fread(void * restrict ptr, size_t size, size_t nmemb,
+      FILE * restrict fp)
+{
+	unsigned char *bp = ptr;
+	size_t n, i;
+	int c;
+
+	if (size == 0)
+		return 0;
+
+	for (n = 0; n < nmemb; n++) {
+		i = size;
+		do {
+			if ((c = getc(fp)) == EOF)
+				return n;
+			*bp++ = c;
+		} while (--i);
+	}
+
+	return n;
+}
--- /dev/null
+++ b/lib/c/stdio/freopen.c
@@ -1,0 +1,14 @@
+#include <stdio.h>
+
+#include "../syscall.h"
+#include "../libc.h"
+#undef freopen
+
+FILE *
+freopen(const char * restrict name, const char * restrict mode,
+        FILE * restrict fp)
+{
+	if (fclose(fp) == EOF)
+		return NULL;
+	return _fpopen(name, mode, fp);
+}
--- /dev/null
+++ b/lib/c/stdio/fseek.c
@@ -1,0 +1,26 @@
+#include <stdio.h>
+#include "../syscall.h"
+#undef fseek
+
+int
+fseek(FILE *fp, long off, int whence)
+{
+	if (fp->flags & _IOERR)
+		return EOF;
+
+	if ((fp->flags & _IOWRITE) && _flsbuf(fp))
+		return -1;
+	else if (whence == SEEK_CUR && (fp->flags & _IOREAD))
+		off -= fp->wp - fp->rp;
+
+	if (_lseek(fp->fd, off, whence) < 0) {
+		fp->flags |= _IOERR;
+		return EOF;
+	}
+
+	if (fp->flags & _IORW)
+		fp->flags &= ~(_IOREAD | _IOWRITE);
+	fp->flags &= ~_IOEOF;
+
+	return 0;
+}
--- /dev/null
+++ b/lib/c/stdio/ftell.c
@@ -1,0 +1,27 @@
+#include <stdio.h>
+#include "../syscall.h"
+#undef ftell
+
+long
+ftell(FILE *fp)
+{
+	long off;
+	unsigned char *p;
+
+	if (fp->flags & _IOERR)
+		return EOF;
+
+	if ((off = _lseek(fp->fd, 0, SEEK_CUR)) < 0) {
+		fp->flags |= _IOERR;
+		return EOF;
+	}
+
+	if (fp->flags & _IOREAD)
+		return off - (fp->wp - fp->rp);
+
+	if (fp->flags & _IOWRITE) {
+		p = (fp->flags & _IOLBF) ? fp->lp : fp->wp;
+		return off + (p - fp->buf);
+	}
+	return off;
+}
--- /dev/null
+++ b/lib/c/stdio/fwrite.c
@@ -1,0 +1,24 @@
+#include <stdio.h>
+#undef fwrite
+
+size_t
+fwrite(const void * restrict ptr, size_t size, size_t nmemb,
+       FILE * restrict fp)
+{
+	const unsigned char *bp = ptr;
+	size_t n, i;
+
+	if (size == 0)
+		return 0;
+
+	for (n = 0; n < nmemb; n++) {
+		i = size;
+		do
+			putc(*bp++, fp);
+		while (--i);
+		if (ferror(fp))
+			break;
+	}
+
+	return n;
+}
--- /dev/null
+++ b/lib/c/stdio/getc.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef getc
+
+int
+getc(FILE *fp)
+{
+	return (fp->rp >= fp->wp) ?  __getc(fp) : *fp->rp++;
+}
--- /dev/null
+++ b/lib/c/stdio/getchar.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef getchar
+
+int
+getchar(void)
+{
+	return getc(stdin);
+}
--- /dev/null
+++ b/lib/c/stdio/gets.c
@@ -1,0 +1,17 @@
+#include <stdio.h>
+#undef gets
+
+char *
+gets(char *s)
+{
+	int ch;
+	char *t = s;
+
+	while ((ch = getc(stdin)) != EOF && ch != '\n')
+		*t++ = ch;
+	if (ch == EOF && s == t)
+		return NULL;
+	*t = '\0';
+
+	return s;
+}
--- /dev/null
+++ b/lib/c/stdio/perror.c
@@ -1,0 +1,16 @@
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#undef perror
+
+void
+perror(const char *msg)
+{
+	if (msg && *msg) {
+		fputs(msg, stderr);
+		putc(':', stderr);
+		putc(' ', stderr);
+	}
+	fputs(strerror(errno), stderr);
+	putc('\n', stderr);
+}
--- /dev/null
+++ b/lib/c/stdio/printf.c
@@ -1,0 +1,15 @@
+#include <stdarg.h>
+#include <stdio.h>
+#undef printf
+
+int
+printf(const char * restrict fmt, ...)
+{
+	int cnt;
+	va_list va;
+
+	va_start(va, fmt);
+	cnt = vfprintf(stdout, fmt, va);
+	va_end(va);
+	return cnt;
+}
--- /dev/null
+++ b/lib/c/stdio/putc.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef putc
+
+int
+putc(int ch, FILE *fp)
+{
+	return (fp->wp >= fp->rp) ? __putc(ch,fp) : (*fp->wp++ = ch);
+}
--- /dev/null
+++ b/lib/c/stdio/putchar.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef putchar
+
+int
+putchar(int ch)
+{
+	return putc(ch, stdout);
+}
--- /dev/null
+++ b/lib/c/stdio/puts.c
@@ -1,0 +1,12 @@
+#include <stdio.h>
+#undef puts
+
+int
+puts(const char *str)
+{
+	int ch;
+
+	while (ch = *str++)
+		putchar(ch);
+	return putchar('\n');
+}
--- /dev/null
+++ b/lib/c/stdio/rewind.c
@@ -1,0 +1,10 @@
+#include <stdio.h>
+#undef rewind
+
+void
+rewind(FILE *fp)
+{
+	fp->flags &= ~_IOERR;
+	fseek(fp, 0, SEEK_SET);
+	clearerr(fp);
+}
--- /dev/null
+++ b/lib/c/stdio/setbuf.c
@@ -1,0 +1,8 @@
+#include <stdio.h>
+#undef setbuf
+
+void
+setbuf(FILE * restrict fp, char * restrict buf)
+{
+	setvbuf(fp, buf, (buf) ? _IOFBF : _IONBF, BUFSIZ);
+}
--- /dev/null
+++ b/lib/c/stdio/setvbuf.c
@@ -1,0 +1,48 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#undef setvbuf
+
+int
+setvbuf(FILE * restrict fp, char * restrict buf, int mode, size_t size)
+{
+	int flags;
+	char *p;
+	size_t l;
+
+	if (_flsbuf(fp) == EOF)
+		return EOF;
+
+	if (buf)
+		p = buf, l = size;
+	else
+		p = fp->buf, l = fp->len;
+
+	switch (mode) {
+	case _IONBF:
+		l = sizeof(fp->unbuf);
+		p = fp->unbuf;
+	case _IOLBF:
+	case _IOFBF:
+		fp->rp = fp->wp = p;
+		fp->lp = p + l;
+		break;
+	default:
+		errno = EINVAL;
+		return EOF;
+	}
+
+	flags = fp->flags;
+	if (flags&_IOALLOC && (buf || mode == _IONBF)) {
+		free(fp->buf);
+		flags &= ~_IOALLOC;
+	}
+
+	fp->buf = p;
+	fp->len = l;
+	flags &= ~(_IONBF | _IOLBF | _IOFBF);
+	flags |= mode;
+	fp->flags = flags;
+
+	return 0;
+}
--- /dev/null
+++ b/lib/c/stdio/snprintf.c
@@ -1,0 +1,16 @@
+#include <stdarg.h>
+#include <stdio.h>
+#undef snprintf
+
+int
+snprintf(char * restrict s, size_t siz, const char * restrict fmt, ...)
+{
+	int r;
+	va_list va;
+
+	va_start(va, fmt);
+	r = vsnprintf(s, siz, fmt, va);
+	va_end(va);
+
+	return r;
+}
--- /dev/null
+++ b/lib/c/stdio/sprintf.c
@@ -1,0 +1,16 @@
+#include <stdarg.h>
+#include <stdio.h>
+#undef sprintf
+
+int
+sprintf(char * restrict s, const char * restrict fmt, ...)
+{
+	int r;
+
+	va_list va;
+	va_start(va, fmt);
+	r = vsprintf(s, fmt, va);
+	va_end(va);
+
+	return r;
+}
--- /dev/null
+++ b/lib/c/stdio/tmpnam.c
@@ -1,0 +1,31 @@
+#include <stdio.h>
+#include <string.h>
+#include "../syscall.h"
+#undef tmpnam
+
+char *
+tmpnam(char *s)
+{
+	static char *tmpl, buf[L_tmpnam];
+	char *p;
+
+	if (*buf == '\0') {
+		for (tmpl = buf, p = _TMPNAME; *tmpl++ = *p++; )
+			;
+		for (p = tmpl; p < &buf[L_tmpnam-1]; ++p)
+			*p = '0';
+		*p = '\0';
+	}
+	for (;;) {
+		for (p = tmpl; *p && *p != '9'; ++p)
+			;
+		if (*p == '\0')
+			return NULL;
+		++*p;
+		if (_access(buf, 0) != 0)
+			break;
+	}
+	if (s)
+		strcpy(s, buf);
+	return buf;
+}
--- /dev/null
+++ b/lib/c/stdio/vfprintf.c
@@ -1,0 +1,362 @@
+#include <ctype.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+#undef vfprintf
+
+enum {
+	LONG     = 1 << 0,
+	LLONG    = 1 << 1,
+	SHORT    = 1 << 2,
+	CHAR     = 1 << 3,
+	SIZET    = 1 << 4,
+	PTRDIFF  = 1 << 5,
+	INTMAX   = 1 << 6,
+	VOIDPTR  = 1 << 7,
+	UNSIGNED = 1 << 8,
+	ALTFORM  = 1 << 9,
+};
+
+#define MAXPREC    50
+
+struct conv {
+	int sign;
+	int prec;
+	char *digs;
+	int base;
+};
+
+static uintmax_t
+getnum(va_list *va, int flags, int *sign)
+{
+	uintmax_t uval;
+	intmax_t val;
+
+	if (flags & CHAR) {
+		val = va_arg(*va, int);
+		uval = (unsigned char) val;
+	} else if (flags & SHORT) {
+		val = va_arg(*va, int);
+		uval = (unsigned short) val;
+	} else if (flags & LONG) {
+		val = va_arg(*va, long);
+		uval = (unsigned long) val;
+	} else if (flags & LLONG) {
+		val = va_arg(*va, long long);
+		uval = (unsigned long long) val;
+	} else if (flags & SIZET) {
+		uval = va_arg(*va, size_t);
+	} else if (flags & INTMAX) {
+		val = va_arg(*va, intmax_t);
+		uval = (uintmax_t) val;
+	} else if (flags & VOIDPTR) {
+		uval = (uintmax_t) va_arg(*va, void *);
+	} else {
+		val = va_arg(*va, int);
+		uval = (unsigned) val;
+	}
+
+	if ((flags & UNSIGNED) == 0 && val < 0) {
+		*sign = '-';
+		uval = -uval;
+	}
+	return uval;
+}
+
+static char *
+numtostr(uintmax_t val, int flags, struct conv *conv, char *buf)
+{
+	char *buf0 = buf;
+	int base = conv->base, prec = conv->prec;
+	uintmax_t oval = val;
+
+	if (prec == -1)
+		prec = 1;
+
+	for (*buf = '\0'; val > 0; val /= base)
+		*--buf = conv->digs[val % base];
+	while (buf0 - buf < prec)
+		*--buf = '0';
+
+	if (flags & ALTFORM) {
+		if (base == 8 && *buf != '0') {
+			*--buf = '0';
+		} else if (base == 16 && oval != 0) {
+			*--buf = conv->digs[16];
+			*--buf = '0';
+		}
+	}
+	if (conv->sign)
+		*--buf = conv->sign;
+
+	return buf;
+}
+
+static void
+savecnt(va_list *va, int flags, int cnt)
+{
+	if (flags & CHAR)
+		*va_arg(*va, char*) = cnt;
+	else if (flags & SHORT)
+		*va_arg(*va, short*) = cnt;
+	else if (flags & LONG)
+		*va_arg(*va, long*) = cnt;
+	else if (flags & LLONG)
+		*va_arg(*va, long long*) = cnt;
+	else if (flags & SIZET)
+		*va_arg(*va, size_t*) = cnt;
+	else if (flags & INTMAX)
+		*va_arg(*va, intmax_t*) = cnt;
+	else
+		*va_arg(*va, int*) = cnt;
+}
+
+static size_t
+wstrout(wchar_t *ws, size_t len, int width, int fill, FILE * restrict fp)
+{
+	int left = 0, adjust;
+	size_t cnt = 0;
+	wchar_t wc;
+#if 0
+
+	if (width < 0) {
+		left = 1;
+		width = -width;
+	}
+
+	len *= sizeof(wchar_t);
+	adjust = (len < width) ? width - len : 0;
+	cnt = adjust + len;
+	if (left)
+		adjust = -adjust;
+
+	for ( ; adjust > 0; adjust++)
+		putc(fill, fp);
+
+	while (wc = *ws++)
+		putwc(wc, fp);
+
+	for ( ; adjust < 0; adjust--)
+		putc(' ', fp);
+#endif
+	return cnt;
+}
+
+static size_t
+strout(char *s, size_t len, int width, int fill, FILE * restrict fp)
+{
+	int left = 0, adjust, ch, prefix;
+	size_t cnt = 0;
+
+	if (width < 0) {
+		left = 1;
+		width = -width;
+	}
+
+	adjust = (len < width) ? width - len : 0;
+	cnt = adjust + len;
+	if (left)
+		adjust = -adjust;
+
+	if (fill == '0') {
+		if (*s == '-' || *s == '+')
+			prefix = 1;
+		else if (*s == '0' && toupper(s[1]) == 'X')
+			prefix = 2;
+		else
+			prefix = 0;
+		while (prefix--) {
+			putc(*s++, fp);
+			--len;
+		}
+	}
+
+	for ( ; adjust > 0; adjust--)
+		putc(fill, fp);
+
+	while (ch = *s++)
+		putc(ch, fp);
+
+	for ( ; adjust < 0; adjust++)
+		putc(' ', fp);
+
+	return cnt;
+}
+
+int
+vfprintf(FILE * restrict fp, const char *fmt, va_list va)
+{
+	int ch, n, flags, width, left, fill, cnt = 0;
+	size_t inc, len;
+	char *s;
+	wchar_t *ws;
+	struct conv conv;
+	char buf[MAXPREC+1];
+	wchar_t wbuf[2];
+	va_list va2;
+
+	va_copy(va2, va);
+	for (cnt = 0; ch = *fmt++; cnt += inc) {
+		if (ch != '%') {
+			putc(ch, fp);
+			inc = 1;
+			continue;
+		}
+
+		fill = ' ';
+		left = flags = width =  0;
+		conv.prec = -1;
+		conv.base = 10;
+		conv.sign = '\0';
+		conv.digs = "0123456789ABCDEFX";
+
+flags:
+		switch (*fmt++) {
+		case ' ':
+			if (conv.sign == '\0')
+				conv.sign = ' ';
+			goto flags;
+		case '+':
+			conv.sign = '+';
+			goto flags;
+		case '#':
+			flags |= ALTFORM;
+			goto flags;
+		case '.':
+			if (*fmt == '*') {
+				fmt++;
+				n = va_arg(va2, int);
+			} else {
+				for (n = 0; isdigit(ch = *fmt); fmt++)
+					n = n * 10 + ch - '0';
+			}
+			if (n > MAXPREC)
+				n = MAXPREC;
+			if (n > 0)
+				conv.prec = n;
+			goto flags;
+		case '*':
+			width = va_arg(va2, int);
+			goto flags;
+		case '-':
+			left = 1;
+			++fmt;
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+		case '8':
+		case '9':
+			--fmt;
+			for (n = 0; isdigit(ch = *fmt); ++fmt)
+				n = n * 10 + ch - '0';
+			if (left)
+				n = -n;
+			width = n;
+			goto flags;
+		case '0':
+			fill = '0';
+			goto flags;
+		case 'l':
+			flags += LONG;
+			goto flags;
+		case 'h':
+			flags += SHORT;
+			goto flags;
+		case '%':
+			ch = '%';
+			goto cout;
+		case 'c':
+			if (flags & LONG) {
+				wbuf[0] = va_arg(va2, wint_t);
+				wbuf[1] = L'\0';
+				ws = wbuf;
+				len = 1;
+				goto wstrout;
+			}
+			ch = va_arg(va2, int);
+		cout:
+			buf[0] = ch;
+			buf[1] = '\0';
+			s = buf;
+			len = 1;
+			goto strout;
+		case 'j':
+			flags |= INTMAX;
+			goto flags;
+		case 't':
+			flags |= PTRDIFF;
+			goto flags;
+		case 'z':
+			flags |= SIZET;
+			goto flags;
+		case 'u':
+			flags |= UNSIGNED;
+		case 'i':
+		case 'd':
+			conv.base = 10;
+			goto numeric;
+		case 'p':
+			flags |= VOIDPTR | ALTFORM;
+			goto numeric16;
+		case 'x':
+			conv.digs = "0123456789abcdefx";
+		case 'X':
+		numeric16:
+			conv.base = 16;
+			flags |= UNSIGNED;
+			goto numeric;
+		case 'o':
+			conv.base = 8;
+			flags |= UNSIGNED;
+		numeric:
+			if (conv.prec != -1)
+				fill = ' ';
+			s = numtostr(getnum(&va2, flags, &conv.sign),
+			             flags,
+			             &conv,
+			             &buf[MAXPREC]);
+			len = &buf[MAXPREC] - s;
+			goto strout;
+		case 'L':
+		case 'a':
+		case 'A':
+		case 'e':
+		case 'E':
+		case 'f':
+		case 'g':
+		case 'G':
+			/* TODO */
+		case 's':
+			if (flags & LONG) {
+				ws = va_arg(va2, wchar_t *);
+				/* len = wcsnlen(ws, conv.prec); */
+				goto wstrout;
+			} else {
+				s = va_arg(va2, char *);
+				len = strnlen(s, conv.prec);
+				goto strout;
+			}
+		wstrout:
+			inc = wstrout(ws, len, width, fill, fp);
+			break;
+		strout:
+			inc = strout(s, len, width, fill, fp);
+			break;
+		case 'n':
+			savecnt(&va2, flags, cnt);
+			break;
+		case '\0':
+			goto out_loop;
+		}
+	}
+
+out_loop:
+	return (ferror(fp)) ? EOF : cnt;
+}
--- /dev/null
+++ b/lib/c/stdio/vprintf.c
@@ -1,0 +1,12 @@
+#include <stdarg.h>
+#include <stdio.h>
+#undef vprintf
+
+int
+vprintf(const char *fmt, va_list ap)
+{
+	va_list ap2;
+
+	va_copy(ap2, ap);
+	return vfprintf(stdout, fmt, ap2);
+}
--- /dev/null
+++ b/lib/c/stdio/vsnprintf.c
@@ -1,0 +1,25 @@
+#include <stdarg.h>
+#include <stdio.h>
+#undef vsnprintf
+
+int
+vsnprintf(char * restrict s, size_t siz, const char * restrict fmt, va_list ap)
+{
+	FILE f;
+	int r;
+
+	f.flags = _IORW | _IOSTRG;
+	f.len = siz;
+	f.buf = s;
+	f.wp = s;
+	f.rp = s + siz;
+
+	r = vfprintf(&f, fmt, ap);
+	if (s) {
+		if (f.wp == f.rp)
+			--f.wp;
+		*f.wp = '\0';
+	}
+
+	return r;
+}
--- /dev/null
+++ b/lib/c/stdio/vsprintf.c
@@ -1,0 +1,12 @@
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#undef vsprintf
+
+
+int
+vsprintf(char * restrict s, const char * restrict fmt, va_list va)
+{
+	return vsnprintf(s, SIZE_MAX, fmt, va);
+}
--- /dev/null
+++ b/lib/c/stdlib/Makefile
@@ -1,0 +1,25 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = abort.o\
+       abs.o\
+       atexit.o\
+       atoi.o\
+       atol.o\
+       atoll.o\
+       bsearch.o\
+       calloc.o\
+       errno.o\
+       exit.o\
+       labs.o\
+       llabs.o\
+       malloc.o\
+       qsort.o\
+       rand.o\
+       realloc.o\
+       strtoull.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/stdlib/abort.c
@@ -1,0 +1,10 @@
+#include <signal.h>
+#include <stdlib.h>
+#undef abort
+
+void
+abort(void)
+{
+	raise(SIGABRT);
+	_Exit(127);
+}
--- /dev/null
+++ b/lib/c/stdlib/abs.c
@@ -1,0 +1,8 @@
+#include <stdlib.h>
+#undef abs
+
+int
+abs(int n)
+{
+	return (n < 0) ? -n : n;
+}
--- /dev/null
+++ b/lib/c/stdlib/atexit.c
@@ -1,0 +1,17 @@
+#include <stdlib.h>
+#include <errno.h>
+#undef atexit
+
+extern void (*_exitf[_ATEXIT_MAX])(void);
+extern unsigned _exitn;
+
+int
+atexit(void (*fun)(void))
+{
+	if (_exitn == _ATEXIT_MAX) {
+		errno = ENOMEM;
+		return -1;
+	}
+	_exitf[_exitn++] = fun;
+	return 0;
+}
--- /dev/null
+++ b/lib/c/stdlib/atoi.c
@@ -1,0 +1,25 @@
+#include <ctype.h>
+#include <stdlib.h>
+#undef atoi
+
+int
+atoi(const char *s)
+{
+	int n, sign = -1;
+
+	while (isspace(*s))
+		++s;
+
+	switch (*s) {
+	case '-':
+		sign = 1;
+	case '+':
+		++s;
+	}
+
+	/* Compute n as a negative number to avoid overflow on INT_MIN */
+	for (n = 0; isdigit(*s); ++s)
+		n = 10*n - (*s - '0');
+
+	return sign * n;
+}
--- /dev/null
+++ b/lib/c/stdlib/atol.c
@@ -1,0 +1,26 @@
+#include <ctype.h>
+#include <stdlib.h>
+#undef atol
+
+long
+atol(const char *s)
+{
+	int sign = -1;
+	long n;
+
+	while (isspace(*s))
+		++s;
+
+	switch (*s) {
+	case '-':
+		sign = 1;
+	case '+':
+		++s;
+	}
+
+	/* Compute n as a negative number to avoid overflow on LONG_MIN */
+	for (n = 0; isdigit(*s); ++s)
+		n = 10*n - (*s - '0');
+
+	return sign * n;
+}
--- /dev/null
+++ b/lib/c/stdlib/atoll.c
@@ -1,0 +1,26 @@
+#include <ctype.h>
+#include <stdlib.h>
+#undef atoll
+
+long long
+atoll(const char *s)
+{
+	int sign = -1;
+	long long n;
+
+	while (isspace(*s))
+		++s;
+
+	switch (*s) {
+	case '-':
+		sign = 1;
+	case '+':
+		++s;
+	}
+
+	/* Compute n as a negative number to avoid overflow on LLONG_MIN */
+	for (n = 0; isdigit(*s); ++s)
+		n = 10*n - (*s - '0');
+
+	return sign * n;
+}
--- /dev/null
+++ b/lib/c/stdlib/bsearch.c
@@ -1,0 +1,26 @@
+#include <stdlib.h>
+
+void *
+bsearch(const void *key, const void *ary, size_t n, size_t size,
+        int (*cmp)(const void *, const void *))
+{
+	int t;
+	size_t mid, low, high;
+	char *cur, *base = ary;
+
+	low = 0;
+	high = n - 1;
+	while (low <= high) {
+		mid = low + (high - low) / 2;
+		cur = base + mid*size;
+
+		if ((t = (*cmp)(key, cur)) == 0)
+			return cur;
+		else if (t > 0)
+			low = mid + 1;
+		else
+			high = mid - 1;
+	}
+
+	return NULL;
+}
--- /dev/null
+++ b/lib/c/stdlib/calloc.c
@@ -1,0 +1,18 @@
+#include <stdlib.h>
+#include <string.h>
+#undef calloc
+
+void *
+calloc(size_t nmemb, size_t size)
+{
+	size_t nbytes;
+	void *mem;
+
+	if (!nmemb || !size || nmemb > (size_t)-1/size)
+                return NULL;
+
+	nbytes = nmemb * size;
+	if ((mem = malloc(nbytes)) == NULL)
+		return NULL;
+	return memset(mem, 0, nbytes);
+}
--- /dev/null
+++ b/lib/c/stdlib/errno.c
@@ -1,0 +1,1 @@
+int errno;
--- /dev/null
+++ b/lib/c/stdlib/exit.c
@@ -1,0 +1,13 @@
+#include <stdlib.h>
+#undef exit
+
+void (*_exitf[_ATEXIT_MAX])(void);
+unsigned _exitn;
+
+void
+exit(int status)
+{
+	while (_exitn > 0)
+		(*_exitf[--_exitn])();
+	_Exit(status);
+}
--- /dev/null
+++ b/lib/c/stdlib/labs.c
@@ -1,0 +1,8 @@
+#include <stdlib.h>
+#undef labs
+
+long
+labs(long n)
+{
+	return (n < 0) ? -n : n;
+}
--- /dev/null
+++ b/lib/c/stdlib/llabs.c
@@ -1,0 +1,8 @@
+#include <stdlib.h>
+#undef llabs
+
+long long
+llabs(long long n)
+{
+	return (n < 0) ? -n : n;
+}
--- /dev/null
+++ b/lib/c/stdlib/malloc.c
@@ -1,0 +1,158 @@
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "malloc.h"
+#include "../syscall.h"
+
+#define MAXADDR ((char *)-1)
+#define ERRADDR ((char *)-1)
+
+static Header base = { .h.next = &base };
+static Header *freep = &base;
+
+/*
+ * Run over the free list looking for the nearest previous
+ * block. There are two possible results: end of the list
+ * or an intermediary block.
+ */
+void *
+_prevchunk(Header *hp)
+{
+	Header *p;
+
+	for (p = freep; ;p = p->h.next) {
+		/* hp between p and p->h.next? */
+		if (p < hp && hp < p->h.next)
+			break;
+		/* p before hp and hp at the end of list? */
+		if (p->h.next <= p && (hp < p->h.next || hp > p))
+			break;
+	}
+	return p;
+}
+
+/*
+ * Get the previous block and try to merge
+ * with next and previous blocks
+ */
+void
+free(void *mem)
+{
+	Header *hp, *prev;
+
+	if (!mem)
+		return;
+
+	hp = (Header *) mem - 1;
+	prev = _prevchunk(hp);
+
+	/* join to next */
+	if (hp + hp->h.size == prev->h.next) {
+		hp->h.size += prev->h.next->h.size;
+		hp->h.next = prev->h.next->h.next;
+	} else {
+		hp->h.next = prev->h.next;
+	}
+
+	/* join to previous */
+	if (prev + prev->h.size == hp) {
+		prev->h.size += hp->h.size;
+		prev->h.next = hp->h.next;
+	} else {
+		prev->h.next = hp;
+	}
+
+	freep = prev;
+}
+
+static void *
+sbrk(uintptr_t inc)
+{
+	char *new, *old;
+	void *p;
+	static void *heap;
+
+	if (!heap)
+		heap = _getheap();
+	old = heap;
+	if (old >= MAXADDR - inc)
+		return ERRADDR;
+	new = old + inc;
+	p = _brk(new);
+	if (p == old || p < 0)
+		return ERRADDR;
+	heap = new;
+
+	return old;
+}
+
+static Header *
+morecore(size_t nunits)
+{
+	char *rawmem;
+	Header *hp;
+
+	if (nunits < NALLOC)
+		nunits = NALLOC;
+
+	rawmem = sbrk(nunits * sizeof(Header));
+	if (rawmem == ERRADDR)
+		return NULL;
+
+	hp = (Header*)rawmem;
+	hp->h.size = nunits;
+
+	/* integrate new memory into the list */
+	free(hp + 1);
+
+	return freep;
+}
+
+/*
+ * Run over the list of free blocks trying to find a block
+ * big enough for nbytes. If the block fit perfectly with
+ * the required size then we only have to unlink
+ * the block. Otherwise we have to split the block and
+ * return the right part. If we run over the full list
+ * without a fit then we have to require more memory
+ *
+ *              ______________________________________
+ * ___________./______________________________________\_____
+ * ...| in   |   |     | in  |  |.....| in   |  |    | |....
+ * ...| use  |   |     | use |  |.....| use  |  |    | |....
+ * ___|______|___|.____|_____|._|_____|______|._|.___|.|____
+ *            \__/ \_________/ \_____________/ \/ \__/
+ */
+void *
+malloc(size_t nbytes)
+{
+	Header *cur, *prev;
+	size_t nunits;
+
+	/* 1 unit for header plus enough units to fit nbytes */
+	nunits = (nbytes+sizeof(Header)-1) / sizeof(Header) + 1;
+
+	for (prev = freep; ; prev = cur) {
+		cur = prev->h.next;
+		if (cur->h.size >= nunits) {
+			if (cur->h.size == nunits) {
+				prev->h.next = cur->h.next;
+			} else {
+				cur->h.size -= nunits;
+				cur += cur->h.size;
+				cur->h.size = nunits;
+			}
+			freep = prev;
+			return cur + 1;
+		}
+
+		if (cur == freep) {
+			if ((cur = morecore(nunits)) == NULL) {
+				errno = ENOMEM;
+				return NULL;
+			}
+		}
+	}
+}
--- /dev/null
+++ b/lib/c/stdlib/malloc.h
@@ -1,0 +1,16 @@
+#include <stdlib.h>
+
+/* minimum amount of required units */
+#define NALLOC 10000
+
+typedef union header Header;
+union header {
+	struct hdr {
+		Header *next;
+		size_t size;
+	} h;
+	/* most restrictive type fixes the union size for alignment */
+	_ALIGNTYPE most;
+};
+
+extern void *_prevchunk(Header *hp);
--- /dev/null
+++ b/lib/c/stdlib/qsort.c
@@ -1,0 +1,68 @@
+#include <stdlib.h>
+#include <string.h>
+#undef qsort
+
+/*
+ * This implementation of qsort is based in the paper
+ * "Engineering a Sort Function", by Jon L.Bentley and M. Douglas McIlroy.
+ * A lot of different optimizations were removed to make the code simpler.
+ */
+
+struct qsort {
+	size_t es;
+	int (*cmp)(const void *, const void *);
+};
+
+static void
+swap(char *i, char *j, size_t n)
+{
+	do {
+		char c = *i;
+		*i++ = *j;
+		*j++ = c;
+	} while (--n > 0);
+}
+
+static void
+xqsort(char *a, size_t n, struct qsort *qs)
+{
+	size_t j, es = qs->es;
+	char *pi, *pj, *pn;
+
+	if (n <= 1)
+		return;
+
+	pi = a;
+	pn = pj = a + n*es;
+
+	swap(a, a + n/2 * es,  es);
+	for (;;) {
+		do {
+			pi += es;
+		} while  (pi < pn && qs->cmp(pi, a) < 0);
+
+		do {
+			pj -= es;
+		} while (pj > a && qs->cmp(pj, a) > 0);
+
+		if (pj < pi)
+			break;
+		swap(pi, pj, es);
+	}
+	swap(a, pj, es);
+
+	j = (pj - a) / es;
+	xqsort(a, j, qs);
+	xqsort(a + (j+1)*es, n-j-1, qs);
+}
+
+void
+qsort(void *base, size_t nmemb, size_t size,
+      int (*f)(const void *, const void *))
+{
+	struct qsort qs;
+
+	qs.cmp = f;
+	qs.es = size;
+	xqsort(base, nmemb, &qs);
+}
--- /dev/null
+++ b/lib/c/stdlib/rand.c
@@ -1,0 +1,18 @@
+#include <stdlib.h>
+#undef rand
+#undef srand
+
+static unsigned long next;
+
+void
+srand(unsigned seed)
+{
+	next = seed;
+}
+
+int
+rand(void)  /* RAND_MAX assumed to be 32767. */
+{
+	next = next * 1103515245 + 12345;
+	return (unsigned)(next/65536) % 32768;
+}
--- /dev/null
+++ b/lib/c/stdlib/realloc.c
@@ -1,0 +1,68 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "malloc.h"
+#undef realloc
+
+void *
+realloc(void *ptr, size_t nbytes)
+{
+	Header *oh, *prev, *next, *new;
+	size_t nunits, avail, onbytes, n;
+
+	if (!nbytes)
+		return NULL;
+
+	if (!ptr)
+		return malloc(nbytes);
+
+	nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
+	oh = (Header*)ptr - 1;
+
+	if (oh->h.size == nunits)
+		return ptr;
+
+	new = oh + nunits;
+
+	if (nunits < oh->h.size - 1) {
+		new->h.size = oh->h.size - nunits;
+		oh->h.size = nunits;
+		free(new + 1);
+		return oh;
+	}
+
+	prev = _prevchunk(oh);
+
+	if (oh + oh->h.size == prev->h.next) {
+		/*
+		 * if there is free space adjacent
+		 * to the current memory
+		 */
+		next = prev->h.next;
+		avail = oh->h.size + next->h.size;
+
+		if (avail == nunits) {
+			oh->h.size = nunits;
+			prev->h.next = next->h.next;
+			return oh;
+		}
+
+		if (avail > nunits) {
+			oh->h.size = nunits;
+			prev->h.next = new;
+			new->h.next = next;
+			new->h.size = avail - nunits;
+			return oh;
+		}
+	}
+
+	onbytes = (oh->h.size - 1) * sizeof(Header);
+	if ((new = malloc(nbytes)) == NULL)
+		return NULL;
+
+	n = (onbytes > nbytes) ? nbytes : onbytes;
+	memcpy(new, ptr, n);
+	free(ptr);
+
+	return new;
+}
--- /dev/null
+++ b/lib/c/stdlib/strtoull.c
@@ -1,0 +1,64 @@
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+
+#undef strtoull
+
+unsigned long long
+strtoull(const char *s, char **end, int base)
+{
+	int d, sign = 1;
+	unsigned long long n;
+	static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+	const char *t, *p;
+
+	while (isspace(*s))
+		++s;
+
+	switch (*s) {
+	case '-':
+		sign = -1;
+	case '+':
+		++s;
+	}
+
+	if (base == 0) {
+		if (*s == '0' && toupper(s[1]) == 'X')
+			base = 16;
+		else if (*s == '0')
+			base = 8;
+		else
+			base = 10;
+	}
+
+	if (base == 16 && *s == '0' && toupper(s[1]) == 'X')
+		s += 2;
+
+	n = 0;
+	for (t = s; p = strchr(digits, toupper(*t)); ++t) {
+		if ((d = p - digits) >= base)
+			break;
+		if (n > ULLONG_MAX/base)
+			goto overflow;
+		n *= base;
+		if (d > ULLONG_MAX - n)
+			goto overflow;
+		n += d;
+	}
+
+
+	if (end)
+		*end = t;
+	if (n == 0 && s == t)
+		errno = EINVAL;
+	return n*sign;
+
+overflow:
+	if (end)
+		*end = t;
+	errno = ERANGE;
+
+	return ULLONG_MAX;
+}
--- a/lib/c/strcat.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <string.h>
-#undef strcat
-
-char *
-strcat(char * restrict dst, const char * restrict src)
-{
-	char *ret = dst;
-
-	while (*dst)
-		++dst;
-	while (*dst++ = *src++)
-		;
-	return ret;
-}
--- a/lib/c/strchr.c
+++ /dev/null
@@ -1,10 +1,0 @@
-#include <string.h>
-#undef strchr
-
-char *
-strchr(const char *s, int c)
-{
-	while (*s && *s != c)
-		++s;
-	return (*s == c) ? (char *)s : NULL;
-}
--- a/lib/c/strcmp.c
+++ /dev/null
@@ -1,10 +1,0 @@
-#include <string.h>
-#undef strcmp
-
-int
-strcmp(const char *s1, const char *s2)
-{
-	while (*s1 && *s2 && *s1 == *s2)
-		++s1, ++s2;
-	return *(unsigned char *)s1 - *(unsigned char *)s2;
-}
--- a/lib/c/strcoll.c
+++ /dev/null
@@ -1,10 +1,0 @@
-#include <string.h>
-#undef strcoll
-
-int
-strcoll(const char *s1, const char *s2)
-{
-	while (*s1 && *s2 && *s1 == *s2)
-		++s1, ++s2;
-	return *(unsigned char *) s1 - *(unsigned char *) s2;
-}
--- a/lib/c/strcpy.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <string.h>
-#undef strcpy
-
-char *
-strcpy(char * restrict dst, const char * restrict src)
-{
-	char *ret = dst;
-
-	while (*dst++ = *src++)
-		;
-	return ret;
-}
--- a/lib/c/strcspn.c
+++ /dev/null
@@ -1,21 +1,0 @@
-#include <string.h>
-#undef strcspn
-
-size_t
-strcspn(const char *s1, const char *s2)
-{
-	const unsigned char *s = s1;
-	const unsigned char *accept = s2;
-	unsigned ch;
-	size_t n;
-	char buf[__NUMCHARS];
-
-	memset(buf, 0, sizeof(buf));
-	while (ch = *accept++)
-		buf[ch] = 1;
-
-	for (n = 0; (ch = *s++) && !buf[ch]; ++n)
-		;
-
-	return n;
-}
--- a/lib/c/strerror.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <errno.h>
-#include <string.h>
-#undef strerror
-
-char *
-strerror(int errnum)
-{
-	if (errnum < _sys_nerr)
-		return _sys_errlist[errnum];
-	else
-		return "Unknown error";
-}
--- a/lib/c/strftime.c
+++ /dev/null
@@ -1,246 +1,0 @@
-#include <time.h>
-#include <string.h>
-#include "libc.h"
-#undef strftime
-
-static char *days[] = {
-	"Sunday",   "Monday", "Tuesday",  "Wednesday",
-	"Thursday", "Friday", "Saturday", 
-};
-
-static char *months[] = {
-	"January",   "February", "March",    "April",
-	"May",       "June",     "July",     "August",
-	"September", "October",  "November", "December"
-};
-
-static char *am_pm[] = {"AM", "PM"};
-
-static size_t
-sval(char *s, size_t siz, char **strs, int abrev, int idx, int max)
-{
-	char *str;
-	size_t len;
-
-	if (idx < 0 && idx >= max)
-		goto wrong;
-
-	str = strs[idx];
-	len = (!abrev) ? strlen(str) : 3;
-	if (len > siz)
-		goto wrong;
-
-	memcpy(s, str, len);
-	return len;
-
-wrong:
-	*s = '?';
-	return 1;
-}
-
-static size_t
-dval(char *s, size_t siz, int prec, int fill, int val)
-{
-	char *t;
-	int n;
-	static char digits[] = "0123456789";
-
-	if (prec > siz || val < 0) {
-		*s = '?';
-		return 1;
-	}
-
-	n = prec;
-	do {
-		s[--n] = digits[val % 10];
-		val /= 10;
-	} while (n > 0 && val > 0);
-
-	while (n > 0)
-		s[--n] = fill;
-
-	return prec;
-}
-
-static size_t
-timezone(char *s, size_t prec, const struct tm * restrict tm)
-{
-	long off = tm->tm_gmtoff;
-
-	if (prec < 5) {
-		*s = '?';
-		return 1;
-	}
-
-	if (off >= 0) {
-		*s++ = '+';
-	} else {
-		*s++ = '-';
-		off = -off;
-	}
-
-	dval(s, 2, 2, '0', off / 3600);
-	dval(s, 2, 2, '0', (off % 3600) / 60);
-
-	return 5;
-}
-
-size_t
-strftime(char * restrict s, size_t siz,
-         const char * restrict fmt,
-         const struct tm * restrict tm)
-{
-	int ch, abrev, val, fill, width;
-	size_t n, inc;
-	char *tfmt;
-
-	for (n = siz-1; (ch = *fmt++) && n > 0; s += inc, n -= inc) {
-		if (ch != '%') {
-			*s = ch;
-			inc = 1;
-			continue;
-		}
-
-		abrev = 0;
-		fill = '0';
-		width = 2;
-
-		switch (*fmt++) {
-		case 'Z':
-			if (!tm->tm_zone)
-				break;
-			inc = sval(s, n, &tm->tm_zone, 0, 0, 1);
-			break;
-		case 'a':
-			abrev = 1;
-		case 'A':
-			inc = sval(s, n, days, abrev, tm->tm_wday, 7);
-			break;
-		case 'h':
-		case 'b':
-			abrev = 1;
-		case 'B':
-			inc = sval(s, n, months, abrev, tm->tm_mon, 12);
-			break;
-		case 'p':
-			inc = sval(s, n, am_pm, 0, tm->tm_hour > 12, 2);
-			break;
-		case 'c':
-			tfmt = "%a %b %e %T %Y";
-			goto recursive;
-		case 'D':
-			tfmt = "%m/%d/%y";
-			goto recursive;
-		case 'F':
-			tfmt = "%Y-%m-%d";
-			goto recursive;
-		case 'R':
-			tfmt = "%H:%M";
-			goto recursive;
-		case 'X':
-		case 'T':
-			tfmt = "%H:%M:%S";
-			goto recursive;
-		case 'r':
-			tfmt = "%I:%M:%S %p";
-			goto recursive;
-		case 'x':
-			tfmt = "%m/%d/%y";
-			goto recursive;
-		recursive:
-			inc = strftime(s, n+1, tfmt, tm) - 1;
-			break;
-		case 'n':
-			val = '\n';
-			goto character;
-		case 't': 
-			val = '\t';
-			goto character;
-		case '%': 
-			val = '%';
-		character:
-			*s = val;
-			inc = 1;
-			break;
-		case 'e':
-			fill = ' ';
-			val = tm->tm_mday;
-			goto number;
-		case 'd':
-			val = tm->tm_mday;
-			goto number;
-		case 'V':
-		case 'g':
-		case 'G':
-			/* TODO */
-			break;
-		case 'C':
-			val = tm->tm_year / 100;
-			goto number;
-		case 'H':
-			val = tm->tm_hour;
-			goto number;
-		case 'I':
-			val = tm->tm_hour;
-			if (val == 0)
-				val = 12;
-			if (val > 12)
-				val -= 12;
-			goto number;
-		case 'j':
-			width = 3;
-			val = tm->tm_yday+1;
-			goto number;
-		case 'm':
-			val = tm->tm_mon+1;
-			goto number;
-		case 'M':
-			val = tm->tm_min;
-			goto number;
-		case 'S':
-			val = tm->tm_sec;
-			goto number;
-		case 'u':
-			width = 1;
-			val = tm->tm_wday+1;
-			goto number;
-		case 'U':
-			val = tm->tm_yday / 7;
-			if (_newyear(tm->tm_year) == SAT)
-				val++;
-			goto number;
-		case 'W':
-			val = tm->tm_yday / 7;
-			if (_newyear(tm->tm_year) == MON)
-				val++;
-			goto number;
-		case 'w':
-			width = 1;
-			val = tm->tm_wday;
-			goto number;
-		case 'y':
-			val = tm->tm_year%100;
-			goto number;
-		case 'Y':
-			width = 4;
-			val = 1900 + tm->tm_year;
-		number:
-			inc = dval(s, n, width, fill, val);
-			break;
-		case 'z':
-			inc = timezone(s, n, tm);
-			break;
-		case 'E':
-		case 'O':
-			if (*fmt != '\0')
-				fmt += 2;;
-		case '\0':
-			inc = 0;
-			--fmt;
-			break;
-		}
-	}
-	*s = '\0';
-
-	return siz - n;
-}
--- /dev/null
+++ b/lib/c/string/Makefile
@@ -1,0 +1,31 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = memchr.o\
+       memcmp.o\
+       memcpy.o\
+       memmove.o\
+       memset.o\
+       strcat.o\
+       strchr.o\
+       strcmp.o\
+       strcoll.o\
+       strcpy.o\
+       strcspn.o\
+       strerror.o\
+       strlen.o\
+       strncat.o\
+       strncmp.o\
+       strncpy.o\
+       strnlen.o\
+       strpbrk.o\
+       strrchr.o\
+       strspn.o\
+       strstr.o\
+       strtok.o\
+       strxfrm.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/string/memchr.c
@@ -1,0 +1,12 @@
+#include <string.h>
+#undef memchr
+
+void *
+memchr(const void *s, int c, size_t n)
+{
+	const unsigned char *bp = s;
+
+	while (n > 0 && *bp++ != c)
+		--n;
+	return (n == 0) ? NULL : bp-1;
+}
--- /dev/null
+++ b/lib/c/string/memcmp.c
@@ -1,0 +1,14 @@
+#include <string.h>
+#undef memcmp
+
+int
+memcmp(const void *s1, const void *s2, size_t n)
+{
+	const char *s = s1;
+	const char *t = s2;
+
+	for ( ; n > 0 && *s == *t; --n)
+		++s, ++t;
+
+	return (n > 0) ? *(unsigned char *) s - *(unsigned char *) t : 0;
+}
--- /dev/null
+++ b/lib/c/string/memcpy.c
@@ -1,0 +1,13 @@
+#include <string.h>
+#undef memcpy
+
+void *
+memcpy(void * restrict dst, const void * restrict src, size_t n)
+{
+	char *s1 = dst;
+	const char *s2 = src;
+
+	while (n-- > 0)
+		*s1++ = *s2++;
+	return dst;
+}
--- /dev/null
+++ b/lib/c/string/memmove.c
@@ -1,0 +1,18 @@
+#include <string.h>
+#undef memmove
+
+void *
+memmove(void *dst, const void *src, size_t n)
+{
+	char *d = dst, *s = (char *) src;
+
+	if (d < s) {
+		while (n-- > 0)
+			*d++ = *s++;
+	} else {
+		s += n-1, d += n-1;
+		while (n-- > 0)
+			*d-- = *s--;
+	}
+	return dst;
+}
--- /dev/null
+++ b/lib/c/string/memset.c
@@ -1,0 +1,12 @@
+#include <string.h>
+#undef memset
+
+void *
+memset(void *s, int c, size_t n)
+{
+	char *m = s;
+
+	while (n-- > 0)
+		*m++ = c;
+	return s;
+}
--- /dev/null
+++ b/lib/c/string/strcat.c
@@ -1,0 +1,14 @@
+#include <string.h>
+#undef strcat
+
+char *
+strcat(char * restrict dst, const char * restrict src)
+{
+	char *ret = dst;
+
+	while (*dst)
+		++dst;
+	while (*dst++ = *src++)
+		;
+	return ret;
+}
--- /dev/null
+++ b/lib/c/string/strchr.c
@@ -1,0 +1,10 @@
+#include <string.h>
+#undef strchr
+
+char *
+strchr(const char *s, int c)
+{
+	while (*s && *s != c)
+		++s;
+	return (*s == c) ? (char *)s : NULL;
+}
--- /dev/null
+++ b/lib/c/string/strcmp.c
@@ -1,0 +1,10 @@
+#include <string.h>
+#undef strcmp
+
+int
+strcmp(const char *s1, const char *s2)
+{
+	while (*s1 && *s2 && *s1 == *s2)
+		++s1, ++s2;
+	return *(unsigned char *)s1 - *(unsigned char *)s2;
+}
--- /dev/null
+++ b/lib/c/string/strcoll.c
@@ -1,0 +1,10 @@
+#include <string.h>
+#undef strcoll
+
+int
+strcoll(const char *s1, const char *s2)
+{
+	while (*s1 && *s2 && *s1 == *s2)
+		++s1, ++s2;
+	return *(unsigned char *) s1 - *(unsigned char *) s2;
+}
--- /dev/null
+++ b/lib/c/string/strcpy.c
@@ -1,0 +1,12 @@
+#include <string.h>
+#undef strcpy
+
+char *
+strcpy(char * restrict dst, const char * restrict src)
+{
+	char *ret = dst;
+
+	while (*dst++ = *src++)
+		;
+	return ret;
+}
--- /dev/null
+++ b/lib/c/string/strcspn.c
@@ -1,0 +1,21 @@
+#include <string.h>
+#undef strcspn
+
+size_t
+strcspn(const char *s1, const char *s2)
+{
+	const unsigned char *s = s1;
+	const unsigned char *accept = s2;
+	unsigned ch;
+	size_t n;
+	char buf[__NUMCHARS];
+
+	memset(buf, 0, sizeof(buf));
+	while (ch = *accept++)
+		buf[ch] = 1;
+
+	for (n = 0; (ch = *s++) && !buf[ch]; ++n)
+		;
+
+	return n;
+}
--- /dev/null
+++ b/lib/c/string/strerror.c
@@ -1,0 +1,12 @@
+#include <errno.h>
+#include <string.h>
+#undef strerror
+
+char *
+strerror(int errnum)
+{
+	if (errnum < _sys_nerr)
+		return _sys_errlist[errnum];
+	else
+		return "Unknown error";
+}
--- /dev/null
+++ b/lib/c/string/strlen.c
@@ -1,0 +1,12 @@
+#include <string.h>
+#undef strlen
+
+size_t
+strlen(const char *s)
+{
+	const char *t;
+
+	for (t = s; *t; ++t)
+		;
+	return t - s;
+}
--- /dev/null
+++ b/lib/c/string/strncat.c
@@ -1,0 +1,15 @@
+#include <string.h>
+#undef strncat
+
+char *
+strncat(char * restrict dst, const char * restrict src, size_t n)
+{
+	char *ret = dst;
+
+	while (*dst)
+		++dst;
+	while (n-- > 0 && *src)
+		*dst++ = *src++;
+	*dst = '\0';
+	return ret;
+}
--- /dev/null
+++ b/lib/c/string/strncmp.c
@@ -1,0 +1,14 @@
+#include <string.h>
+#undef strncmp
+
+int
+strncmp(const char *s1, const char *s2, size_t n)
+{
+	int c;
+
+	for ( ; n > 0 && (c = *s1) && c == *s2; --n)
+		++s1, ++s2;
+	if (n == 0)
+		return 0;
+	return *(unsigned char *) s1 - *(unsigned char *) s2;
+}
--- /dev/null
+++ b/lib/c/string/strncpy.c
@@ -1,0 +1,14 @@
+#include <string.h>
+#undef strncpy
+
+char *
+strncpy(char * restrict dst, const char * restrict src, size_t n)
+{
+	char *ret = dst;
+
+	for (; n > 0 && *src; --n)
+		*dst++ = *src++;
+	while (n-- > 0)
+		*dst++ = '\0';
+	return ret;
+}
--- /dev/null
+++ b/lib/c/string/strnlen.c
@@ -1,0 +1,13 @@
+#include <string.h>
+
+#undef strnlen
+
+size_t
+strnlen(const char *s, size_t maxlen)
+{
+	size_t n;
+
+	for (n = 0; n < maxlen && *s++; ++n)
+		;
+	return n;
+}
--- /dev/null
+++ b/lib/c/string/strpbrk.c
@@ -1,0 +1,20 @@
+#include <string.h>
+#undef strpbrk
+
+char *
+strpbrk(const char *s1, const char *s2)
+{
+	const unsigned char *s = s1;
+	const unsigned char *accept = s2;
+	unsigned ch;
+	char buf[__NUMCHARS];
+
+	memset(buf, 0, sizeof(buf));
+	while (ch = *accept++)
+		buf[ch] = 1;
+
+	while ((ch = *s) && !buf[ch])
+		s++;
+
+	return (ch == '\0') ? NULL : (char *) s;
+}
--- /dev/null
+++ b/lib/c/string/strrchr.c
@@ -1,0 +1,14 @@
+#include <string.h>
+#undef strrchr
+
+char *
+strrchr(const char *s, int c)
+{
+	const char *t = s;
+
+	while (*t)
+		++t;
+	while (t > s && *t != c)
+		--t;
+	return (*t == c) ? (char *)t : NULL;
+}
--- /dev/null
+++ b/lib/c/string/strspn.c
@@ -1,0 +1,21 @@
+#include <string.h>
+#undef strspn
+
+size_t
+strspn(const char *s1, const char *s2)
+{
+	const unsigned char *s = s1;
+	const unsigned char *accept = s2;
+	unsigned ch;
+	size_t n;
+	char buf[__NUMCHARS];
+
+	memset(buf, 0, sizeof(buf));
+	while (ch = *accept++)
+		buf[ch] = 1;
+
+	for (n = 0; (ch = *s++) && buf[ch]; ++n)
+		;
+
+	return n;
+}
--- /dev/null
+++ b/lib/c/string/strstr.c
@@ -1,0 +1,18 @@
+#include <stddef.h>
+#include <string.h>
+#undef strstr
+
+char *
+strstr(const char *s1, const char *s2)
+{
+	const char *p;
+	int c = *s2;
+
+	if (c == '\0')
+		return NULL;
+	for (p = s1; p = strchr(p, c); ++p) {
+		if (!strcmp(p, s2))
+			return (char *) p;
+	}
+	return NULL;
+}
--- /dev/null
+++ b/lib/c/string/strtok.c
@@ -1,0 +1,25 @@
+#include <string.h>
+#undef strtok
+
+char *
+strtok(char * restrict s, const char * restrict delim)
+{
+	static char *line;
+
+	if (s)
+		line = s;
+	if (!s && !line)
+		return NULL;
+
+	s = line + strspn(line, delim);
+	if (*s == '\0')
+		return line = NULL;
+
+	line = s + strcspn(s, delim);
+	if (*line != '\0')
+		*line++ = '\0';
+	else
+		line = NULL;
+
+	return s;
+}
--- /dev/null
+++ b/lib/c/string/strxfrm.c
@@ -1,0 +1,12 @@
+#include <string.h>
+#undef strxfrm
+
+size_t
+strxfrm(char * restrict dst, const char * restrict src, size_t n)
+{
+	size_t len = strlen(src);
+
+	if (len < n)
+		strcpy(dst, src);
+	return len;
+}
--- a/lib/c/strlen.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <string.h>
-#undef strlen
-
-size_t
-strlen(const char *s)
-{
-	const char *t;
-
-	for (t = s; *t; ++t)
-		;
-	return t - s;
-}
--- a/lib/c/strncat.c
+++ /dev/null
@@ -1,15 +1,0 @@
-#include <string.h>
-#undef strncat
-
-char *
-strncat(char * restrict dst, const char * restrict src, size_t n)
-{
-	char *ret = dst;
-
-	while (*dst)
-		++dst;
-	while (n-- > 0 && *src)
-		*dst++ = *src++;
-	*dst = '\0';
-	return ret;
-}
--- a/lib/c/strncmp.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <string.h>
-#undef strncmp
-
-int
-strncmp(const char *s1, const char *s2, size_t n)
-{
-	int c;
-
-	for ( ; n > 0 && (c = *s1) && c == *s2; --n)
-		++s1, ++s2;
-	if (n == 0)
-		return 0;
-	return *(unsigned char *) s1 - *(unsigned char *) s2;
-}
--- a/lib/c/strncpy.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <string.h>
-#undef strncpy
-
-char *
-strncpy(char * restrict dst, const char * restrict src, size_t n)
-{
-	char *ret = dst;
-
-	for (; n > 0 && *src; --n)
-		*dst++ = *src++;
-	while (n-- > 0)
-		*dst++ = '\0';
-	return ret;
-}
--- a/lib/c/strnlen.c
+++ /dev/null
@@ -1,13 +1,0 @@
-#include <string.h>
-
-#undef strnlen
-
-size_t
-strnlen(const char *s, size_t maxlen)
-{
-	size_t n;
-
-	for (n = 0; n < maxlen && *s++; ++n)
-		;
-	return n;
-}
--- a/lib/c/strpbrk.c
+++ /dev/null
@@ -1,20 +1,0 @@
-#include <string.h>
-#undef strpbrk
-
-char *
-strpbrk(const char *s1, const char *s2)
-{
-	const unsigned char *s = s1;
-	const unsigned char *accept = s2;
-	unsigned ch;
-	char buf[__NUMCHARS];
-
-	memset(buf, 0, sizeof(buf));
-	while (ch = *accept++)
-		buf[ch] = 1;
-
-	while ((ch = *s) && !buf[ch])
-		s++;
-
-	return (ch == '\0') ? NULL : (char *) s;
-}
--- a/lib/c/strrchr.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <string.h>
-#undef strrchr
-
-char *
-strrchr(const char *s, int c)
-{
-	const char *t = s;
-
-	while (*t)
-		++t;
-	while (t > s && *t != c)
-		--t;
-	return (*t == c) ? (char *)t : NULL;
-}
--- a/lib/c/strspn.c
+++ /dev/null
@@ -1,21 +1,0 @@
-#include <string.h>
-#undef strspn
-
-size_t
-strspn(const char *s1, const char *s2)
-{
-	const unsigned char *s = s1;
-	const unsigned char *accept = s2;
-	unsigned ch;
-	size_t n;
-	char buf[__NUMCHARS];
-
-	memset(buf, 0, sizeof(buf));
-	while (ch = *accept++)
-		buf[ch] = 1;
-
-	for (n = 0; (ch = *s++) && buf[ch]; ++n)
-		;
-
-	return n;
-}
--- a/lib/c/strstr.c
+++ /dev/null
@@ -1,18 +1,0 @@
-#include <stddef.h>
-#include <string.h>
-#undef strstr
-
-char *
-strstr(const char *s1, const char *s2)
-{
-	const char *p;
-	int c = *s2;
-
-	if (c == '\0')
-		return NULL;
-	for (p = s1; p = strchr(p, c); ++p) {
-		if (!strcmp(p, s2))
-			return (char *) p;
-	}
-	return NULL;
-}
--- a/lib/c/strtok.c
+++ /dev/null
@@ -1,25 +1,0 @@
-#include <string.h>
-#undef strtok
-
-char *
-strtok(char * restrict s, const char * restrict delim)
-{
-	static char *line;
-
-	if (s)
-		line = s;
-	if (!s && !line)
-		return NULL;
-
-	s = line + strspn(line, delim);
-	if (*s == '\0')
-		return line = NULL;
-
-	line = s + strcspn(s, delim);
-	if (*line != '\0')
-		*line++ = '\0';
-	else
-		line = NULL;
-
-	return s;
-}
--- a/lib/c/strxfrm.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <string.h>
-#undef strxfrm
-
-size_t
-strxfrm(char * restrict dst, const char * restrict src, size_t n)
-{
-	size_t len = strlen(src);
-
-	if (len < n)
-		strcpy(dst, src);
-	return len;
-}
--- a/lib/c/target/.gitignore
+++ /dev/null
@@ -1,1 +1,0 @@
-_sys_errlist.c
--- a/lib/c/target/Makefile
+++ /dev/null
@@ -1,15 +1,0 @@
-
-PROJECTDIR = ../../..
-
-include $(PROJECTDIR)/rules.mk
-
-DIRS = amd64-sysv-linux \
-       amd64-sysv-openbsd \
-       amd64-sysv-netbsd \
-
-all clean distclean:
-	$(FORALL)
-
-dep:
-	./script/objlst.sh
-	$(FORALL)
--- a/lib/c/target/amd64-sysv-linux/.gitignore
+++ /dev/null
@@ -1,10 +1,0 @@
-_Exit.s
-_brk.s
-_close.s
-_getpid.s
-_kill.s
-_lseek.s
-_open.s
-_read.s
-_sigaction.s
-_write.s
--- a/lib/c/target/amd64-sysv-linux/Makefile
+++ /dev/null
@@ -1,17 +1,0 @@
-.POSIX:
-
-PROJECTDIR = ../../../..
-include $(PROJECTDIR)/rules.mk
-
-SYS        = linux
-ARCH       = amd64
-ABI        = sysv
-SYSERRTBL  = ../posix/linux.e
-MORECFLAGS = -std=c99 -g -static -nostdinc -ffreestanding -fno-stack-protector
-SYSOBJ     = raise.o signal.o
-
-include syscall.mk
-include ../amd64-sysv/objlst.mk
-include ../script/objlst.mk
-include ../posix/objlst.mk
-include ../script/common.mk
--- a/lib/c/target/amd64-sysv-linux/sys.h
+++ /dev/null
@@ -1,19 +1,0 @@
-#define O_RDONLY  0x00000000
-#define O_WRONLY  0x00000001
-#define O_RDWR    0x00000002
-
-#define O_TRUNC   0x00000400
-#define O_APPEND  0x00000008
-#define O_CREAT   0x00000200
-
-typedef int pid_t;
-
-struct sigaction {
-	void (*sa_handler)(int);
-	int sa_mask;
-	int sa_flags;
-};
-
-extern pid_t _getpid(void);
-extern int _kill(pid_t pid, int signum);
-extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- a/lib/c/target/amd64-sysv-linux/syscall.lst
+++ /dev/null
@@ -1,11 +1,0 @@
-#number	name
-0	_read
-1	_write
-2	_open
-3	_close
-3	_lseek
-12	_brk
-13	_sigaction
-38	_getpid
-60	_Exit
-32	_kill
--- a/lib/c/target/amd64-sysv-linux/syscall.mk
+++ /dev/null
@@ -1,1 +1,0 @@
-SYSCALL = _read.o _write.o _open.o _close.o _lseek.o _brk.o _sigaction.o _getpid.o _Exit.o _kill.o 
--- a/lib/c/target/amd64-sysv-netbsd/.gitignore
+++ /dev/null
@@ -1,11 +1,0 @@
-_Exit.s
-_brk.s
-_close.s
-_getpid.s
-_kill.s
-_lseek.s
-_open.s
-_read.s
-_write.s
-_sigaction.s
-_gettimeofday.s
--- a/lib/c/target/amd64-sysv-netbsd/Makefile
+++ /dev/null
@@ -1,19 +1,0 @@
-.POSIX:
-
-PROJECTDIR = ../../../..
-include $(PROJECTDIR)/rules.mk
-
-SYS        = netbsd
-ARCH       = amd64
-ABI        = sysv
-SYSERRTBL  = ../posix/netbsd.e
-MORECFLAGS = -std=c99 -g -static -nostdinc
-SYSOBJ     = _tzone.o getenv.o raise.o signal.o \
-             _sigaction.o _sigaction2.o _setcontext.o \
-            time.o
-
-include syscall.mk
-include ../amd64-sysv/objlst.mk
-include ../script/objlst.mk
-include ../posix/objlst.mk
-include ../script/common.mk
--- a/lib/c/target/amd64-sysv-netbsd/_setcontext.s
+++ /dev/null
@@ -1,14 +1,0 @@
-
-	.text
-	.globl	_Exit
-	.globl	_setcontext
-
-_setcontext:
-	movq	%r15,%rdi
-	movq	$0x134,%rax
-	syscall
-
-	# Something was wrong, finish the program. We can't call
-	# abort here because it could generate a loop
-	movq	$-1,%rdi
-	jmp	_Exit
--- a/lib/c/target/amd64-sysv-netbsd/_sigaction.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <stddef.h>
-#include <sys.h>
-
-extern int _sigaction2(int sig,
-                       struct sigaction *new, struct sigaction *old,
-                       int siginfo[], int num);
-
-int
-_sigaction(int sig, struct sigaction *new, struct sigaction *old)
-{
-	extern int _setcontext[];
-
-	return _sigaction2(sig, new, old, _setcontext, 2);
-}
--- a/lib/c/target/amd64-sysv-netbsd/_sigaction2.s
+++ /dev/null
@@ -1,12 +1,0 @@
-
-# This syscall cannot be autogenerated because it receives more than
-# 4 arguments
-
-	.text
-	.globl	_sigaction2
-
-_sigaction2:
-	mov	$0x154,%eax
-	mov	%rcx,%r10
-	syscall
-	retq
--- a/lib/c/target/amd64-sysv-netbsd/sys.h
+++ /dev/null
@@ -1,19 +1,0 @@
-#define O_RDONLY  0x00000000
-#define O_WRONLY  0x00000001
-#define O_RDWR    0x00000002
-
-#define O_TRUNC   0x00000400
-#define O_APPEND  0x00000008
-#define O_CREAT   0x00000200
-
-typedef int pid_t;
-
-struct sigaction {
-	void (*sa_handler)(int);
-	char sa_mask[8];
-	int sa_flags;
-};
-
-extern pid_t _getpid(void);
-extern int _kill(pid_t pid, int signum);
-extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- a/lib/c/target/amd64-sysv-netbsd/syscall.lst
+++ /dev/null
@@ -1,11 +1,0 @@
-#number	name
-1	_Exit
-3	_read
-4	_write
-5	_open
-6	_close
-17	_brk
-20	_getpid
-37	_kill
-199	_lseek
-418	_gettimeofday
--- a/lib/c/target/amd64-sysv-netbsd/syscall.mk
+++ /dev/null
@@ -1,1 +1,0 @@
-SYSCALL = _Exit.o _read.o _write.o _open.o _close.o _brk.o _getpid.o _kill.o _lseek.o _gettimeofday.o 
--- a/lib/c/target/amd64-sysv-openbsd/.gitignore
+++ /dev/null
@@ -1,10 +1,0 @@
-_Exit.s
-_brk.s
-_close.s
-_getpid.s
-_kill.s
-_lseek.s
-_open.s
-_read.s
-_sigaction.s
-_write.s
--- a/lib/c/target/amd64-sysv-openbsd/Makefile
+++ /dev/null
@@ -1,17 +1,0 @@
-.POSIX:
-
-PROJECTDIR = ../../../..
-include $(PROJECTDIR)/rules.mk
-
-SYS        = openbsd
-ARCH       = amd64
-ABI        = sysv
-SYSERRTBL  = ../posix/netbsd.e
-MORECFLAGS = -std=c99 -g -static -nostdinc -fno-stack-protector --freestanding
-SYSOBJ     = raise.o signal.o _sigaction.o
-
-include syscall.mk
-include ../amd64-sysv/objlst.mk
-include ../script/objlst.mk
-include ../posix/objlst.mk
-include ../script/common.mk
--- a/lib/c/target/amd64-sysv-openbsd/sys.h
+++ /dev/null
@@ -1,19 +1,0 @@
-#define O_RDONLY  0x00000000
-#define O_WRONLY  0x00000001
-#define O_RDWR    0x00000002
-
-#define O_TRUNC   0x00000400
-#define O_APPEND  0x00000008
-#define O_CREAT   0x00000200
-
-typedef int pid_t;
-
-struct sigaction {
-	void (*sa_handler)(int);
-	int sa_mask;
-	int sa_flags;
-};
-
-extern pid_t _getpid(void);
-extern int _kill(pid_t pid, int signum);
-extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- a/lib/c/target/amd64-sysv-openbsd/syscall.lst
+++ /dev/null
@@ -1,11 +1,0 @@
-#number	name
-1	_Exit
-3	_read
-4	_write
-5	_open
-6	_close
-17	_brk
-20	_getpid
-46	_sigaction
-122	_kill
-198	_lseek
--- a/lib/c/target/amd64-sysv-openbsd/syscall.mk
+++ /dev/null
@@ -1,1 +1,0 @@
-SYSCALL = _Exit.o _read.o _write.o _open.o _close.o _brk.o _getpid.o _sigaction.o _kill.o _lseek.o 
--- a/lib/c/target/amd64-sysv/longjmp.s
+++ /dev/null
@@ -1,20 +1,0 @@
-# Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license
-	.file	"longjmp"
-	.global	longjmp
-
-longjmp:
-	mov	%rsi,%rax      # val will be longjmp return
-	test	%rax,%rax
-	jnz	1f
-	inc	%rax           # if val==0, val=1 per longjmp semantics
-1:
-	mov	(%rdi),%rbx    # rdi is the jmp_buf, restore regs from it
-	mov	8(%rdi),%rbp
-	mov	16(%rdi),%r12
-	mov	24(%rdi),%r13
-	mov	32(%rdi),%r14
-	mov	40(%rdi),%r15
-	mov	48(%rdi),%rdx  # this ends up being the stack pointer
-	mov	%rdx,%rsp
-	mov	56(%rdi),%rdx  # this is the instruction pointer
-	jmp	*%rdx          # goto saved address without altering rsp
--- a/lib/c/target/amd64-sysv/objlst.mk
+++ /dev/null
@@ -1,7 +1,0 @@
-ARCHOBJ = setjmp.o longjmp.o
-
-setjmp.o: ../amd64-sysv/setjmp.s
-	$(AS) $(ASFLAGS) -o $@ ../amd64-sysv/setjmp.s
-
-longjmp.o: ../amd64-sysv/longjmp.s
-	$(AS) $(ASFLAGS) -o $@ ../amd64-sysv/longjmp.s
--- a/lib/c/target/amd64-sysv/setjmp.s
+++ /dev/null
@@ -1,17 +1,0 @@
-/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
-
-	.file	"setjmp.s"
-	.global	setjmp
-setjmp:
-	mov	%rbx,(%rdi)     # rdi is jmp_buf, move registers onto it
-	mov	%rbp,8(%rdi)
-	mov	%r12,16(%rdi)
-	mov	%r13,24(%rdi)
-	mov	%r14,32(%rdi)
-	mov	%r15,40(%rdi)
-	lea	8(%rsp),%rdx    # this is our rsp WITHOUT current ret addr
-	mov	%rdx,48(%rdi)
-	mov	(%rsp),%rdx     # save return addr ptr for new rip
-	mov	%rdx,56(%rdi)
-	xor	%rax,%rax       # always return 0
-	ret
--- a/lib/c/target/i386-sysv-linux/Makefile
+++ /dev/null
@@ -1,9 +1,0 @@
-.POSIX:
-
-PROJECTDIR = ../../../..
-
-include $(PROJECTDIR)/rules.mk
-include ../objlst.mk
-include ../common.mk
-
-SCC_CFLAGS = -nostdinc -I../../include -I../../include/bits/i386-sysv/
--- a/lib/c/target/posix/_tzone.c
+++ /dev/null
@@ -1,27 +1,0 @@
-#include <stdlib.h>
-#include <time.h>
-#include "../../libc.h"
-
-struct tzone *
-_tzone(struct tm *tm)
-{
-	static struct tzone tz;
-	static int first = 1;
-
-	if (!first)
-		return &tz;
-
-	tz.name = getenv("TZ");
-	if (!tz.name || *tz.name == '\0') {
-		tz.name = NULL;
-		tz.gmtoff = 0;
-		tz.isdst = 0;
-	} else {
-		/* TODO: parse TZ string */
-		tz.gmtoff = 0;
-		tz.isdst = 0;
-	}
-	first = 0;
-
-	return &tz;
-}
--- a/lib/c/target/posix/getenv.c
+++ /dev/null
@@ -1,22 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-#undef getenv
-
-extern char **_environ;
-
-char *
-getenv(const char *name)
-{
-	char **p;
-	size_t len = strlen(name);
-
-	for (p = _environ; *p; ++p) {
-		if (!memcmp(name, *p, len) && (*p)[len] == '=')
-			break;
-	}
-
-	if (!*p) 
-		return NULL;
-
-	return &(*p)[len];
-}
--- a/lib/c/target/posix/geterrno.sh
+++ /dev/null
@@ -1,8 +1,0 @@
-#!/bin/sh
-
-awk '/define[ 	]*E/ && $3 ~ /[0-9]+/ && $3 > 0 {
-	sub(/\#define[ 	]*/, "")
-	sub(/\/\*/, "")
-	sub(/\*\//, "")
-	print
-}' /usr/include/sys/errno.h
--- a/lib/c/target/posix/linux.e
+++ /dev/null
@@ -1,131 +1,0 @@
-EPERM		 1	 Operation not permitted 
-ENOENT		 2	 No such file or directory 
-ESRCH		 3	 No such process 
-EINTR		 4	 Interrupted system call 
-EIO		 5	 I/O error 
-ENXIO		 6	 No such device or address 
-E2BIG		 7	 Argument list too long 
-ENOEXEC		 8	 Exec format error 
-EBADF		 9	 Bad file number 
-ECHILD		10	 No child processes 
-EAGAIN		11	 Try again 
-ENOMEM		12	 Out of memory 
-EACCES		13	 Permission denied 
-EFAULT		14	 Bad address 
-ENOTBLK		15	 Block device required 
-EBUSY		16	 Device or resource busy 
-EEXIST		17	 File exists 
-EXDEV		18	 Cross-device link 
-ENODEV		19	 No such device 
-ENOTDIR		20	 Not a directory 
-EISDIR		21	 Is a directory 
-EINVAL		22	 Invalid argument 
-ENFILE		23	 File table overflow 
-EMFILE		24	 Too many open files 
-ENOTTY		25	 Not a typewriter 
-ETXTBSY		26	 Text file busy 
-EFBIG		27	 File too large 
-ENOSPC		28	 No space left on device 
-ESPIPE		29	 Illegal seek 
-EROFS		30	 Read-only file system 
-EMLINK		31	 Too many links 
-EPIPE		32	 Broken pipe 
-EDOM		33	 Math argument out of domain of func 
-ERANGE		34	 Math result not representable 
-EDEADLK		35	 Resource deadlock would occur 
-ENAMETOOLONG	36	 File name too long 
-ENOLCK		37	 No record locks available 
-ENOSYS		38	 Invalid system call number 
-ENOTEMPTY	39	 Directory not empty 
-ELOOP		40	 Too many symbolic links encountered 
-ENOMSG		42	 No message of desired type 
-EIDRM		43	 Identifier removed 
-ECHRNG		44	 Channel number out of range 
-EL2NSYNC	45	 Level 2 not synchronized 
-EL3HLT		46	 Level 3 halted 
-EL3RST		47	 Level 3 reset 
-ELNRNG		48	 Link number out of range 
-EUNATCH		49	 Protocol driver not attached 
-ENOCSI		50	 No CSI structure available 
-EL2HLT		51	 Level 2 halted 
-EBADE		52	 Invalid exchange 
-EBADR		53	 Invalid request descriptor 
-EXFULL		54	 Exchange full 
-ENOANO		55	 No anode 
-EBADRQC		56	 Invalid request code 
-EBADSLT		57	 Invalid slot 
-EBFONT		59	 Bad font file format 
-ENOSTR		60	 Device not a stream 
-ENODATA		61	 No data available 
-ETIME		62	 Timer expired 
-ENOSR		63	 Out of streams resources 
-ENONET		64	 Machine is not on the network 
-ENOPKG		65	 Package not installed 
-EREMOTE		66	 Object is remote 
-ENOLINK		67	 Link has been severed 
-EADV		68	 Advertise error 
-ESRMNT		69	 Srmount error 
-ECOMM		70	 Communication error on send 
-EPROTO		71	 Protocol error 
-EMULTIHOP	72	 Multihop attempted 
-EDOTDOT		73	 RFS specific error 
-EBADMSG		74	 Not a data message 
-EOVERFLOW	75	 Value too large for defined data type 
-ENOTUNIQ	76	 Name not unique on network 
-EBADFD		77	 File descriptor in bad state 
-EREMCHG		78	 Remote address changed 
-ELIBACC		79	 Can not access a needed shared library 
-ELIBBAD		80	 Accessing a corrupted shared library 
-ELIBSCN		81	 .lib section in a.out corrupted 
-ELIBMAX		82	 Attempting to link in too many shared libraries 
-ELIBEXEC	83	 Cannot exec a shared library directly 
-EILSEQ		84	 Illegal byte sequence 
-ERESTART	85	 Interrupted system call should be restarted 
-ESTRPIPE	86	 Streams pipe error 
-EUSERS		87	 Too many users 
-ENOTSOCK	88	 Socket operation on non-socket 
-EDESTADDRREQ	89	 Destination address required 
-EMSGSIZE	90	 Message too long 
-EPROTOTYPE	91	 Protocol wrong type for socket 
-ENOPROTOOPT	92	 Protocol not available 
-EPROTONOSUPPORT	93	 Protocol not supported 
-ESOCKTNOSUPPORT	94	 Socket type not supported 
-EOPNOTSUPP	95	 Operation not supported on transport endpoint 
-EPFNOSUPPORT	96	 Protocol family not supported 
-EAFNOSUPPORT	97	 Address family not supported by protocol 
-EADDRINUSE	98	 Address already in use 
-EADDRNOTAVAIL	99	 Cannot assign requested address 
-ENETDOWN	100	 Network is down 
-ENETUNREACH	101	 Network is unreachable 
-ENETRESET	102	 Network dropped connection because of reset 
-ECONNABORTED	103	 Software caused connection abort 
-ECONNRESET	104	 Connection reset by peer 
-ENOBUFS		105	 No buffer space available 
-EISCONN		106	 Transport endpoint is already connected 
-ENOTCONN	107	 Transport endpoint is not connected 
-ESHUTDOWN	108	 Cannot send after transport endpoint shutdown 
-ETOOMANYREFS	109	 Too many references: cannot splice 
-ETIMEDOUT	110	 Connection timed out 
-ECONNREFUSED	111	 Connection refused 
-EHOSTDOWN	112	 Host is down 
-EHOSTUNREACH	113	 No route to host 
-EALREADY	114	 Operation already in progress 
-EINPROGRESS	115	 Operation now in progress 
-ESTALE		116	 Stale file handle 
-EUCLEAN		117	 Structure needs cleaning 
-ENOTNAM		118	 Not a XENIX named type file 
-ENAVAIL		119	 No XENIX semaphores available 
-EISNAM		120	 Is a named type file 
-EREMOTEIO	121	 Remote I/O error 
-EDQUOT		122	 Quota exceeded 
-ENOMEDIUM	123	 No medium found 
-EMEDIUMTYPE	124	 Wrong medium type 
-ECANCELED	125	 Operation Canceled 
-ENOKEY		126	 Required key not available 
-EKEYEXPIRED	127	 Key has expired 
-EKEYREVOKED	128	 Key has been revoked 
-EKEYREJECTED	129	 Key was rejected by service 
-EOWNERDEAD	130	 Owner died 
-ENOTRECOVERABLE	131	 State not recoverable 
-ERFKILL		132	 Operation not possible due to RF-kill 
-EHWPOISON	133	 Memory page has hardware error 
--- a/lib/c/target/posix/netbsd.e
+++ /dev/null
@@ -1,98 +1,0 @@
-EPERM		1		 Operation not permitted 
-ENOENT		2		 No such file or directory 
-ESRCH		3		 No such process 
-EINTR		4		 Interrupted system call 
-EIO		5		 Input/output error 
-ENXIO		6		 Device not configured 
-E2BIG		7		 Argument list too long 
-ENOEXEC		8		 Exec format error 
-EBADF		9		 Bad file descriptor 
-ECHILD		10		 No child processes 
-EDEADLK		11		 Resource deadlock avoided 
-ENOMEM		12		 Cannot allocate memory 
-EACCES		13		 Permission denied 
-EFAULT		14		 Bad address 
-ENOTBLK		15		 Block device required 
-EBUSY		16		 Device busy 
-EEXIST		17		 File exists 
-EXDEV		18		 Cross-device link 
-ENODEV		19		 Operation not supported by device 
-ENOTDIR		20		 Not a directory 
-EISDIR		21		 Is a directory 
-EINVAL		22		 Invalid argument 
-ENFILE		23		 Too many open files in system 
-EMFILE		24		 Too many open files 
-ENOTTY		25		 Inappropriate ioctl for device 
-ETXTBSY		26		 Text file busy 
-EFBIG		27		 File too large 
-ENOSPC		28		 No space left on device 
-ESPIPE		29		 Illegal seek 
-EROFS		30		 Read-only file system 
-EMLINK		31		 Too many links 
-EPIPE		32		 Broken pipe 
-EDOM		33		 Numerical argument out of domain 
-ERANGE		34		 Result too large or too small 
-EAGAIN		35		 Resource temporarily unavailable 
-EWOULDBLOCK	EAGAIN		 Operation would block 
-EINPROGRESS	36		 Operation now in progress 
-EALREADY	37		 Operation already in progress 
-ENOTSOCK	38		 Socket operation on non-socket 
-EDESTADDRREQ	39		 Destination address required 
-EMSGSIZE	40		 Message too long 
-EPROTOTYPE	41		 Protocol wrong type for socket 
-ENOPROTOOPT	42		 Protocol option not available 
-EPROTONOSUPPORT	43		 Protocol not supported 
-ESOCKTNOSUPPORT	44		 Socket type not supported 
-EOPNOTSUPP	45		 Operation not supported 
-EPFNOSUPPORT	46		 Protocol family not supported 
-EAFNOSUPPORT	47		 Address family not supported by protocol family 
-EADDRINUSE	48		 Address already in use 
-EADDRNOTAVAIL	49		 Can't assign requested address 
-ENETDOWN	50		 Network is down 
-ENETUNREACH	51		 Network is unreachable 
-ENETRESET	52		 Network dropped connection on reset 
-ECONNABORTED	53		 Software caused connection abort 
-ECONNRESET	54		 Connection reset by peer 
-ENOBUFS		55		 No buffer space available 
-EISCONN		56		 Socket is already connected 
-ENOTCONN	57		 Socket is not connected 
-ESHUTDOWN	58		 Can't send after socket shutdown 
-ETOOMANYREFS	59		 Too many references: can't splice 
-ETIMEDOUT	60		 Operation timed out 
-ECONNREFUSED	61		 Connection refused 
-ELOOP		62		 Too many levels of symbolic links 
-ENAMETOOLONG	63		 File name too long 
-EHOSTDOWN	64		 Host is down 
-EHOSTUNREACH	65		 No route to host 
-ENOTEMPTY	66		 Directory not empty 
-EPROCLIM	67		 Too many processes 
-EUSERS		68		 Too many users 
-EDQUOT		69		 Disc quota exceeded 
-ESTALE		70		 Stale NFS file handle 
-EREMOTE		71		 Too many levels of remote in path 
-EBADRPC		72		 RPC struct is bad 
-ERPCMISMATCH	73		 RPC version wrong 
-EPROGUNAVAIL	74		 RPC prog. not avail 
-EPROGMISMATCH	75		 Program version wrong 
-EPROCUNAVAIL	76		 Bad procedure for program 
-ENOLCK		77		 No locks available 
-ENOSYS		78		 Function not implemented 
-EFTYPE		79		 Inappropriate file type or format 
-EAUTH		80		 Authentication error 
-ENEEDAUTH	81		 Need authenticator 
-EIDRM		82		 Identifier removed 
-ENOMSG		83		 No message of desired type 
-EOVERFLOW	84		 Value too large to be stored in data type 
-EILSEQ		85		 Illegal byte sequence 
-ENOTSUP		86		 Not supported 
-ECANCELED	87		 Operation canceled 
-EBADMSG		88		 Bad or Corrupt message 
-ENODATA		89		 No message available 
-ENOSR		90		 No STREAM resources 
-ENOSTR		91		 Not a STREAM 
-ETIME		92		 STREAM ioctl timeout 
-ENOATTR		93		 Attribute not found 
-EMULTIHOP	94		 Multihop attempted  
-ENOLINK		95		 Link has been severed 
-EPROTO		96		 Protocol error 
-ELAST		96		 Must equal largest errno 
--- a/lib/c/target/posix/objlst.mk
+++ /dev/null
@@ -1,15 +1,0 @@
-
-raise.o: ../posix/raise.c
-	$(CC) $(SCC_CFLAGS) ../posix/raise.c -c
-
-signal.o: ../posix/signal.c
-	$(CC) $(SCC_CFLAGS) ../posix/signal.c -c
-
-getenv.o: ../posix/getenv.c
-	$(CC) $(SCC_CFLAGS) ../posix/getenv.c -c
-
-time.o: ../posix/time.c
-	$(CC) $(SCC_CFLAGS) ../posix/time.c -c
-
-_tzone.o: ../posix/_tzone.c ../../libc.h
-	$(CC) $(SCC_CFLAGS) ../posix/_tzone.c -c
--- a/lib/c/target/posix/openbsd.e
+++ /dev/null
@@ -1,96 +1,0 @@
-EPERM		1	 Operation not permitted 
-ENOENT		2	 No such file or directory 
-ESRCH		3	 No such process 
-EINTR		4	 Interrupted system call 
-EIO		5	 Input/output error 
-ENXIO		6	 Device not configured 
-E2BIG		7	 Argument list too long 
-ENOEXEC		8	 Exec format error 
-EBADF		9	 Bad file descriptor 
-ECHILD		10	 No child processes 
-EDEADLK		11	 Resource deadlock avoided 
-ENOMEM		12	 Cannot allocate memory 
-EACCES		13	 Permission denied 
-EFAULT		14	 Bad address 
-ENOTBLK		15	 Block device required 
-EBUSY		16	 Device busy 
-EEXIST		17	 File exists 
-EXDEV		18	 Cross-device link 
-ENODEV		19	 Operation not supported by device 
-ENOTDIR		20	 Not a directory 
-EISDIR		21	 Is a directory 
-EINVAL		22	 Invalid argument 
-ENFILE		23	 Too many open files in system 
-EMFILE		24	 Too many open files 
-ENOTTY		25	 Inappropriate ioctl for device 
-ETXTBSY		26	 Text file busy 
-EFBIG		27	 File too large 
-ENOSPC		28	 No space left on device 
-ESPIPE		29	 Illegal seek 
-EROFS		30	 Read-only file system 
-EMLINK		31	 Too many links 
-EPIPE		32	 Broken pipe 
-EDOM		33	 Numerical argument out of domain 
-ERANGE		34	 Result too large 
-EAGAIN		35	 Resource temporarily unavailable 
-EINPROGRESS	36	 Operation now in progress 
-EALREADY	37	 Operation already in progress 
-ENOTSOCK	38	 Socket operation on non-socket 
-EDESTADDRREQ	39	 Destination address required 
-EMSGSIZE	40	 Message too long 
-EPROTOTYPE	41	 Protocol wrong type for socket 
-ENOPROTOOPT	42	 Protocol not available 
-EPROTONOSUPPORT	43	 Protocol not supported 
-ESOCKTNOSUPPORT	44	 Socket type not supported 
-EOPNOTSUPP	45	 Operation not supported 
-EPFNOSUPPORT	46	 Protocol family not supported 
-EAFNOSUPPORT	47	 Address family not supported by protocol family 
-EADDRINUSE	48	 Address already in use 
-EADDRNOTAVAIL	49	 Can't assign requested address 
-ENETDOWN	50	 Network is down 
-ENETUNREACH	51	 Network is unreachable 
-ENETRESET	52	 Network dropped connection on reset 
-ECONNABORTED	53	 Software caused connection abort 
-ECONNRESET	54	 Connection reset by peer 
-ENOBUFS		55	 No buffer space available 
-EISCONN		56	 Socket is already connected 
-ENOTCONN	57	 Socket is not connected 
-ESHUTDOWN	58	 Can't send after socket shutdown 
-ETOOMANYREFS	59	 Too many references: can't splice 
-ETIMEDOUT	60	 Operation timed out 
-ECONNREFUSED	61	 Connection refused 
-ELOOP		62	 Too many levels of symbolic links 
-ENAMETOOLONG	63	 File name too long 
-EHOSTDOWN	64	 Host is down 
-EHOSTUNREACH	65	 No route to host 
-ENOTEMPTY	66	 Directory not empty 
-EPROCLIM	67	 Too many processes 
-EUSERS		68	 Too many users 
-EDQUOT		69	 Disk quota exceeded 
-ESTALE		70	 Stale NFS file handle 
-EREMOTE		71	 Too many levels of remote in path 
-EBADRPC		72	 RPC struct is bad 
-ERPCMISMATCH	73	 RPC version wrong 
-EPROGUNAVAIL	74	 RPC program not available 
-EPROGMISMATCH	75	 Program version wrong 
-EPROCUNAVAIL	76	 Bad procedure for program 
-ENOLCK		77	 No locks available 
-ENOSYS		78	 Function not implemented 
-EFTYPE		79	 Inappropriate file type or format 
-EAUTH		80	 Authentication error 
-ENEEDAUTH	81	 Need authenticator 
-EIPSEC		82	 IPsec processing failure 
-ENOATTR		83	 Attribute not found 
-EILSEQ		84	 Illegal byte sequence 
-ENOMEDIUM	85	 No medium found 
-EMEDIUMTYPE	86	 Wrong medium type 
-EOVERFLOW	87	 Value too large to be stored in data type 
-ECANCELED	88	 Operation canceled 
-EIDRM		89	 Identifier removed 
-ENOMSG		90	 No message of desired type 
-ENOTSUP		91	 Not supported 
-EBADMSG		92	 Bad message 
-ENOTRECOVERABLE	93	 State not recoverable 
-EOWNERDEAD	94	 Previous owner died 
-EPROTO		95	 Protocol error 
-ELAST		95	 Must be equal largest errno 
--- a/lib/c/target/posix/raise.c
+++ /dev/null
@@ -1,11 +1,0 @@
-#include <stddef.h>
-#include <signal.h>
-#include <sys.h>
-
-#undef raise
-
-int
-raise(int signum)
-{
-	return _kill(_getpid(), signum);
-}
--- a/lib/c/target/posix/signal.c
+++ /dev/null
@@ -1,17 +1,0 @@
-#include <stddef.h>
-#include <signal.h>
-#include <sys.h>
-#undef signal
-
-void
-(*signal(int signum, void (*func)(int)))(int)
-{
-	struct sigaction sa = {
-		.sa_handler = func,
-	};
-
-	if (_sigaction(signum, &sa, &sa) < 0)
-		return SIG_ERR;
-
-	return sa.sa_handler;
-}
--- a/lib/c/target/posix/time.c
+++ /dev/null
@@ -1,21 +1,0 @@
-#include <time.h>
-
-struct timeval {
-	time_t tv_sec;
-	int tv_usec; /* TODO use a arch type */
-};
-
-int
-_gettimeofday(struct timeval * restrict tp, void * restrict tzp);
-
-time_t
-time(time_t *t)
-{
-	struct timeval tv;
-
-	if (_gettimeofday(&tv, NULL) == -1)
-		return -1;
-	if (t)
-		*t =tv.tv_sec;
-	return tv.tv_sec;
-}
--- a/lib/c/target/script/amd64-sysv.sh
+++ /dev/null
@@ -1,15 +1,0 @@
-#!/bin/sh
-
-#
-# This job is very easy because app and kernel ABI are identical
-# until the 4th parameter, so we only have to set the syscall
-# number in rax
-
-awk '/^#/	{next}
-		{name=$2 ".s"
-	        printf ".global %s\n" \
-	               "%s:\n" \
-	               "\tmovq\t$%d,%%rax\n" \
-	               "\tsyscall\n" \
-	               "\tret\n", $2, $2, $1 > name
-	        close(name)}' syscall.lst
--- a/lib/c/target/script/common.mk
+++ /dev/null
@@ -1,38 +1,0 @@
-SYSNAME  = $(ARCH)-$(ABI)-$(SYS)
-SYSASM   = $(SYSCALL:.o=.s)
-TARGET   = $(LIBDIR)/$(SYSNAME)/libc.a
-INCLUDE  = -I$(INCDIR) \
-           -I$(INCDIR)/bits/$(ARCH)-$(ABI) \
-           -I$(INCDIR)/bits/$(SYS) \
-           -I.
-SYSERRNO = $(INCDIR)/bits/$(SYS)/sys/errno.h
-OBJ      = $(LIBOBJ) $(SYSOBJ) $(SYSCALL) $(ARCHOBJ)
-
-SCC_CFLAGS = $(MORECFLAGS) $(INCLUDE)
-
-all: $(TARGET)
-
-$(OBJ): $(SYSERRNO)
-
-$(SYSERRNO): $(SYSERRTBL)
-	trap "rm -f $$$$.tmp" 0 2 3 4; \
-	../script/generrno.sh $(SYSERRTBL) > $$$$.tmp && mv $$$$.tmp $@
-
-_sys_errlist.c: $(SYSERRTBL) $(SYSERRNO)
-	trap "rm -f $$$$.tmp" 0 2 3 4; \
-	../script/generrstr.sh $(SYSERRTBL) > $$$$.tmp && mv $$$$.tmp $@
-
-$(TARGET): $(OBJ)
-	$(AR) $(ARFLAGS) $@ $?
-	ranlib $@
-
-clean:
-	rm -f *.o *.a _sys_errlist.c $(SYSERRNO)
-	rm -f $(SYSASM)
-	rm -f $(TARGET)
-
-$(SYSASM): syscall.lst
-	../script/amd64-sysv.sh
-
-dep:
-	../script/syscall.sh
--- a/lib/c/target/script/generrno.sh
+++ /dev/null
@@ -1,12 +1,0 @@
-#!/bin/sh
-
-awk '
-/^E/ && $2 > 0 {
-	errno[$1] = $2
-}
-
-END {
-	for (i in errno)
-		print "#define", i, errno[i] | "sort -n -k3"
-	close("sort -n -k3")
-}' $@
--- a/lib/c/target/script/generrstr.sh
+++ /dev/null
@@ -1,21 +1,0 @@
-#!/bin/sh
-
-awk '
-/^E/ && $2 > 0 {
-	str = ""
-	for (i = 3; i <= NF; i++)
-		str = str " " $i
-	sub(/^ /, "", str)
-	errstr[$1] = str
-	if ($2 > max)
-		max = $2;
-}
-
-END {
-	print "#include <errno.h>\n"
-	print "char *_sys_errstr[] = {"
-	for (i in errstr)
-		printf "\t%-20.20s = \"%s\",\n", "[" i "]", errstr[i]
-	print "};"
-	print "int _sys_nerr =", $2 + 1 ";"
-}' $@
--- a/lib/c/target/script/objlst.mk
+++ /dev/null
@@ -1,345 +1,0 @@
-
-LIBOBJ = bsearch.o qsort.o \
-         abs.o __abs.o labs.o __labs.o llabs.o __llabs.o \
-         perror.o strerror.o \
-         rand.o tmpnam.o \
-         sprintf.o snprintf.o vsprintf.o vsnprintf.o \
-         printf.o fprintf.o vfprintf.o \
-         fgets.o gets.o fgetc.o fputc.o getchar.o putchar.o \
-         fputs.o puts.o fread.o fwrite.o \
-         getc.o putc.o __putc.o __getc.o \
-         ftell.o rewind.o fseek.o ferror.o feof.o clearerr.o \
-         setbuf.o setvbuf.o \
-         fclose.o fopen.o freopen.o _fpopen.o _flsbuf.o stdio.o \
-         realloc.o calloc.o malloc.o \
-         __assert.o strcpy.o strcmp.o strlen.o strchr.o \
-         strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
-         strxfrm.o strstr.o strspn.o strcspn.o strpbrk.o strtok.o \
-         memset.o memcpy.o memmove.o memcmp.o memchr.o \
-         isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
-         isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
-         isxdigit.o toupper.o tolower.o ctype.o setlocale.o \
-         localeconv.o atoi.o atol.o atoll.o atexit.o abort.o exit.o \
-         mktime.o localtime.o gmtime.o difftime.o \
-         _daysyear.o ctime.o asctime.o strftime.o \
-         errno.o _sys_errlist.o strnlen.o
-
-#rules
-__abs.o: ../../__abs.c
-	$(CC) $(SCC_CFLAGS) ../../__abs.c -c
-
-__assert.o: ../../__assert.c
-	$(CC) $(SCC_CFLAGS) ../../__assert.c -c
-
-__getc.o: ../../__getc.c
-	$(CC) $(SCC_CFLAGS) ../../__getc.c -c
-
-__labs.o: ../../__labs.c
-	$(CC) $(SCC_CFLAGS) ../../__labs.c -c
-
-__llabs.o: ../../__llabs.c
-	$(CC) $(SCC_CFLAGS) ../../__llabs.c -c
-
-__putc.o: ../../__putc.c
-	$(CC) $(SCC_CFLAGS) ../../__putc.c -c
-
-_daysyear.o: ../../_daysyear.c
-	$(CC) $(SCC_CFLAGS) ../../_daysyear.c -c
-
-_flsbuf.o: ../../_flsbuf.c
-	$(CC) $(SCC_CFLAGS) ../../_flsbuf.c -c
-
-_fpopen.o: ../../_fpopen.c
-	$(CC) $(SCC_CFLAGS) ../../_fpopen.c -c
-
-abort.o: ../../abort.c
-	$(CC) $(SCC_CFLAGS) ../../abort.c -c
-
-abs.o: ../../abs.c
-	$(CC) $(SCC_CFLAGS) ../../abs.c -c
-
-asctime.o: ../../asctime.c
-	$(CC) $(SCC_CFLAGS) ../../asctime.c -c
-
-atexit.o: ../../atexit.c
-	$(CC) $(SCC_CFLAGS) ../../atexit.c -c
-
-atoi.o: ../../atoi.c
-	$(CC) $(SCC_CFLAGS) ../../atoi.c -c
-
-atol.o: ../../atol.c
-	$(CC) $(SCC_CFLAGS) ../../atol.c -c
-
-atoll.o: ../../atoll.c
-	$(CC) $(SCC_CFLAGS) ../../atoll.c -c
-
-bsearch.o: ../../bsearch.c
-	$(CC) $(SCC_CFLAGS) ../../bsearch.c -c
-
-calloc.o: ../../calloc.c
-	$(CC) $(SCC_CFLAGS) ../../calloc.c -c
-
-clearerr.o: ../../clearerr.c
-	$(CC) $(SCC_CFLAGS) ../../clearerr.c -c
-
-ctime.o: ../../ctime.c
-	$(CC) $(SCC_CFLAGS) ../../ctime.c -c
-
-ctype.o: ../../ctype.c
-	$(CC) $(SCC_CFLAGS) ../../ctype.c -c
-
-difftime.o: ../../difftime.c
-	$(CC) $(SCC_CFLAGS) ../../difftime.c -c
-
-errno.o: ../../errno.c
-	$(CC) $(SCC_CFLAGS) ../../errno.c -c
-
-exit.o: ../../exit.c
-	$(CC) $(SCC_CFLAGS) ../../exit.c -c
-
-fclose.o: ../../fclose.c
-	$(CC) $(SCC_CFLAGS) ../../fclose.c -c
-
-feof.o: ../../feof.c
-	$(CC) $(SCC_CFLAGS) ../../feof.c -c
-
-ferror.o: ../../ferror.c
-	$(CC) $(SCC_CFLAGS) ../../ferror.c -c
-
-fgetc.o: ../../fgetc.c
-	$(CC) $(SCC_CFLAGS) ../../fgetc.c -c
-
-fgets.o: ../../fgets.c
-	$(CC) $(SCC_CFLAGS) ../../fgets.c -c
-
-fopen.o: ../../fopen.c
-	$(CC) $(SCC_CFLAGS) ../../fopen.c -c
-
-fprintf.o: ../../fprintf.c
-	$(CC) $(SCC_CFLAGS) ../../fprintf.c -c
-
-fputc.o: ../../fputc.c
-	$(CC) $(SCC_CFLAGS) ../../fputc.c -c
-
-fputs.o: ../../fputs.c
-	$(CC) $(SCC_CFLAGS) ../../fputs.c -c
-
-fread.o: ../../fread.c
-	$(CC) $(SCC_CFLAGS) ../../fread.c -c
-
-freopen.o: ../../freopen.c
-	$(CC) $(SCC_CFLAGS) ../../freopen.c -c
-
-fseek.o: ../../fseek.c
-	$(CC) $(SCC_CFLAGS) ../../fseek.c -c
-
-ftell.o: ../../ftell.c
-	$(CC) $(SCC_CFLAGS) ../../ftell.c -c
-
-fwrite.o: ../../fwrite.c
-	$(CC) $(SCC_CFLAGS) ../../fwrite.c -c
-
-getc.o: ../../getc.c
-	$(CC) $(SCC_CFLAGS) ../../getc.c -c
-
-getchar.o: ../../getchar.c
-	$(CC) $(SCC_CFLAGS) ../../getchar.c -c
-
-gets.o: ../../gets.c
-	$(CC) $(SCC_CFLAGS) ../../gets.c -c
-
-gmtime.o: ../../gmtime.c
-	$(CC) $(SCC_CFLAGS) ../../gmtime.c -c
-
-isalnum.o: ../../isalnum.c
-	$(CC) $(SCC_CFLAGS) ../../isalnum.c -c
-
-isalpha.o: ../../isalpha.c
-	$(CC) $(SCC_CFLAGS) ../../isalpha.c -c
-
-isascii.o: ../../isascii.c
-	$(CC) $(SCC_CFLAGS) ../../isascii.c -c
-
-isblank.o: ../../isblank.c
-	$(CC) $(SCC_CFLAGS) ../../isblank.c -c
-
-iscntrl.o: ../../iscntrl.c
-	$(CC) $(SCC_CFLAGS) ../../iscntrl.c -c
-
-isdigit.o: ../../isdigit.c
-	$(CC) $(SCC_CFLAGS) ../../isdigit.c -c
-
-isgraph.o: ../../isgraph.c
-	$(CC) $(SCC_CFLAGS) ../../isgraph.c -c
-
-islower.o: ../../islower.c
-	$(CC) $(SCC_CFLAGS) ../../islower.c -c
-
-isprint.o: ../../isprint.c
-	$(CC) $(SCC_CFLAGS) ../../isprint.c -c
-
-ispunct.o: ../../ispunct.c
-	$(CC) $(SCC_CFLAGS) ../../ispunct.c -c
-
-isspace.o: ../../isspace.c
-	$(CC) $(SCC_CFLAGS) ../../isspace.c -c
-
-isupper.o: ../../isupper.c
-	$(CC) $(SCC_CFLAGS) ../../isupper.c -c
-
-isxdigit.o: ../../isxdigit.c
-	$(CC) $(SCC_CFLAGS) ../../isxdigit.c -c
-
-labs.o: ../../labs.c
-	$(CC) $(SCC_CFLAGS) ../../labs.c -c
-
-llabs.o: ../../llabs.c
-	$(CC) $(SCC_CFLAGS) ../../llabs.c -c
-
-localeconv.o: ../../localeconv.c
-	$(CC) $(SCC_CFLAGS) ../../localeconv.c -c
-
-localtime.o: ../../localtime.c
-	$(CC) $(SCC_CFLAGS) ../../localtime.c -c
-
-malloc.o: ../../malloc.c
-	$(CC) $(SCC_CFLAGS) ../../malloc.c -c
-
-memchr.o: ../../memchr.c
-	$(CC) $(SCC_CFLAGS) ../../memchr.c -c
-
-memcmp.o: ../../memcmp.c
-	$(CC) $(SCC_CFLAGS) ../../memcmp.c -c
-
-memcpy.o: ../../memcpy.c
-	$(CC) $(SCC_CFLAGS) ../../memcpy.c -c
-
-memmove.o: ../../memmove.c
-	$(CC) $(SCC_CFLAGS) ../../memmove.c -c
-
-memset.o: ../../memset.c
-	$(CC) $(SCC_CFLAGS) ../../memset.c -c
-
-mktime.o: ../../mktime.c
-	$(CC) $(SCC_CFLAGS) ../../mktime.c -c
-
-perror.o: ../../perror.c
-	$(CC) $(SCC_CFLAGS) ../../perror.c -c
-
-printf.o: ../../printf.c
-	$(CC) $(SCC_CFLAGS) ../../printf.c -c
-
-putc.o: ../../putc.c
-	$(CC) $(SCC_CFLAGS) ../../putc.c -c
-
-putchar.o: ../../putchar.c
-	$(CC) $(SCC_CFLAGS) ../../putchar.c -c
-
-puts.o: ../../puts.c
-	$(CC) $(SCC_CFLAGS) ../../puts.c -c
-
-qsort.o: ../../qsort.c
-	$(CC) $(SCC_CFLAGS) ../../qsort.c -c
-
-rand.o: ../../rand.c
-	$(CC) $(SCC_CFLAGS) ../../rand.c -c
-
-realloc.o: ../../realloc.c
-	$(CC) $(SCC_CFLAGS) ../../realloc.c -c
-
-rewind.o: ../../rewind.c
-	$(CC) $(SCC_CFLAGS) ../../rewind.c -c
-
-setbuf.o: ../../setbuf.c
-	$(CC) $(SCC_CFLAGS) ../../setbuf.c -c
-
-setlocale.o: ../../setlocale.c
-	$(CC) $(SCC_CFLAGS) ../../setlocale.c -c
-
-setvbuf.o: ../../setvbuf.c
-	$(CC) $(SCC_CFLAGS) ../../setvbuf.c -c
-
-snprintf.o: ../../snprintf.c
-	$(CC) $(SCC_CFLAGS) ../../snprintf.c -c
-
-sprintf.o: ../../sprintf.c
-	$(CC) $(SCC_CFLAGS) ../../sprintf.c -c
-
-stdio.o: ../../stdio.c
-	$(CC) $(SCC_CFLAGS) ../../stdio.c -c
-
-strcat.o: ../../strcat.c
-	$(CC) $(SCC_CFLAGS) ../../strcat.c -c
-
-strchr.o: ../../strchr.c
-	$(CC) $(SCC_CFLAGS) ../../strchr.c -c
-
-strcmp.o: ../../strcmp.c
-	$(CC) $(SCC_CFLAGS) ../../strcmp.c -c
-
-strcoll.o: ../../strcoll.c
-	$(CC) $(SCC_CFLAGS) ../../strcoll.c -c
-
-strcpy.o: ../../strcpy.c
-	$(CC) $(SCC_CFLAGS) ../../strcpy.c -c
-
-strcspn.o: ../../strcspn.c
-	$(CC) $(SCC_CFLAGS) ../../strcspn.c -c
-
-strerror.o: ../../strerror.c
-	$(CC) $(SCC_CFLAGS) ../../strerror.c -c
-
-strftime.o: ../../strftime.c
-	$(CC) $(SCC_CFLAGS) ../../strftime.c -c
-
-strlen.o: ../../strlen.c
-	$(CC) $(SCC_CFLAGS) ../../strlen.c -c
-
-strncat.o: ../../strncat.c
-	$(CC) $(SCC_CFLAGS) ../../strncat.c -c
-
-strncmp.o: ../../strncmp.c
-	$(CC) $(SCC_CFLAGS) ../../strncmp.c -c
-
-strncpy.o: ../../strncpy.c
-	$(CC) $(SCC_CFLAGS) ../../strncpy.c -c
-
-strnlen.o: ../../strnlen.c
-	$(CC) $(SCC_CFLAGS) ../../strnlen.c -c
-
-strpbrk.o: ../../strpbrk.c
-	$(CC) $(SCC_CFLAGS) ../../strpbrk.c -c
-
-strrchr.o: ../../strrchr.c
-	$(CC) $(SCC_CFLAGS) ../../strrchr.c -c
-
-strspn.o: ../../strspn.c
-	$(CC) $(SCC_CFLAGS) ../../strspn.c -c
-
-strstr.o: ../../strstr.c
-	$(CC) $(SCC_CFLAGS) ../../strstr.c -c
-
-strtok.o: ../../strtok.c
-	$(CC) $(SCC_CFLAGS) ../../strtok.c -c
-
-strxfrm.o: ../../strxfrm.c
-	$(CC) $(SCC_CFLAGS) ../../strxfrm.c -c
-
-tmpnam.o: ../../tmpnam.c
-	$(CC) $(SCC_CFLAGS) ../../tmpnam.c -c
-
-tolower.o: ../../tolower.c
-	$(CC) $(SCC_CFLAGS) ../../tolower.c -c
-
-toupper.o: ../../toupper.c
-	$(CC) $(SCC_CFLAGS) ../../toupper.c -c
-
-vfprintf.o: ../../vfprintf.c
-	$(CC) $(SCC_CFLAGS) ../../vfprintf.c -c
-
-vsnprintf.o: ../../vsnprintf.c
-	$(CC) $(SCC_CFLAGS) ../../vsnprintf.c -c
-
-vsprintf.o: ../../vsprintf.c
-	$(CC) $(SCC_CFLAGS) ../../vsprintf.c -c
-
--- a/lib/c/target/script/objlst.sh
+++ /dev/null
@@ -1,20 +1,0 @@
-#!/bin/sh
-
-set -e
-
-
-(cd ..
-echo H
-echo '/^#rules/+;$c'
-
-for i in *.c
-do
-	cat <<EOF
-${i%.c}.o: ../../$i
-	\$(CC) \$(SCC_CFLAGS) ../../$i -c
-
-EOF
-done
-
-echo .
-echo w)  | ed -s script/objlst.mk
--- a/lib/c/target/script/syscall.sh
+++ /dev/null
@@ -1,8 +1,0 @@
-#!/bin/sh
-
-(echo '/SYS/c'
- awk 'BEGIN  {printf "SYSCALL = "}
-      ! /^#/ {printf "%s.o ", $2}
-      END    {print ""}' syscall.lst
- echo .
- echo w) | ed -s syscall.mk
--- a/lib/c/target/z80-scc-none/Makefile
+++ /dev/null
@@ -1,9 +1,0 @@
-.POSIX:
-
-PROJECTDIR = ../../../..
-
-include $(PROJECTDIR)/rules.mk
-include ../objlst.mk
-include ../common.mk
-
-SCC_CFLAGS = -nostdinc -I../../include -I../../include/bits/z80-none/
--- /dev/null
+++ b/lib/c/time/Makefile
@@ -1,0 +1,16 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+MORECFLAGS = -w
+
+OBJS = _daysyear.o\
+       asctime.o\
+       ctime.o\
+       difftime.o\
+       gmtime.o\
+       localtime.o\
+       mktime.o\
+       strftime.o\
+
+all: $(OBJS)
--- /dev/null
+++ b/lib/c/time/_daysyear.c
@@ -1,0 +1,30 @@
+#include <time.h>
+#include "../libc.h"
+
+int _daysmon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+int
+_daysyear(int year)
+{
+	if (year%4 != 0)
+		return 365;
+	if (year%100 == 0 && year%400 != 0)
+		return 365;
+	return 366;
+}
+
+/*
+ * Happy New Year!!!!
+ */
+int
+_newyear(int year)
+{
+	int day;
+
+	year += 1900 - 1;
+	day = 1 + year + year/4;
+	day -= year/100;
+	day += year/400;
+
+	return day % 7;
+}
--- /dev/null
+++ b/lib/c/time/asctime.c
@@ -1,0 +1,12 @@
+#include <time.h>
+#undef asctime
+
+#include <stdio.h> // TODO: remove me!
+char *
+asctime(const struct tm *tm)
+{
+	static char buf[30];
+
+	strftime(buf, sizeof(buf), "%c\n", tm);
+	return buf;
+}
--- /dev/null
+++ b/lib/c/time/ctime.c
@@ -1,0 +1,8 @@
+#include <time.h>
+#undef ctime
+
+char *
+ctime(const time_t *t)
+{
+	return asctime(localtime(t));
+}
--- /dev/null
+++ b/lib/c/time/difftime.c
@@ -1,0 +1,8 @@
+#include <time.h>
+#undef difftime
+
+double
+difftime(time_t t1, time_t t2)
+{
+	return (double) (t1 - t2);
+}
--- /dev/null
+++ b/lib/c/time/gmtime.c
@@ -1,0 +1,35 @@
+#include <time.h>
+#include "libc.h"
+#undef gmtime
+
+struct tm *
+gmtime(const time_t *t)
+{
+        static struct tm tm;
+        time_t sec, min, hour, year, day;
+	int i;
+
+        tm.tm_sec = *t % SECDAY;
+	tm.tm_min = tm.tm_sec / 60;
+	tm.tm_sec %= 60;
+	tm.tm_hour = tm.tm_min / 60;
+	tm.tm_min %= 60;
+	day = *t / SECDAY;
+
+	tm.tm_wday = (day + THU) % 7; /* 1/1/1970 was Thursday */
+
+	for (i = EPOCH; day >= _daysyear(i); ++i)
+		day -= _daysyear(i);
+        tm.tm_year = i - 1900;
+	tm.tm_yday = day;
+
+	_daysmon[FEB] = FEBDAYS(tm.tm_year);
+	for (i = JAN; day > _daysmon[i]; i++)
+		day -= _daysmon[i];
+	tm.tm_mon = i;
+	tm.tm_mday = day + 1;
+
+	tm.tm_isdst = 0;
+
+        return &tm;
+}
--- /dev/null
+++ b/lib/c/time/localtime.c
@@ -1,0 +1,21 @@
+#include <time.h>
+#include "libc.h"
+#undef localtime
+
+struct tm *
+localtime(const time_t *timep)
+{
+	struct tzone *tz;
+	struct tm *tm;
+	time_t t = *timep;
+
+	t += tz->gmtoff * 60;
+	t += tz->isdst * 60;
+	tm = gmtime(&t);
+	tz = _tzone(tm);
+	tm->tm_zone = tz->name;
+	tm->tm_isdst = tz->isdst;
+	tm->tm_gmtoff = tz->gmtoff;
+
+	return tm;
+}
--- /dev/null
+++ b/lib/c/time/mktime.c
@@ -1,0 +1,112 @@
+#include <limits.h>
+#include <time.h>
+#include "libc.h"
+#undef mktime
+
+static int
+norm(int *val, int *next, int qty)
+{
+	int v = *val, n = *next, d;
+
+	if (v < 0) {
+		d = -v / qty + 1;
+		v += d * qty;
+		if (n > INT_MAX - d)
+			return 0;
+		n += d;
+	}
+	if (v >= qty) {
+		d = v / qty;
+		v -= d * qty;
+		if (n < INT_MIN + d)
+			return 0;
+		n -= d;
+	}
+
+	*val = v;
+	*next = n;
+	return 1;
+}
+
+static int
+normalize(struct tm *tm)
+{
+	int mon, day, year;
+	struct tm aux = *tm;
+
+	if (!norm(&tm->tm_sec, &tm->tm_min, 60)   ||
+	    !norm(&tm->tm_min, &tm->tm_hour, 60)  ||
+	    !norm(&tm->tm_hour, &tm->tm_mday, 24) ||
+	    !norm(&tm->tm_mon, &tm->tm_year, 12)) {
+		return 0;
+	}
+
+	day = tm->tm_mday;
+	year = EPOCH + tm->tm_year;
+	_daysmon[FEB] = FEBDAYS(year);
+
+	for (mon = tm->tm_mon; day < 1; --mon) {
+		day += _daysmon[mon];
+		if (mon == JAN) {
+			if (year == EPOCH)
+				return -1;
+			year--;
+			_daysmon[FEB] = FEBDAYS(year);
+			mon = DEC+1;
+		}
+	}
+
+	for (; day > _daysmon[mon]; ++mon) {
+		day -= _daysmon[mon];
+		if (mon == DEC) {
+			if (year == _MAXYEAR)
+				return -1;
+			year++;
+			_daysmon[FEB] = FEBDAYS(year);
+			mon = JAN-1;
+		}
+	}
+
+	tm->tm_mon = mon;
+	tm->tm_year = year - EPOCH;
+	tm->tm_mday = day;
+	tm->tm_wday = (_newyear(tm->tm_year) + tm->tm_yday) % 7;
+
+	return 1;
+}
+
+time_t
+mktime(struct tm *tm)
+{
+	int i, year, dst;
+	time_t t;
+	struct tm *aux;
+
+	if (!normalize(tm))
+		return -1;
+
+	t = 0;
+	year = tm->tm_year + 1900;
+	for (i = EPOCH; i < year; i++)
+		t += _daysyear(i) * SECDAY;
+
+	for (i = 0; i < tm->tm_mon; i++)
+		t += _daysmon[i] * SECDAY;
+
+	t += tm->tm_sec;
+	t += tm->tm_min * SECMIN;
+	t += tm->tm_hour * SECHOUR;
+	t += (tm->tm_mday-1) * SECDAY;
+
+	aux = localtime(&t);
+
+	dst = 0;
+	if (tm->tm_isdst == 0 && aux->tm_isdst == 1)
+		dst = -SECHOUR;
+	else if (tm->tm_isdst == 1 && aux->tm_isdst == 0)
+		dst = +SECHOUR;
+
+	t += aux->tm_gmtoff + dst;
+
+	return t;
+}
--- /dev/null
+++ b/lib/c/time/strftime.c
@@ -1,0 +1,246 @@
+#include <time.h>
+#include <string.h>
+#include "libc.h"
+#undef strftime
+
+static char *days[] = {
+	"Sunday",   "Monday", "Tuesday",  "Wednesday",
+	"Thursday", "Friday", "Saturday", 
+};
+
+static char *months[] = {
+	"January",   "February", "March",    "April",
+	"May",       "June",     "July",     "August",
+	"September", "October",  "November", "December"
+};
+
+static char *am_pm[] = {"AM", "PM"};
+
+static size_t
+sval(char *s, size_t siz, char **strs, int abrev, int idx, int max)
+{
+	char *str;
+	size_t len;
+
+	if (idx < 0 && idx >= max)
+		goto wrong;
+
+	str = strs[idx];
+	len = (!abrev) ? strlen(str) : 3;
+	if (len > siz)
+		goto wrong;
+
+	memcpy(s, str, len);
+	return len;
+
+wrong:
+	*s = '?';
+	return 1;
+}
+
+static size_t
+dval(char *s, size_t siz, int prec, int fill, int val)
+{
+	char *t;
+	int n;
+	static char digits[] = "0123456789";
+
+	if (prec > siz || val < 0) {
+		*s = '?';
+		return 1;
+	}
+
+	n = prec;
+	do {
+		s[--n] = digits[val % 10];
+		val /= 10;
+	} while (n > 0 && val > 0);
+
+	while (n > 0)
+		s[--n] = fill;
+
+	return prec;
+}
+
+static size_t
+timezone(char *s, size_t prec, const struct tm * restrict tm)
+{
+	long off = tm->tm_gmtoff;
+
+	if (prec < 5) {
+		*s = '?';
+		return 1;
+	}
+
+	if (off >= 0) {
+		*s++ = '+';
+	} else {
+		*s++ = '-';
+		off = -off;
+	}
+
+	dval(s, 2, 2, '0', off / 3600);
+	dval(s, 2, 2, '0', (off % 3600) / 60);
+
+	return 5;
+}
+
+size_t
+strftime(char * restrict s, size_t siz,
+         const char * restrict fmt,
+         const struct tm * restrict tm)
+{
+	int ch, abrev, val, fill, width;
+	size_t n, inc;
+	char *tfmt;
+
+	for (n = siz-1; (ch = *fmt++) && n > 0; s += inc, n -= inc) {
+		if (ch != '%') {
+			*s = ch;
+			inc = 1;
+			continue;
+		}
+
+		abrev = 0;
+		fill = '0';
+		width = 2;
+
+		switch (*fmt++) {
+		case 'Z':
+			if (!tm->tm_zone)
+				break;
+			inc = sval(s, n, &tm->tm_zone, 0, 0, 1);
+			break;
+		case 'a':
+			abrev = 1;
+		case 'A':
+			inc = sval(s, n, days, abrev, tm->tm_wday, 7);
+			break;
+		case 'h':
+		case 'b':
+			abrev = 1;
+		case 'B':
+			inc = sval(s, n, months, abrev, tm->tm_mon, 12);
+			break;
+		case 'p':
+			inc = sval(s, n, am_pm, 0, tm->tm_hour > 12, 2);
+			break;
+		case 'c':
+			tfmt = "%a %b %e %T %Y";
+			goto recursive;
+		case 'D':
+			tfmt = "%m/%d/%y";
+			goto recursive;
+		case 'F':
+			tfmt = "%Y-%m-%d";
+			goto recursive;
+		case 'R':
+			tfmt = "%H:%M";
+			goto recursive;
+		case 'X':
+		case 'T':
+			tfmt = "%H:%M:%S";
+			goto recursive;
+		case 'r':
+			tfmt = "%I:%M:%S %p";
+			goto recursive;
+		case 'x':
+			tfmt = "%m/%d/%y";
+			goto recursive;
+		recursive:
+			inc = strftime(s, n+1, tfmt, tm) - 1;
+			break;
+		case 'n':
+			val = '\n';
+			goto character;
+		case 't': 
+			val = '\t';
+			goto character;
+		case '%': 
+			val = '%';
+		character:
+			*s = val;
+			inc = 1;
+			break;
+		case 'e':
+			fill = ' ';
+			val = tm->tm_mday;
+			goto number;
+		case 'd':
+			val = tm->tm_mday;
+			goto number;
+		case 'V':
+		case 'g':
+		case 'G':
+			/* TODO */
+			break;
+		case 'C':
+			val = tm->tm_year / 100;
+			goto number;
+		case 'H':
+			val = tm->tm_hour;
+			goto number;
+		case 'I':
+			val = tm->tm_hour;
+			if (val == 0)
+				val = 12;
+			if (val > 12)
+				val -= 12;
+			goto number;
+		case 'j':
+			width = 3;
+			val = tm->tm_yday+1;
+			goto number;
+		case 'm':
+			val = tm->tm_mon+1;
+			goto number;
+		case 'M':
+			val = tm->tm_min;
+			goto number;
+		case 'S':
+			val = tm->tm_sec;
+			goto number;
+		case 'u':
+			width = 1;
+			val = tm->tm_wday+1;
+			goto number;
+		case 'U':
+			val = tm->tm_yday / 7;
+			if (_newyear(tm->tm_year) == SAT)
+				val++;
+			goto number;
+		case 'W':
+			val = tm->tm_yday / 7;
+			if (_newyear(tm->tm_year) == MON)
+				val++;
+			goto number;
+		case 'w':
+			width = 1;
+			val = tm->tm_wday;
+			goto number;
+		case 'y':
+			val = tm->tm_year%100;
+			goto number;
+		case 'Y':
+			width = 4;
+			val = 1900 + tm->tm_year;
+		number:
+			inc = dval(s, n, width, fill, val);
+			break;
+		case 'z':
+			inc = timezone(s, n, tm);
+			break;
+		case 'E':
+		case 'O':
+			if (*fmt != '\0')
+				fmt += 2;;
+		case '\0':
+			inc = 0;
+			--fmt;
+			break;
+		}
+	}
+	*s = '\0';
+
+	return siz - n;
+}
--- a/lib/c/tmpnam.c
+++ /dev/null
@@ -1,31 +1,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "syscall.h"
-#undef tmpnam
-
-char *
-tmpnam(char *s)
-{
-	static char *tmpl, buf[L_tmpnam];
-	char *p;
-
-	if (*buf == '\0') {
-		for (tmpl = buf, p = _TMPNAME; *tmpl++ = *p++; )
-			;
-		for (p = tmpl; p < &buf[L_tmpnam-1]; ++p)
-			*p = '0';
-		*p = '\0';
-	}
-	for (;;) {
-		for (p = tmpl; *p && *p != '9'; ++p)
-			;
-		if (*p == '\0')
-			return NULL;
-		++*p;
-		if (_access(buf, 0) != 0)
-			break;
-	}
-	if (s)
-		strcpy(s, buf);
-	return buf;
-}
--- a/lib/c/tolower.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef tolower
-
-int
-tolower(int c)
-{
-	return (isupper(c)) ? c | 0x20 : c;
-}
--- a/lib/c/toupper.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#define __USE_MACROS
-#include <ctype.h>
-#undef toupper
-
-int
-toupper(int c)
-{
-	return (islower(c)) ? c & ~0x20 : c;
-}
--- a/lib/c/vfprintf.c
+++ /dev/null
@@ -1,361 +1,0 @@
-#include <ctype.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <wchar.h>
-#undef vfprintf
-
-enum {
-	LONG     = 1 << 0,
-	LLONG    = 1 << 1,
-	SHORT    = 1 << 2,
-	CHAR     = 1 << 3,
-	SIZET    = 1 << 4,
-	PTRDIFF  = 1 << 5,
-	INTMAX   = 1 << 6,
-	VOIDPTR  = 1 << 7,
-	UNSIGNED = 1 << 8,
-	ALTFORM  = 1 << 9,
-};
-
-#define MAXPREC    50
-
-struct conv {
-	int sign;
-	int prec;
-	char *digs;
-	int base;
-};
-
-static uintmax_t
-getnum(va_list *va, int flags, int *sign)
-{
-	uintmax_t uval;
-	intmax_t val;
-
-	if (flags & CHAR) {
-		val = va_arg(*va, int);
-		uval = (unsigned char) val;
-	} else if (flags & SHORT) {
-		val = va_arg(*va, int);
-		uval = (unsigned short) val;
-	} else if (flags & LONG) {
-		val = va_arg(*va, long);
-		uval = (unsigned long) val;
-	} else if (flags & LLONG) {
-		val = va_arg(*va, long long);
-		uval = (unsigned long long) val;
-	} else if (flags & SIZET) {
-		uval = va_arg(*va, size_t);
-	} else if (flags & INTMAX) {
-		val = va_arg(*va, intmax_t);
-		uval = (uintmax_t) val;
-	} else if (flags & VOIDPTR) {
-		uval = (uintmax_t) va_arg(*va, void *);
-	} else {
-		val = va_arg(*va, int);
-		uval = (unsigned) val;
-	}
-
-	if ((flags & UNSIGNED) == 0 && val < 0) {
-		*sign = '-';
-		uval = -uval;
-	}
-	return uval;
-}
-
-static char *
-numtostr(uintmax_t val, int flags, struct conv *conv, char *buf)
-{
-	char *buf0 = buf;
-	int base = conv->base, prec = conv->prec;
-	uintmax_t oval = val;
-
-	if (prec == -1)
-		prec = 1;
-
-	for (*buf = '\0'; val > 0; val /= base)
-		*--buf = conv->digs[val % base];
-	while (buf0 - buf < prec)
-		*--buf = '0';
-
-	if (flags & ALTFORM) {
-		if (base == 8 && *buf != '0') {
-			*--buf = '0';
-		} else if (base == 16 && oval != 0) {
-			*--buf = conv->digs[16];
-			*--buf = '0';
-		}
-	}
-	if (conv->sign)
-		*--buf = conv->sign;
-
-	return buf;
-}
-
-static void
-savecnt(va_list *va, int flags, int cnt)
-{
-	if (flags & CHAR)
-		*va_arg(*va, char*) = cnt;
-	else if (flags & SHORT)
-		*va_arg(*va, short*) = cnt;
-	else if (flags & LONG)
-		*va_arg(*va, long*) = cnt;
-	else if (flags & LLONG)
-		*va_arg(*va, long long*) = cnt;
-	else if (flags & SIZET)
-		*va_arg(*va, size_t*) = cnt;
-	else if (flags & INTMAX)
-		*va_arg(*va, intmax_t*) = cnt;
-	else
-		*va_arg(*va, int*) = cnt;
-}
-
-static size_t
-wstrout(wchar_t *ws, size_t len, int width, int fill, FILE * restrict fp)
-{
-	int left = 0, adjust;
-	size_t cnt = 0;
-	wchar_t wc;
-#if 0
-
-	if (width < 0) {
-		left = 1;
-		width = -width;
-	}
-
-	len *= sizeof(wchar_t);
-	adjust = (len < width) ? width - len : 0;
-	cnt = adjust + len;
-	if (left)
-		adjust = -adjust;
-
-	for ( ; adjust > 0; adjust++)
-		putc(fill, fp);
-
-	while (wc = *ws++)
-		putwc(wc, fp);
-
-	for ( ; adjust < 0; adjust--)
-		putc(' ', fp);
-#endif
-	return cnt;
-}
-
-static size_t
-strout(char *s, size_t len, int width, int fill, FILE * restrict fp)
-{
-	int left = 0, adjust, ch, prefix;
-	size_t cnt = 0;
-
-	if (width < 0) {
-		left = 1;
-		width = -width;
-	}
-
-	adjust = (len < width) ? width - len : 0;
-	cnt = adjust + len;
-	if (left)
-		adjust = -adjust;
-
-	if (fill == '0') {
-		if (*s == '-' || *s == '+')
-			prefix = 1;
-		else if (*s == '0' && toupper(s[1]) == 'X')
-			prefix = 2;
-		else
-			prefix = 0;
-		while (prefix--) {
-			putc(*s++, fp);
-			--len;
-		}
-	}
-
-	for ( ; adjust > 0; adjust--)
-		putc(fill, fp);
-
-	while (ch = *s++)
-		putc(ch, fp);
-
-	for ( ; adjust < 0; adjust++)
-		putc(' ', fp);
-
-	return cnt;
-}
-
-int
-vfprintf(FILE * restrict fp, const char *fmt, va_list va)
-{
-	int ch, n, flags, width, left, fill, cnt = 0;
-	size_t inc, len;
-	char *s;
-	wchar_t *ws;
-	struct conv conv;
-	char buf[MAXPREC+1];
-	wchar_t wbuf[2];
-
-	for (cnt = 0; ch = *fmt++; cnt += inc) {
-		if (ch != '%') {
-			putc(ch, fp);
-			inc = 1;
-			continue;
-		}
-
-		fill = ' ';
-		left = flags = width =  0;
-		conv.prec = -1;
-		conv.base = 10;
-		conv.sign = '\0';
-		conv.digs = "0123456789ABCDEFX";
-
-flags:
-		switch (*fmt++) {
-		case ' ':
-			if (conv.sign == '\0')
-				conv.sign = ' ';
-			goto flags;
-		case '+':
-			conv.sign = '+';
-			goto flags;
-		case '#':
-			flags |= ALTFORM;
-			goto flags;
-		case '.':
-			if (*fmt == '*') {
-				fmt++;
-				n = va_arg(va, int);
-			} else {
-				for (n = 0; isdigit(ch = *fmt); fmt++)
-					n = n * 10 + ch - '0';
-			}
-			if (n > MAXPREC)
-				n = MAXPREC;
-			if (n > 0)
-				conv.prec = n;
-			goto flags;
-		case '*':
-			width = va_arg(va, int);
-			goto flags;
-		case '-':
-			left = 1;
-			++fmt;
-		case '1':
-		case '2':
-		case '3':
-		case '4':
-		case '5':
-		case '6':
-		case '7':
-		case '8':
-		case '9':
-			--fmt;
-			for (n = 0; isdigit(ch = *fmt); ++fmt)
-				n = n * 10 + ch - '0';
-			if (left)
-				n = -n;
-			width = n;
-			goto flags;
-		case '0':
-			fill = '0';
-			goto flags;
-		case 'l':
-			flags += LONG;
-			goto flags;
-		case 'h':
-			flags += SHORT;
-			goto flags;
-		case '%':
-			ch = '%';
-			goto cout;
-		case 'c':
-			if (flags & LONG) {
-				wbuf[0] = va_arg(va, wint_t);
-				wbuf[1] = L'\0';
-				ws = wbuf;
-				len = 1;
-				goto wstrout;
-			}
-			ch = va_arg(va, int);
-		cout:
-			buf[0] = ch;
-			buf[1] = '\0';
-			s = buf;
-			len = 1;
-			goto strout;
-		case 'j':
-			flags |= INTMAX;
-			goto flags;
-		case 't':
-			flags |= PTRDIFF;
-			goto flags;
-		case 'z':
-			flags |= SIZET;
-			goto flags;
-		case 'u':
-			flags |= UNSIGNED;
-		case 'i':
-		case 'd':
-		numeric10:
-			conv.base = 10;
-			goto numeric;
-		case 'p':
-			flags |= VOIDPTR | ALTFORM;
-			goto numeric16;
-		case 'x':
-			conv.digs = "0123456789abcdefx";
-		case 'X':
-		numeric16:
-			conv.base = 16;
-			flags |= UNSIGNED;
-			goto numeric;
-		case 'o':
-			conv.base = 8;
-			flags |= UNSIGNED;
-		numeric:
-			if (conv.prec != -1)
-				fill = ' ';
-			s = numtostr(getnum(&va, flags, &conv.sign),
-			             flags,
-			             &conv,
-			             &buf[MAXPREC]);
-			len = &buf[MAXPREC] - s;
-			goto strout;
-		case 'L':
-		case 'a':
-		case 'A':
-		case 'e':
-		case 'E':
-		case 'f':
-		case 'g':
-		case 'G':
-			/* TODO */
-		case 's':
-			if (flags & LONG) {
-				ws = va_arg(va, wchar_t *);
-				/* len = wcsnlen(ws, conv.prec); */
-				goto wstrout;
-			} else {
-				s = va_arg(va, char *);
-				len = strnlen(s, conv.prec);
-				goto strout;
-			}
-		wstrout:
-			inc = wstrout(ws, len, width, fill, fp);
-			break;
-		strout:
-			inc = strout(s, len, width, fill, fp);
-			break;
-		case 'n':
-			savecnt(&va, flags, cnt);
-			break;
-		case '\0':
-			goto out_loop;
-		}
-	}
-
-out_loop:
-	return (ferror(fp)) ? EOF : cnt;
-}
--- a/lib/c/vsnprintf.c
+++ /dev/null
@@ -1,25 +1,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#undef vsnprintf
-
-int
-vsnprintf(char * restrict s, size_t siz, const char * restrict fmt, va_list ap)
-{
-	FILE f;
-	int r;
-
-	f.flags = _IORW | _IOSTRG;
-	f.len = siz;
-	f.buf = s;
-	f.wp = s;
-	f.rp = s + siz;
-
-	r = vfprintf(&f, fmt, ap);
-	if (s) {
-		if (f.wp == f.rp)
-			--f.wp;
-		*f.wp = '\0';
-	}
-
-	return r;
-}
--- a/lib/c/vsprintf.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include <limits.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#undef vsprintf
-
-
-int
-vsprintf(char * restrict s, const char * restrict fmt, va_list va)
-{
-	return vsnprintf(s, SIZE_MAX, fmt, va);
-}
--- a/root/include/scc/bits/amd64-sysv/arch/limits.h
+++ /dev/null
@@ -1,18 +1,0 @@
-#define CHAR_BIT   8
-#define SCHAR_MAX  0x7F
-#define SCHAR_MIN  (-SCHAR_MAX-1)
-#define CHAR_MAX   0x7F
-#define CHAR_MIN   (-CHAR_MAX-1)
-#define UCHAR_MAX  0xFF
-#define SHRT_MAX   0x7FFF
-#define SHRT_MIN   (-SHRT_MAX-1)
-#define USHRT_MAX  0xFFFF
-#define INT_MAX    0x7FFFFFFF
-#define INT_MIN    (-INT_MAX-1)
-#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/amd64-sysv/arch/setjmp.h
+++ /dev/null
@@ -1,1 +1,0 @@
-typedef unsigned long long jmp_buf[8];
--- a/root/include/scc/bits/amd64-sysv/arch/stddef.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/root/include/scc/bits/amd64-sysv/arch/stdint.h
+++ /dev/null
@@ -1,115 +1,0 @@
-#define INT8_MAX  0x7F
-#define INT8_MIN  (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX  0x7FFF
-#define INT16_MIN  (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX  0x7FFFFFFF
-#define INT32_MIN  (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#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
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN  INT16_MIN
-#define INT_LEAST16_MAX  INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN  INT32_MIN
-#define INT_LEAST32_MAX  INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN  INT64_MIN
-#define INT_LEAST64_MAX  INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN  INT32_MIN
-#define INT_FAST8_MAX  INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN  INT32_MIN
-#define INT_FAST16_MAX  INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN  INT32_MIN
-#define INT_FAST32_MAX  INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN  INT64_MIN
-#define INT_FAST64_MAX  INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN  INT64_MIN
-#define INTPTR_MAX  INT64_MAX
-#define UINTPTR_MAX UINT64_MAX
-
-#define INTMAX_MIN  INT64_MIN
-#define INTMAX_MAX  INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT64_MIN
-#define PTRDIFF_MAX INT64_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT64_MAX
-
-#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;
-typedef long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long uint64_t;
-
-typedef signed char int8_least_t;
-typedef short int16_least_t;
-typedef int int32_least_t;
-typedef long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned short uint16_least_t;
-typedef unsigned uint32_least_t;
-typedef unsigned long uint64_least_t;
-
-typedef int int8_fast_t;
-typedef int int16_fast_t;
-typedef int int32_fast_t;
-typedef long int64_fast_t;
-
-typedef unsigned uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned uint32_fast_t;
-typedef unsigned long uint64_fast_t;
-
-typedef long intptr_t;
-typedef unsigned long uintptr_t;
-
-typedef long intmax_t;
-typedef unsigned long uintmax_t;
--- a/root/include/scc/bits/amd64-sysv/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ        512
-#define FILENAME_MAX  256
-#define FOPEN_MAX      16
-
-#define TMP_MAX        25
-#define L_tmpnam      256
-
-#define _TMPNAME      "/tmp/tmp.0000000"
-
-typedef int fpos_t;
--- a/root/include/scc/bits/amd64-sysv/arch/stdlib.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE long double
--- a/root/include/scc/bits/amd64-sysv/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#endif
-
-#define __NUMCHARS 128
--- a/root/include/scc/bits/amd64-sysv/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define _MAXYEAR 9999
-
-typedef long int time_t;
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/limits.h
@@ -1,0 +1,18 @@
+#define CHAR_BIT   8
+#define SCHAR_MAX  0x7F
+#define SCHAR_MIN  (-SCHAR_MIN-1)
+#define CHAR_MAX   0x7F
+#define CHAR_MIN   (-CHAR_MAX-1)
+#define UCHAR_MAX  0xFF
+#define SHRT_MAX   0x7FFF
+#define SHRT_MIN   (-SHRT_MAX-1)
+#define USHRT_MAX  0xFFFF
+#define INT_MAX    0x7FFFFFFF
+#define INT_MIN    (-INT_MAX-1)
+#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
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/setjmp.h
@@ -1,0 +1,1 @@
+typedef unsigned long long jmp_buf[8];
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/stddef.h
@@ -1,0 +1,14 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#ifndef _PTRDIFF_T
+typedef long ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/stdint.h
@@ -1,0 +1,115 @@
+#define INT8_MAX  0x7F
+#define INT8_MIN  (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX  0x7FFF
+#define INT16_MIN  (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX  0x7FFFFFFF
+#define INT32_MIN  (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#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
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN  INT16_MIN
+#define INT_LEAST16_MAX  INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN  INT32_MIN
+#define INT_LEAST32_MAX  INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN  INT64_MIN
+#define INT_LEAST64_MAX  INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN  INT32_MIN
+#define INT_FAST8_MAX  INT32_MAX
+#define UINT_FAST8_MAX UINT32_MAX
+
+#define INT_FAST16_MIN  INT32_MIN
+#define INT_FAST16_MAX  INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN  INT32_MIN
+#define INT_FAST32_MAX  INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN  INT64_MIN
+#define INT_FAST64_MAX  INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN  INT64_MIN
+#define INTPTR_MAX  INT64_MAX
+#define UINTPTR_MAX UINT64_MAX
+
+#define INTMAX_MIN  INT64_MIN
+#define INTMAX_MAX  INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT64_MIN
+#define PTRDIFF_MAX INT64_MAX
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#define SIZE_MAX UINT64_MAX
+
+#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;
+typedef long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned uint32_t;
+typedef unsigned long uint64_t;
+
+typedef signed char int8_least_t;
+typedef short int16_least_t;
+typedef int int32_least_t;
+typedef long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned short uint16_least_t;
+typedef unsigned uint32_least_t;
+typedef unsigned long uint64_least_t;
+
+typedef int int8_fast_t;
+typedef int int16_fast_t;
+typedef int int32_fast_t;
+typedef long int64_fast_t;
+
+typedef unsigned uint8_fast_t;
+typedef unsigned uint16_fast_t;
+typedef unsigned uint32_fast_t;
+typedef unsigned long uint64_fast_t;
+
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/stdio.h
@@ -1,0 +1,15 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ        512
+#define FILENAME_MAX  256
+#define FOPEN_MAX      16
+
+#define TMP_MAX        25
+#define L_tmpnam      256
+
+#define _TMPNAME      "/tmp/tmp.0000000"
+
+typedef int fpos_t;
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/stdlib.h
@@ -1,0 +1,14 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE long double
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/string.h
@@ -1,0 +1,5 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#endif
+
+#define __NUMCHARS 128
\ No newline at end of file
--- /dev/null
+++ b/root/include/scc/bits/amd64/arch/time.h
@@ -1,0 +1,8 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define _MAXYEAR 9999
+
+typedef long int time_t;
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/limits.h
@@ -1,0 +1,18 @@
+#define CHAR_BIT   8
+#define SCHAR_MAX  0x7F
+#define SCHAR_MIN  (-SCHAR_MIN - 1)
+#define CHAR_MAX   0x7F
+#define CHAR_MIN   (-CHAR_MAX - 1)
+#define UCHAR_MAX  0xFFU
+#define SHRT_MAX   0x7FFF
+#define SHRT_MIN   (-SHRT_MAX - 1)
+#define USHRT_MAX  0xFFFFU
+#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
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/setjmp.h
@@ -1,0 +1,1 @@
+typedef unsigned long long jmp_buf[22];
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/stddef.h
@@ -1,0 +1,9 @@
+#ifndef SIZET_
+typedef unsigned long size_t;
+#define SIZET_
+#endif
+
+#ifndef _PTRDIFF_T
+typedef long ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/stdint.h
@@ -1,0 +1,109 @@
+#define INT8_MAX  0x7F
+#define INT8_MIN  (-INT8_MAX - 1)
+#define UINT8_MAX 0xFFU
+
+#define INT16_MAX  0x7FFF
+#define INT16_MIN  (-INT16_MAX - 1)
+#define UINT16_MAX 0xFFFFU
+
+#define INT32_MAX  0x7FFFFFFF
+#define INT32_MIN  (-INT32_MAX - 1)
+#define UINT32_MAX 0xFFFFFFFFU
+
+#define INT64_MAX  0x7FFFFFFFFFFFFFFFLL
+#define INT64_MIN  (-INT64_MAX - 1LL)
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
+
+#define INT_LEAST8_MIN  INT8_MIN
+#define INT_LEAST8_MAX  INT8_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN  INT16_MIN
+#define INT_LEAST16_MAX  INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN  INT32_MIN
+#define INT_LEAST32_MAX  INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN  INT64_MIN
+#define INT_LEAST64_MAX  INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN  INT32_MIN
+#define INT_FAST8_MAX  INT32_MAX
+#define UINT_FAST8_MAX UINT32_MAX
+
+#define INT_FAST16_MIN  INT32_MIN
+#define INT_FAST16_MAX  INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN  INT32_MIN
+#define INT_FAST32_MAX  INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN  INT64_MIN
+#define INT_FAST64_MAX  INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN  INT64_MIN
+#define INTPTR_MAX  INT64_MAX
+#define UINTPTR_MAX UINT64_MAX
+
+#define INTMAX_MIN  INT64_MIN
+#define INTMAX_MAX  INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT64_MIN
+#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;
+typedef int int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_least_t;
+typedef short int16_least_t;
+typedef int int32_least_t;
+typedef long long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned short uint16_least_t;
+typedef unsigned int uint32_least_t;
+typedef unsigned long long uint64_least_t;
+
+typedef int int8_fast_t;
+typedef int int16_fast_t;
+typedef int int32_fast_t;
+typedef long long int64_fast_t;
+
+typedef unsigned int uint8_fast_t;
+typedef unsigned int uint16_fast_t;
+typedef unsigned int uint32_fast_t;
+typedef unsigned long long uint64_fast_t;
+
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/stdio.h
@@ -1,0 +1,15 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ        512
+#define FILENAME_MAX  256
+#define FOPEN_MAX      16
+
+#define TMP_MAX        25
+#define L_tmpnam      256
+
+#define _TMPNAME      "/tmp/tmp.0000000"
+
+typedef int fpos_t;
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/stdlib.h
@@ -1,0 +1,14 @@
+#ifndef SIZET_
+typedef unsigned long size_t;
+#define SIZET_
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE long double
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/string.h
@@ -1,0 +1,6 @@
+#ifndef SIZET_
+typedef unsigned long size_t;
+#define SIZET_
+#endif
+
+#define __NUMCHARS 128
--- /dev/null
+++ b/root/include/scc/bits/arm64/arch/time.h
@@ -1,0 +1,8 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define _MAXYEAR 9999
+
+typedef long int time_t;
--- /dev/null
+++ b/root/include/scc/bits/dragonfly/sys.h
@@ -1,0 +1,19 @@
+#define O_RDONLY  0x00000000
+#define O_WRONLY  0x00000001
+#define O_RDWR    0x00000002
+
+#define O_TRUNC   0x00000400
+#define O_APPEND  0x00000008
+#define O_CREAT   0x00000200
+
+typedef int pid_t;
+
+struct sigaction {
+	void (*sa_handler)(int);
+	char sa_mask[8];
+	int sa_flags;
+};
+
+extern pid_t _getpid(void);
+extern int _kill(pid_t pid, int signum);
+extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- /dev/null
+++ b/root/include/scc/bits/dragonfly/sys/signal.h
@@ -1,0 +1,12 @@
+typedef int sig_atomic_t;
+
+#define SIG_ERR    ((void (*)(int))-1)
+#define SIG_DFL    ((void (*)(int)) 0)
+#define SIG_IGN    ((void (*)(int)) 1)
+
+#define SIGINT      2
+#define SIGILL      4
+#define SIGABRT     6
+#define SIGFPE      8
+#define SIGSEGV    11
+#define SIGTERM    15
--- a/root/include/scc/bits/i386-sysv/arch/limits.h
+++ /dev/null
@@ -1,18 +1,0 @@
-#define CHAR_BIT   8
-#define SCHAR_MAX  0x7F
-#define SCHAR_MIN  (-SCHAR_MIN-1)
-#define CHAR_MAX   0x7F
-#define CHAR_MIN   (-CHAR_MAX-1)
-#define UCHAR_MAX  0xFF
-#define SHRT_MAX   0x7FFF
-#define SHRT_MIN   (-SHRT_MAX-1)
-#define USHRT_MAX  0xFFFF
-#define INT_MAX    0x7FFFFFFF
-#define INT_MIN    (-INT_MAX-1)
-#define UINT_MAX   0xFFFFFFFF
-#define LONG_MAX   0x7FFFFFFF
-#define LONG_MIN   (-LONG_MAX-1)
-#define ULONG_MAX  0xFFFFFFFF
-#define LLONG_MAX  0x7FFFFFFFFFFFFFFF
-#define LLONG_MIN  (-LLONG_MAX-1)
-#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- a/root/include/scc/bits/i386-sysv/arch/stddef.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/root/include/scc/bits/i386-sysv/arch/stdint.h
+++ /dev/null
@@ -1,115 +1,0 @@
-#define INT8_MAX  0x7F
-#define INT8_MIN  (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX  0x7FFF
-#define INT16_MIN  (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX  0x7FFFFFFF
-#define INT32_MIN  (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#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
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN  INT16_MIN
-#define INT_LEAST16_MAX  INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN  INT32_MIN
-#define INT_LEAST32_MAX  INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN  INT64_MIN
-#define INT_LEAST64_MAX  INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN  INT32_MIN
-#define INT_FAST8_MAX  INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN  INT32_MIN
-#define INT_FAST16_MAX  INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN  INT32_MIN
-#define INT_FAST32_MAX  INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN  INT64_MIN
-#define INT_FAST64_MAX  INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN  INT32_MIN
-#define INTPTR_MAX  INT32_MAX
-#define UINTPTR_MAX UINT32_MAX
-
-#define INTMAX_MIN  INT64_MIN
-#define INTMAX_MAX  INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT32_MIN
-#define PTRDIFF_MAX INT32_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT32_MAX
-
-#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 ## 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 ## LL
-#define UINTMAX_C(x) x ## ULL
-
-typedef signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long long uint64_t;
-
-typedef signed char int8_least_t;
-typedef short int16_least_t;
-typedef int int32_least_t;
-typedef long long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned short uint16_least_t;
-typedef unsigned uint32_least_t;
-typedef unsigned long long uint64_least_t;
-
-typedef int int8_fast_t;
-typedef int int16_fast_t;
-typedef int int32_fast_t;
-typedef long long int64_fast_t;
-
-typedef unsigned uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned uint32_fast_t;
-typedef unsigned long long uint64_fast_t;
-
-typedef int intptr_t;
-typedef unsigned uintptr_t;
-
-typedef long long intmax_t;
-typedef unsigned long long uintmax_t;
--- a/root/include/scc/bits/i386-sysv/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ        512
-#define FILENAME_MAX  256
-#define FOPEN_MAX      16
-
-#define TMP_MAX        25
-#define L_tmpnam      256
-
-#define _TMPNAME      "/tmp/tmp.0000000"
-
-typedef long fpos_t;
--- a/root/include/scc/bits/i386-sysv/arch/stdlib.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE long double
--- a/root/include/scc/bits/i386-sysv/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#endif
-
-#define __NUMCHARS 128
--- a/root/include/scc/bits/i386-sysv/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define _MAXYEAR 2037
-
-typedef long int time_t;
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/limits.h
@@ -1,0 +1,18 @@
+#define CHAR_BIT   8
+#define SCHAR_MAX  0x7F
+#define SCHAR_MIN  (-SCHAR_MIN-1)
+#define CHAR_MAX   0x7F
+#define CHAR_MIN   (-CHAR_MAX-1)
+#define UCHAR_MAX  0xFF
+#define SHRT_MAX   0x7FFF
+#define SHRT_MIN   (-SHRT_MAX-1)
+#define USHRT_MAX  0xFFFF
+#define INT_MAX    0x7FFFFFFF
+#define INT_MIN    (-INT_MAX-1)
+#define UINT_MAX   0xFFFFFFFF
+#define LONG_MAX   0x7FFFFFFF
+#define LONG_MIN   (-LONG_MAX-1)
+#define ULONG_MAX  0xFFFFFFFF
+#define LLONG_MAX  0x7FFFFFFFFFFFFFFF
+#define LLONG_MIN  (-LLONG_MAX-1)
+#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/stddef.h
@@ -1,0 +1,14 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#ifndef _PTRDIFF_T
+typedef long ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/stdint.h
@@ -1,0 +1,115 @@
+#define INT8_MAX  0x7F
+#define INT8_MIN  (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX  0x7FFF
+#define INT16_MIN  (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX  0x7FFFFFFF
+#define INT32_MIN  (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#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
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN  INT16_MIN
+#define INT_LEAST16_MAX  INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN  INT32_MIN
+#define INT_LEAST32_MAX  INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN  INT64_MIN
+#define INT_LEAST64_MAX  INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN  INT32_MIN
+#define INT_FAST8_MAX  INT32_MAX
+#define UINT_FAST8_MAX UINT32_MAX
+
+#define INT_FAST16_MIN  INT32_MIN
+#define INT_FAST16_MAX  INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN  INT32_MIN
+#define INT_FAST32_MAX  INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN  INT64_MIN
+#define INT_FAST64_MAX  INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN  INT32_MIN
+#define INTPTR_MAX  INT32_MAX
+#define UINTPTR_MAX UINT32_MAX
+
+#define INTMAX_MIN  INT64_MIN
+#define INTMAX_MAX  INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT32_MIN
+#define PTRDIFF_MAX INT32_MAX
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#define SIZE_MAX UINT32_MAX
+
+#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 ## 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 ## LL
+#define UINTMAX_C(x) x ## ULL
+
+typedef signed char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_least_t;
+typedef short int16_least_t;
+typedef int int32_least_t;
+typedef long long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned short uint16_least_t;
+typedef unsigned uint32_least_t;
+typedef unsigned long long uint64_least_t;
+
+typedef int int8_fast_t;
+typedef int int16_fast_t;
+typedef int int32_fast_t;
+typedef long long int64_fast_t;
+
+typedef unsigned uint8_fast_t;
+typedef unsigned uint16_fast_t;
+typedef unsigned uint32_fast_t;
+typedef unsigned long long uint64_fast_t;
+
+typedef int intptr_t;
+typedef unsigned uintptr_t;
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/stdio.h
@@ -1,0 +1,15 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ        512
+#define FILENAME_MAX  256
+#define FOPEN_MAX      16
+
+#define TMP_MAX        25
+#define L_tmpnam      256
+
+#define _TMPNAME      "/tmp/tmp.0000000"
+
+typedef long fpos_t;
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/stdlib.h
@@ -1,0 +1,14 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE long double
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/string.h
@@ -1,0 +1,5 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#endif
+
+#define __NUMCHARS 128
--- /dev/null
+++ b/root/include/scc/bits/i386/arch/time.h
@@ -1,0 +1,8 @@
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define _MAXYEAR 2037
+
+typedef long int time_t;
--- /dev/null
+++ b/root/include/scc/bits/linux/sys.h
@@ -1,0 +1,19 @@
+#define O_RDONLY  0x00000000
+#define O_WRONLY  0x00000001
+#define O_RDWR    0x00000002
+
+#define O_TRUNC   0x00000400
+#define O_APPEND  0x00000008
+#define O_CREAT   0x00000200
+
+typedef int pid_t;
+
+struct sigaction {
+	void (*sa_handler)(int);
+	int sa_mask;
+	int sa_flags;
+};
+
+extern pid_t _getpid(void);
+extern int _kill(pid_t pid, int signum);
+extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- /dev/null
+++ b/root/include/scc/bits/netbsd/sys.h
@@ -1,0 +1,19 @@
+#define O_RDONLY  0x00000000
+#define O_WRONLY  0x00000001
+#define O_RDWR    0x00000002
+
+#define O_TRUNC   0x00000400
+#define O_APPEND  0x00000008
+#define O_CREAT   0x00000200
+
+typedef int pid_t;
+
+struct sigaction {
+	void (*sa_handler)(int);
+	char sa_mask[8];
+	int sa_flags;
+};
+
+extern pid_t _getpid(void);
+extern int _kill(pid_t pid, int signum);
+extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- a/root/include/scc/bits/netbsd/sys/signal.h
+++ b/root/include/scc/bits/netbsd/sys/signal.h
@@ -4,24 +4,9 @@
 #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 SIGUSR1    10
 #define SIGSEGV    11
-#define SIGUSR2    12
-#define SIGPIPE    13
-#define SIGALRM    14
 #define SIGTERM    15
-#define SIGCHLD    17
-#define SIGCONT    18
-#define SIGSTOP    19
-#define SIGSSTP    20
-#define SIGTTIN    21
-#define SIGTTOU    22
-
-#define __NR_SIGNALS 23
--- /dev/null
+++ b/root/include/scc/bits/openbsd/sys.h
@@ -1,0 +1,19 @@
+#define O_RDONLY  0x00000000
+#define O_WRONLY  0x00000001
+#define O_RDWR    0x00000002
+
+#define O_TRUNC   0x00000400
+#define O_APPEND  0x00000008
+#define O_CREAT   0x00000200
+
+typedef int pid_t;
+
+struct sigaction {
+	void (*sa_handler)(int);
+	int sa_mask;
+	int sa_flags;
+};
+
+extern pid_t _getpid(void);
+extern int _kill(pid_t pid, int signum);
+extern int _sigaction(int sig, struct sigaction *new, struct sigaction *old);
--- a/root/include/scc/bits/openbsd/sys/signal.h
+++ b/root/include/scc/bits/openbsd/sys/signal.h
@@ -4,24 +4,9 @@
 #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 SIGUSR1    10
 #define SIGSEGV    11
-#define SIGUSR2    12
-#define SIGPIPE    13
-#define SIGALRM    14
 #define SIGTERM    15
-#define SIGCHLD    17
-#define SIGCONT    18
-#define SIGSTOP    19
-#define SIGSSTP    20
-#define SIGTTIN    21
-#define SIGTTOU    22
-
-#define __NR_SIGNALS 23
--- a/root/include/scc/bits/z80-dos/arch/limits.h
+++ /dev/null
@@ -1,18 +1,0 @@
-#define CHAR_BIT   8
-#define SCHAR_MAX  0x7F
-#define SCHAR_MIN  (-SCHAR_MIN-1)
-#define CHAR_MAX   0xFF
-#define CHAR_MIN   0
-#define UCHAR_MAX  0xFF
-#define SHRT_MAX   0x7FFF
-#define SHRT_MIN   (-SHRT_MAX-1)
-#define USHRT_MAX  0xFFFF
-#define INT_MAX    0x7FFF
-#define INT_MIN    (-INT_MAX-1)
-#define UINT_MAX   0xFFFF
-#define LONG_MAX   0x7FFFFFFF
-#define LONG_MIN   (-LONG_MAX-1)
-#define ULONG_MAX  0xFFFFFFFF
-#define LLONG_MAX  0x7FFFFFFFFFFFFFFF
-#define LLONG_MIN  (-LLONG_MAX-1)
-#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- a/root/include/scc/bits/z80-dos/arch/stddef.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef short wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef short ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/root/include/scc/bits/z80-dos/arch/stdint.h
+++ /dev/null
@@ -1,115 +1,0 @@
-#define INT8_MAX  0x7F
-#define INT8_MIN  (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX  0x7FFF
-#define INT16_MIN  (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX  0x7FFFFFFF
-#define INT32_MIN  (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#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
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN  INT16_MIN
-#define INT_LEAST16_MAX  INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN  INT32_MIN
-#define INT_LEAST32_MAX  INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN  INT64_MIN
-#define INT_LEAST64_MAX  INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN  INT16_MIN
-#define INT_FAST8_MAX  INT16_MAX
-#define UINT_FAST8_MAX UINT16_MAX
-
-#define INT_FAST16_MIN  INT16_MIN
-#define INT_FAST16_MAX  INT16_MAX
-#define UINT_FAST16_MAX UINT16_MAX
-
-#define INT_FAST32_MIN  INT32_MIN
-#define INT_FAST32_MAX  INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN  INT64_MIN
-#define INT_FAST64_MAX  INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN  INT16_MIN
-#define INTPTR_MAX  INT16_MAX
-#define UINTPTR_MAX UINT16_MAX
-
-#define INTMAX_MIN  INT64_MIN
-#define INTMAX_MAX  INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT16_MIN
-#define PTRDIFF_MAX INT16_MAX
-
-#define SIG_ATOMIC_MIN INT16_MIN
-#define SIG_ATOMIC_MAX INT16_MAX
-
-#define SIZE_MAX UINT64_MAX
-
-#define WCHAR_MIN INT16_MIN
-#define WCHAR_MAX INT16_MAX
-
-#define INT8_C(x)  x
-#define INT16_C(x) x
-#define INT32_C(x) x ## L
-#define INT64_C(x) x ## LL
-
-#define UINT8_C(x)  x
-#define UINT16_C(x) x ## U
-#define UINT32_C(x) x ## UL
-#define UINT64_C(x) x ## ULL
-
-#define INTMAX_C(x)  x ## LL
-#define UINTMAX_C(x) x ## ULL
-
-typedef signed char int8_t;
-typedef int int16_t;
-typedef long int32_t;
-typedef long long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned uint16_t;
-typedef unsigned long uint32_t;
-typedef unsigned long long uint64_t;
-
-typedef signed char int8_least_t;
-typedef int int16_least_t;
-typedef long int32_least_t;
-typedef long long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned uint16_least_t;
-typedef unsigned long uint32_least_t;
-typedef unsigned long long uint64_least_t;
-
-typedef signed char int8_fast_t;
-typedef int int16_fast_t;
-typedef long int32_fast_t;
-typedef long long int64_fast_t;
-
-typedef unsigned char uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned long uint32_fast_t;
-typedef unsigned long long uint64_fast_t;
-
-typedef int intptr_t;
-typedef unsigned uintptr_t;
-
-typedef long long intmax_t;
-typedef unsigned long long uintmax_t;
--- a/root/include/scc/bits/z80-dos/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ        512
-#define FILENAME_MAX  256
-#define FOPEN_MAX      16
-
-#define TMP_MAX        25
-#define L_tmpnam      256
-
-#define _TMPNAME      "TMP.000"
-
-typedef long fpos_t;
--- a/root/include/scc/bits/z80-dos/arch/stdlib.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef short wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE int
--- a/root/include/scc/bits/z80-dos/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#endif
-
-#define __NUMCHARS 128
--- a/root/include/scc/bits/z80-dos/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#define _MAXYEAR 2037
-
-typedef long time_t;
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/limits.h
@@ -1,0 +1,18 @@
+#define CHAR_BIT   8
+#define SCHAR_MAX  0x7F
+#define SCHAR_MIN  (-SCHAR_MIN-1)
+#define CHAR_MAX   0xFF
+#define CHAR_MIN   0
+#define UCHAR_MAX  0xFF
+#define SHRT_MAX   0x7FFF
+#define SHRT_MIN   (-SHRT_MAX-1)
+#define USHRT_MAX  0xFFFF
+#define INT_MAX    0x7FFF
+#define INT_MIN    (-INT_MAX-1)
+#define UINT_MAX   0xFFFF
+#define LONG_MAX   0x7FFFFFFF
+#define LONG_MIN   (-LONG_MAX-1)
+#define ULONG_MAX  0xFFFFFFFF
+#define LLONG_MAX  0x7FFFFFFFFFFFFFFF
+#define LLONG_MIN  (-LLONG_MAX-1)
+#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/stddef.h
@@ -1,0 +1,14 @@
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#ifndef _WCHAR_T
+typedef short wchar_t;
+#define _WCHAR_T
+#endif
+
+#ifndef _PTRDIFF_T
+typedef short ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/stdint.h
@@ -1,0 +1,115 @@
+#define INT8_MAX  0x7F
+#define INT8_MIN  (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX  0x7FFF
+#define INT16_MIN  (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX  0x7FFFFFFF
+#define INT32_MIN  (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#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
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN  INT16_MIN
+#define INT_LEAST16_MAX  INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN  INT32_MIN
+#define INT_LEAST32_MAX  INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN  INT64_MIN
+#define INT_LEAST64_MAX  INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN  INT16_MIN
+#define INT_FAST8_MAX  INT16_MAX
+#define UINT_FAST8_MAX UINT16_MAX
+
+#define INT_FAST16_MIN  INT16_MIN
+#define INT_FAST16_MAX  INT16_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+
+#define INT_FAST32_MIN  INT32_MIN
+#define INT_FAST32_MAX  INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN  INT64_MIN
+#define INT_FAST64_MAX  INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN  INT16_MIN
+#define INTPTR_MAX  INT16_MAX
+#define UINTPTR_MAX UINT16_MAX
+
+#define INTMAX_MIN  INT64_MIN
+#define INTMAX_MAX  INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT16_MIN
+#define PTRDIFF_MAX INT16_MAX
+
+#define SIG_ATOMIC_MIN INT16_MIN
+#define SIG_ATOMIC_MAX INT16_MAX
+
+#define SIZE_MAX UINT64_MAX
+
+#define WCHAR_MIN INT16_MIN
+#define WCHAR_MAX INT16_MAX
+
+#define INT8_C(x)  x
+#define INT16_C(x) x
+#define INT32_C(x) x ## L
+#define INT64_C(x) x ## LL
+
+#define UINT8_C(x)  x
+#define UINT16_C(x) x ## U
+#define UINT32_C(x) x ## UL
+#define UINT64_C(x) x ## ULL
+
+#define INTMAX_C(x)  x ## LL
+#define UINTMAX_C(x) x ## ULL
+
+typedef signed char int8_t;
+typedef int int16_t;
+typedef long int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned uint16_t;
+typedef unsigned long uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_least_t;
+typedef int int16_least_t;
+typedef long int32_least_t;
+typedef long long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned uint16_least_t;
+typedef unsigned long uint32_least_t;
+typedef unsigned long long uint64_least_t;
+
+typedef signed char int8_fast_t;
+typedef int int16_fast_t;
+typedef long int32_fast_t;
+typedef long long int64_fast_t;
+
+typedef unsigned char uint8_fast_t;
+typedef unsigned uint16_fast_t;
+typedef unsigned long uint32_fast_t;
+typedef unsigned long long uint64_fast_t;
+
+typedef int intptr_t;
+typedef unsigned uintptr_t;
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/stdio.h
@@ -1,0 +1,15 @@
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ        512
+#define FILENAME_MAX  256
+#define FOPEN_MAX      16
+
+#define TMP_MAX        25
+#define L_tmpnam      256
+
+#define _TMPNAME      "TMP.000"
+
+typedef long fpos_t;
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/stdlib.h
@@ -1,0 +1,14 @@
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef short wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE int
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/string.h
@@ -1,0 +1,5 @@
+#ifndef _SIZET
+typedef unsigned size_t;
+#endif
+
+#define __NUMCHARS 128
--- /dev/null
+++ b/root/include/scc/bits/z80/arch/time.h
@@ -1,0 +1,8 @@
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#define _MAXYEAR 2037
+
+typedef long time_t;
--- a/root/include/scc/ctype.h
+++ b/root/include/scc/ctype.h
@@ -16,7 +16,6 @@
 extern int tolower(int c);
 extern int toupper(int c);
 
-#ifdef __USE_MACROS
 
 #define _U	0x01	/* upper */
 #define _L	0x02	/* lower */
@@ -28,7 +27,6 @@
 #define _SP	0x80	/* hard space (0x20) */
 
 extern unsigned char __ctype[];
-extern int __ctmp;
 
 #define isalnum(c)  ((__ctype+1)[c] & (_U|_L|_D))
 #define isalpha(c)  ((__ctype+1)[c] & (_U|_L))
@@ -42,11 +40,6 @@
 #define isupper(c)  ((__ctype+1)[c] & (_U))
 #define isxdigit(c) ((__ctype+1)[c] & (_D|_X))
 
-#define tolower(c) ((__ctmp=c, isupper(__ctmp) ? __ctmp | 0x20 : __ctmp))
-#define toupper(c) ((__ctmp=c, islower(__ctmp) ? __ctmp & ~0x20 : __ctmp))
-
 #define isascii(c) ((unsigned)(c)<=0x7f)
-
-#endif
 
 #endif
--- a/root/include/scc/float.h
+++ /dev/null
@@ -1,4 +1,0 @@
-#ifndef _FLOAT_H
-#define _FLOAT_H
-#error not supported yet
-#endif
--- a/root/include/scc/stdio.h
+++ b/root/include/scc/stdio.h
@@ -110,11 +110,8 @@
 extern int __getc(FILE *fp);
 extern int __putc(int, FILE *fp);
 
-#ifdef __USE_MACROS
-#ifdef __UNIX_FILES
-#define getc(fp)     ((fp)->rp >= (fp)->wp ?  __getc(fp) : *(fp)->rp++)
-#define putc(c, fp)  ((fp)->wp >= (fp)->rp ? __putc(c,fp) : (*(fp)->wp++ = c))
-#endif
+#define getc(fp)            ((fp)->rp >= (fp)->wp ? __getc(fp) : *(fp)->rp++)
+#define putc(c, fp)         ((fp)->wp >= (fp)->rp ? __putc(c,fp) : (*(fp)->wp++ = c))
 
 #define ferror(fp)          ((fp)->flags & _IOERR)
 #define feof(fp)            ((fp)->flags & _IOEOF)
@@ -122,6 +119,5 @@
 #define getchar()           getc(stdin)
 #define putchar(c)          putc((c), stdout)
 #define setbuf(fp, b)       (void) setvbuf(fp, b, b ? _IOFBF:_IONBF, BUFSIZ)
-#endif
 
 #endif
--- a/root/include/scc/stdlib.h
+++ b/root/include/scc/stdlib.h
@@ -66,14 +66,4 @@
 extern size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
 extern size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
 
-#ifdef __USE_MACROS
-extern int __abs;
-extern long __labs;
-extern long long __llabs;
-
-#define abs(x)   (__abs = (x), (__abs) < 0 ? -__abs :  __abs)
-#define labs(x)  (__labs = (x), (__labs) < 0 ? -__labs :  __labs)
-#define llabs(x) (__llabs = (x), (__llabs) < 0 ? -__llabs :  __llabs)
-#endif
-
 #endif