diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-01-30 18:35:35 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-01-30 18:35:35 -0500 |
commit | d5e1fa835e46dac2e1729e73c5e6743ef78714c7 (patch) | |
tree | 656a1c893b9930f444761c2811b1fc57fccd6802 | |
parent | 7cdd27f8dce39bed37a266fa578cfaedce0a015d (diff) |
fix to compile under c89
-rw-r--r-- | src/__checked_i.c | 63 | ||||
-rw-r--r-- | src/locale/__load_locale.c | 2 | ||||
-rw-r--r-- | src/signal/raise.c | 2 | ||||
-rw-r--r-- | src/stdio/__printf.c | 7 | ||||
-rw-r--r-- | src/stdio/fflush.c | 2 | ||||
-rw-r--r-- | src/stdio/freopen.c | 7 | ||||
-rw-r--r-- | src/stdio/remove.c | 14 | ||||
-rw-r--r-- | src/stdlib/realloc.c | 2 | ||||
-rw-r--r-- | src/string/strcpy.c | 2 |
9 files changed, 60 insertions, 41 deletions
diff --git a/src/__checked_i.c b/src/__checked_i.c index c97a9b4d..e7e92919 100644 --- a/src/__checked_i.c +++ b/src/__checked_i.c @@ -1,24 +1,33 @@ #undef __UNG_INTERNAL__ #include <ctype.h> -#include <complex.h> // TODO -#include <fenv.h> -#include <inttypes.h> #include <locale.h> -#include <math.h> // TODO +#include <math.h> /* TODO */ #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdio.h> -#include <stdlib.h> // TODO +#include <stdlib.h> /* TODO */ #include <string.h> -#include <threads.h> // TODO -#include <time.h> // TODO -#include <uchar.h> // TODO -//#include <wchar.h> // TODO -#include <wctype.h> // TODO +#include <time.h> /* TODO */ + +#if __STDC_VERSION__ >= 199409L +#include <wchar.h> /* TODO */ +#include <wctype.h> /* TODO */ +#endif + +#if __STDC_VERSION__ >= 199901L +#include <complex.h> /* TODO */ +#include <fenv.h> +#include <inttypes.h> +#endif + +#if __STDC_VERSION__ >= 201112 +#include <threads.h> /* TODO */ +#include <uchar.h> /* TODO */ +#endif -#include "_assert.h" +#include "_safety.h" extern char *(gets)(char*); @@ -41,16 +50,19 @@ int __checked_i(const char *file, const char *func, unsigned long long line, int || fn == F(islower) || fn == F(toupper) || fn == F(tolower) + /* || fn == F(feclearexcept) || fn == F(feraiseexcept) || fn == F(fesetround) || fn == F(fetestexcept) + */ || fn == F(raise) || fn == F(putchar) || fn == F(abs) ) { int arg = va_arg(ap, int); ret = fn(arg); + /* } else if (fn == F(fegetenv) || fn == F(feholdexcept) || fn == F(fesetenv) @@ -64,8 +76,9 @@ int __checked_i(const char *file, const char *func, unsigned long long line, int fexcept_t *fe = va_arg(ap, fexcept_t *); int i = va_arg(ap, int); ret = fn(fe, i); - } else if (fn == F(fegetround) - || fn == F(getchar) + */ + } else if (/*fn == F(fegetround) + || */fn == F(getchar) ) { ret = fn(); } else if (fn == F(fclose) @@ -73,7 +86,7 @@ int __checked_i(const char *file, const char *func, unsigned long long line, int || fn == F(ferror) || fn == F(fflush) || fn == F(fgetc) - || fn == F(getc) + /* || fn == F(getc) */ ) { FILE *f = va_arg(ap, FILE *); ret = fn(f); @@ -127,12 +140,14 @@ int __checked_i(const char *file, const char *func, unsigned long long line, int const char *p2 = va_arg(ap, const char *); size_t n = va_arg(ap, size_t); ret = fn(p1, p2, n); + /* } else if (fn == F(atexit)) { void *p = va_arg(ap, void *); ret = fn(p); + */ } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -148,6 +163,7 @@ int __checked_i(const char *file, const char *func, unsigned long long line, int STDC(0) */ +#if __STDC_VERSION__ >= 199901L #undef F #define F(fn) (intmax_t(*)())(fn) intmax_t __checked_im(const char *file, const char *func, unsigned long long line, intmax_t (*fn)(), ...) @@ -180,7 +196,7 @@ intmax_t __checked_im(const char *file, const char *func, unsigned long long lin ret = fn(s1, s2); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -216,7 +232,7 @@ uintmax_t __checked_uim(const char *file, const char *func, unsigned long long l ret = fn(s, end, i); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -246,7 +262,7 @@ imaxdiv_t __checked_imd(const char *file, const char *func, unsigned long long l ret = fn(n, d); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -256,6 +272,7 @@ imaxdiv_t __checked_imd(const char *file, const char *func, unsigned long long l return ret; } +#endif #undef F #define F(fn) (void *(*)())(fn) @@ -299,7 +316,7 @@ void *__checked_p(const char *file, const char *func, unsigned long long line, v FILE *f = va_arg(ap, FILE *); ret = fn(name, mode, f); } else if (fn == F(tmpnam) - || fn == F(gets) + /* || fn == F(gets) */ ) { char *s = va_arg(ap, char *); ret = fn(s); @@ -343,7 +360,7 @@ void *__checked_p(const char *file, const char *func, unsigned long long line, v ret = fn(s1, s2); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -382,7 +399,7 @@ void __checked(const char *file, const char *func, unsigned long long line, void fn(); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -426,7 +443,7 @@ size_t __checked_s(const char *file, const char *func, unsigned long long line, ret = fn(s1, s2, n); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); @@ -455,7 +472,7 @@ long __checked_l(const char *file, const char *func, unsigned long long line, lo ret = fn(f); } else { (fprintf)(stderr, "Unwrapped function %s\n", func); - (_Exit(1)); + (abort()); } va_end(ap); diff --git a/src/locale/__load_locale.c b/src/locale/__load_locale.c index 0f6bd496..89fbd8a9 100644 --- a/src/locale/__load_locale.c +++ b/src/locale/__load_locale.c @@ -25,7 +25,7 @@ char * __load_locale(struct __locale_t *loc, int mask, const char *name) char localepath[FILENAME_MAX] = "/lib/locale/"; strcat(localepath, name); - FILE *localefile = NULL; //fopen(localepath, "rb"); + FILE *localefile = fopen(localepath, "rb"); if (localefile == NULL && strcmp(name, "C") && strcmp(name, "POSIX")) { return NULL; } diff --git a/src/signal/raise.c b/src/signal/raise.c index c4fd9649..f841b4a2 100644 --- a/src/signal/raise.c +++ b/src/signal/raise.c @@ -3,9 +3,7 @@ #define POSIX_FORCED #endif -//#include <sys/types.h> #include <signal.h> -//#include <unistd.h> #ifdef POSIX_FORCED #include "_syscall.h" diff --git a/src/stdio/__printf.c b/src/stdio/__printf.c index 0d950583..391f7cbc 100644 --- a/src/stdio/__printf.c +++ b/src/stdio/__printf.c @@ -1,15 +1,18 @@ +#if 0 //#include <sys/types.h> +//#include <unistd.h> +#endif + #include <stdio.h> #include <stddef.h> #include "wctype/wint_t.h" #include "wctype/wctrans_t.h" #include <wchar.h> #include <inttypes.h> -//#include <unistd.h> #include <stdlib.h> #include "_stdio.h" -#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199909L +#if (!defined __STDC_VERSION__) || (__STDC_VERSION__ < 199909L) #include "stdint/intmax_t.h" #include "stdint/uintmax_t.h" #include "stdint/intptr_t.h" diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c index 23899e82..e13f8979 100644 --- a/src/stdio/fflush.c +++ b/src/stdio/fflush.c @@ -4,8 +4,6 @@ #endif #include <stdio.h> -//#include <sys/types.h> -//#include <unistd.h> #include "_stdio.h" #ifdef POSIX_FORCED diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c index b39fda4c..b40eb439 100644 --- a/src/stdio/freopen.c +++ b/src/stdio/freopen.c @@ -3,19 +3,16 @@ #define POSIX_FORCED #endif -//#include <sys/types.h> #include <errno.h> -//#include <fcntl.h> #include <stdio.h> #include <string.h> -//#include <unistd.h> #include "_stdio.h" #ifdef POSIX_FORCED -#include "termios/_termios.h" #include "_syscall.h" #define open(_p, _f, _m) __scall3(open, _p, _f, _m) -#define isatty(_fd) ioctl(_fd, TCFLSH, 0) +#define isatty(_fd) (-1) /*ioctl(_fd, TCFLSH, 0) */ +#define TCFLSH 0x540B #define O_RDONLY 00 #define O_WRONLY 01 #define O_CREAT 0100 diff --git a/src/stdio/remove.c b/src/stdio/remove.c index 2ac91743..8b6c5925 100644 --- a/src/stdio/remove.c +++ b/src/stdio/remove.c @@ -1,13 +1,16 @@ -#if 0 #ifndef _POSIX_SOURCE #define _POSIX_SOURCE #define POSIX_FORCED #endif #include <stdio.h> +#include "_stdio.h" + +#if 0 #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> +#endif #ifdef POSIX_FORCED #include "_syscall.h" @@ -20,15 +23,20 @@ int remove(const char *filename) { - struct stat st; + /* struct stat st; */ SIGNAL_SAFE(0); + /* stat(filename, &st); if (S_ISDIR(st.st_mode)) { return rmdir(filename); } return unlink(filename); + */ + + (void)filename; + return -1; } /*** @@ -40,5 +48,3 @@ open that file will fail unless creating a new file. IMPLEMENTATION(Whether the file is removed if it is open) STDC(1) */ - -#endif diff --git a/src/stdlib/realloc.c b/src/stdlib/realloc.c index 982d01ac..e02ad89a 100644 --- a/src/stdlib/realloc.c +++ b/src/stdlib/realloc.c @@ -6,9 +6,11 @@ #include <stdlib.h> #include "_stdlib.h" +#if 0 //#include <sys/types.h> //#include <fcntl.h> //#include <sys/mman.h> +#endif #ifdef POSIX_FORCED #include "_syscall.h" diff --git a/src/string/strcpy.c b/src/string/strcpy.c index a7785c27..1f80e41b 100644 --- a/src/string/strcpy.c +++ b/src/string/strcpy.c @@ -2,8 +2,6 @@ #include "_safety.h" #undef strcpy -#undef strcpy - /** copy string **/ char * strcpy(char * restrict s1, const char * restrict s2) |