shithub: scc

Download patch

ref: 197533c60f4f89dbe35912d241d7295603925f29
parent: fd277d39d846ec05a4940fd7f7f95333900db1c9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 27 07:44:57 EDT 2021

libc: Update stdlib to last version

This code is being updated out of the tree of scc and
it is time to synchroniza both copies now.

--- a/src/libc/libc.h
+++ b/src/libc/libc.h
@@ -28,7 +28,9 @@
 };
 
 extern void *_getheap(void);
+extern int _dtoi(char c);
 
+
 #ifdef stdin
 extern int _allocbuf(FILE *);
 extern int _flsbuf(FILE *);
@@ -51,3 +53,6 @@
 extern int _daysmon[12];
 extern char *_tzname[2];
 extern struct tzone tzones[];
+
+extern void (*_exitf[_ATEXIT_MAX])(void);
+extern unsigned _exitn;
--- /dev/null
+++ b/src/libc/stdlib/_Exit.c
@@ -1,0 +1,11 @@
+#include <stdlib.h>
+
+#include "../syscall.h"
+
+#undef _Exit
+
+void
+_Exit(int status)
+{
+	_exit(status);
+}
--- a/src/libc/stdlib/abort.c
+++ b/src/libc/stdlib/abort.c
@@ -1,5 +1,6 @@
 #include <signal.h>
 #include <stdlib.h>
+
 #undef abort
 
 void
--- a/src/libc/stdlib/atexit.c
+++ b/src/libc/stdlib/atexit.c
@@ -1,10 +1,8 @@
 #include <stdlib.h>
 #include <errno.h>
+
 #undef atexit
 
-extern void (*_exitf[_ATEXIT_MAX])(void);
-extern unsigned _exitn;
-
 int
 atexit(void (*fun)(void))
 {
@@ -12,6 +10,8 @@
 		errno = ENOMEM;
 		return -1;
 	}
+
 	_exitf[_exitn++] = fun;
+
 	return 0;
 }
--- a/src/libc/stdlib/errno.c
+++ b/src/libc/stdlib/errno.c
@@ -1,1 +1,3 @@
+#include <errno.h>
+
 int errno;
--- a/src/libc/stdlib/exit.c
+++ b/src/libc/stdlib/exit.c
@@ -1,4 +1,7 @@
 #include <stdlib.h>
+
+#include "../libc.h"
+
 #undef exit
 
 void (*_exitf[_ATEXIT_MAX])(void);
@@ -9,5 +12,6 @@
 {
 	while (_exitn > 0)
 		(*_exitf[--_exitn])();
+
 	_Exit(status);
 }
--- a/src/libc/stdlib/malloc.c
+++ b/src/libc/stdlib/malloc.c
@@ -7,6 +7,8 @@
 #include "../syscall.h"
 #include "../libc.h"
 
+#undef malloc
+
 #define MAXADDR ((char *)-1)
 #define ERRADDR ((char *)-1)
 
@@ -27,6 +29,7 @@
 		/* 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;
@@ -77,9 +80,11 @@
 
 	if (!heap)
 		heap = _getheap();
+
 	old = heap;
 	if (old >= MAXADDR - inc)
 		return ERRADDR;
+
 	new = old + inc;
 	p = _brk(new);
 	if (p == old || p == ERRADDR)
@@ -133,7 +138,7 @@
 	size_t nunits;
 
 	/* 1 unit for header plus enough units to fit nbytes */
-	nunits = (nbytes+sizeof(Header)-1) / sizeof(Header) + 1;
+	nunits = (nbytes+sizeof(Header)-1) / sizeof(Header)+1;
 
 	for (prev = freep; ; prev = cur) {
 		cur = prev->h.next;
--- a/src/libc/stdlib/malloc.h
+++ b/src/libc/stdlib/malloc.h
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-
 /* minimum amount of required units */
 #define NALLOC 16
 
@@ -13,4 +11,4 @@
 	_ALIGNTYPE most;
 };
 
-extern void *_prevchunk(Header *hp);
+extern void *_prevchunk(Header *);