diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 38fba6bb3..3427826e6 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -44,7 +44,7 @@ for _, plat in ipairs(vars.plats) do "./core/ctype/*.c", "./core/misc/*.c", "./sys/malloc/*.c", - "./signal/*.c", + "./sys/exit/*.c", "./assert/*.c", "./stdio/*.c", "./stdlib/*.c", diff --git a/lang/cem/libcc.ansi/stdlib/abort.c b/lang/cem/libcc.ansi/core/misc/abort.c similarity index 70% rename from lang/cem/libcc.ansi/stdlib/abort.c rename to lang/cem/libcc.ansi/core/misc/abort.c index afad36bf9..d59624169 100644 --- a/lang/cem/libcc.ansi/stdlib/abort.c +++ b/lang/cem/libcc.ansi/core/misc/abort.c @@ -4,17 +4,11 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) -#include -#endif -#include #include - -extern void (*_clean)(void); +#include +#include void abort(void) { - if (_clean) - _clean(); /* flush all output files */ raise(SIGABRT); } diff --git a/lang/cem/libcc.ansi/signal/raise.c b/lang/cem/libcc.ansi/core/misc/raise.c similarity index 85% rename from lang/cem/libcc.ansi/signal/raise.c rename to lang/cem/libcc.ansi/core/misc/raise.c index e1aedaa01..e50193136 100644 --- a/lang/cem/libcc.ansi/signal/raise.c +++ b/lang/cem/libcc.ansi/core/misc/raise.c @@ -4,14 +4,17 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) +#include #include -#endif #include +#if ACKCONF_WANT_EMULATED_RAISE + int raise(int sig) { if (sig < 0 || sig > _NSIG) return -1; return kill(getpid(), sig); } + +#endif diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index ae397dbfe..593767d4c 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -24,4 +24,14 @@ #define ACKCONF_WANT_TERMIOS 0 #endif +#ifndef ACKCONF_WANT_EMULATED_RAISE +/* Implement raise() in terms of kill() and getpid(). */ +#define ACKCONF_WANT_EMULATED_RAISE 1 +#endif + +#ifndef ACKCONF_WANT_MALLOC +/* Uses sbrk() to get memory from the system. */ +#define ACKCONF_WANT_MALLOC 1 +#endif + #endif diff --git a/lang/cem/libcc.ansi/signal/LIST b/lang/cem/libcc.ansi/signal/LIST deleted file mode 100644 index ff77f128d..000000000 --- a/lang/cem/libcc.ansi/signal/LIST +++ /dev/null @@ -1 +0,0 @@ -raise.c diff --git a/lang/cem/libcc.ansi/signal/Makefile b/lang/cem/libcc.ansi/signal/Makefile deleted file mode 100644 index c9578ae90..000000000 --- a/lang/cem/libcc.ansi/signal/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -f raise.o OLIST diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/stdio/fflush.c index f5ef6c355..24baa6e70 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/stdio/fflush.c @@ -68,7 +68,7 @@ int fflush(FILE* stream) return EOF; } -void __cleanup(void) +static void cleanup(void) { register int i; @@ -76,3 +76,13 @@ void __cleanup(void) if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING)) (void)fflush(__iotab[i]); } + +void __register_stdio_cleanup(void) +{ + static char registered = 0; + if (!registered) + { + registered = 1; + atexit(cleanup); + } +} diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/stdio/flushbuf.c index 9518de70d..976d82a89 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/stdio/flushbuf.c @@ -8,8 +8,6 @@ #include #include "loc_incl.h" -extern void (*_clean)(void); - static int do_write(int d, char* buf, int nbytes) { @@ -28,7 +26,7 @@ do_write(int d, char* buf, int nbytes) int __flushbuf(int c, FILE* stream) { - _clean = __cleanup; + __register_stdio_cleanup(); if (fileno(stream) < 0) return EOF; if (!io_testflag(stream, _IOWRITE)) diff --git a/lang/cem/libcc.ansi/stdio/loc_incl.h b/lang/cem/libcc.ansi/stdio/loc_incl.h index 52488e0c9..b30d3272a 100644 --- a/lang/cem/libcc.ansi/stdio/loc_incl.h +++ b/lang/cem/libcc.ansi/stdio/loc_incl.h @@ -14,7 +14,8 @@ int _doprnt(const char *format, va_list ap, FILE *stream); int _doscan(FILE * stream, const char *format, va_list ap); char *_i_compute(unsigned long val, int base, char *s, int nrdigits); char *_f_print(va_list *ap, int flags, char *s, char c, int precision); -void __cleanup(void); + +extern void __register_stdio_cleanup(void); FILE *popen(const char *command, const char *type); FILE *fdopen(int fd, const char *mode); diff --git a/lang/cem/libcc.ansi/stdio/setvbuf.c b/lang/cem/libcc.ansi/stdio/setvbuf.c index b7571ccc6..4650db03d 100644 --- a/lang/cem/libcc.ansi/stdio/setvbuf.c +++ b/lang/cem/libcc.ansi/stdio/setvbuf.c @@ -13,7 +13,7 @@ int setvbuf(register FILE* stream, char* buf, int mode, size_t size) { int retval = 0; - _clean = __cleanup; + __register_stdio_cleanup(); if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) return EOF; diff --git a/lang/cem/libcc.ansi/stdlib/atexit.c b/lang/cem/libcc.ansi/sys/exit/atexit.c similarity index 64% rename from lang/cem/libcc.ansi/stdlib/atexit.c rename to lang/cem/libcc.ansi/sys/exit/atexit.c index c9dc7964a..2cb16da9f 100644 --- a/lang/cem/libcc.ansi/stdlib/atexit.c +++ b/lang/cem/libcc.ansi/sys/exit/atexit.c @@ -1,11 +1,7 @@ /* $Id$ */ #include - -#define NEXITS 32 - -extern void (*__functab[NEXITS])(void); -extern int __funccnt; +#include "atexits.h" int atexit(void (*func)(void)) { diff --git a/lang/cem/libcc.ansi/sys/exit/atexits.h b/lang/cem/libcc.ansi/sys/exit/atexits.h new file mode 100644 index 000000000..3cca599c5 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/exit/atexits.h @@ -0,0 +1,9 @@ +#ifndef ATEXITS_H +#define ATEXITS_H + +#define NEXITS 32 + +extern void (*__functab[NEXITS])(void); +extern int __funccnt; + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/exit.c b/lang/cem/libcc.ansi/sys/exit/exit.c similarity index 62% rename from lang/cem/libcc.ansi/stdlib/exit.c rename to lang/cem/libcc.ansi/sys/exit/exit.c index ef8976bc0..7f861321f 100644 --- a/lang/cem/libcc.ansi/stdlib/exit.c +++ b/lang/cem/libcc.ansi/sys/exit/exit.c @@ -7,29 +7,16 @@ #include #include #include - -#define NEXITS 32 +#include "atexits.h" void (*__functab[NEXITS])(void); int __funccnt = 0; -/* only flush output buffers when necessary */ -int (*_clean)(void) = NULL; - -static void -_calls(void) -{ - register int i = __funccnt; - - /* "Called in reversed order of their registration" */ - while (--i >= 0) - (*__functab[i])(); -} - void exit(int status) { - _calls(); - if (_clean) - _clean(); + /* "Called in reversed order of their registration" */ + while (__funccnt >= 0) + (*__functab[__funccnt])(); + _exit(status); }