diff --git a/include/ctype.h b/include/ctype.h index c533f244..027abdba 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -29,9 +29,11 @@ #else // ! WITH_GLIBC #include -int isdigit (int); -int isxdigit (int); -int isspace (int); +int isalpha (int c); +int isascii (int c); +int isdigit (int c); +int isxdigit (int c); +int isspace (int c); #endif // ! WITH_GLIBC #endif // __MES_CTYPE_H diff --git a/include/limits.h b/include/limits.h index 2f55cd28..0a33da16 100644 --- a/include/limits.h +++ b/include/limits.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -28,6 +28,7 @@ #include_next #else // ! WITH_GLIBC + #define CHAR_BIT 8 #define UCHAR_MAX 255 #define INT_MIN -2147483648 @@ -35,7 +36,7 @@ #define MB_CUR_MAX 1 #define LONG_MIN -2147483648 #define LONG_MAX 2147483647 -#define LONG_MAX _POSIX_OPEN_MAX 16 +#define _POSIX_OPEN_MAX 16 #endif // ! WITH_GLIBC diff --git a/include/stdint.h b/include/stdint.h index eb774d6c..ca6f4573 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -63,13 +63,22 @@ typedef long long int64_t; typedef unsigned long size_t; #endif +#ifndef __MES_INTPTR_T +#define __MES_INTPTR_T +#undef intptr_t +typedef long intptr_t; +#endif + // FIXME typedef int intmax_t; typedef unsigned uintmax_t; -typedef int* intptr_t; typedef unsigned* uintptr_t; -typedef unsigned ptrdiff_t; +#ifndef __MES_PTRDIFF_T +#define __MES_PTRDIFF_T +#undef ptrdiff_t +typedef long ptrdiff_t; +#endif #endif // ! WITH_GLIBC diff --git a/include/stdlib.h b/include/stdlib.h index c683902c..5e2078a9 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -54,9 +54,17 @@ unsigned long long strtoull (char const *nptr, char **endptr, int base); #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 + +#if __MESC__ +typedef int (*comparison_fn_t) (void const *, void const *); +#else +typedef void (*comparison_fn_t) (); +#endif + +void * bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare); + #include #endif // ! WITH_GLIBC #endif // __MES_STDLIB_H - diff --git a/include/time.h b/include/time.h index be948d12..c7ab8a2f 100644 --- a/include/time.h +++ b/include/time.h @@ -43,6 +43,8 @@ struct tm { }; struct tm *localtime (time_t const *timep); +struct tm *gmtime (time_t const *time); + time_t time (time_t *tloc); #ifndef __MES_STRUCT_TIMESPEC diff --git a/include/unistd.h b/include/unistd.h index 511adee4..a555146c 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -33,6 +33,12 @@ #define NULL 0 #endif +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +#endif // STDIN_FILENO + #ifndef __MES_OFF_T #define __MES_OFF_T #undef off_t @@ -51,6 +57,18 @@ typedef unsigned long size_t; typedef long ssize_t; #endif +#ifndef __MES_INTPTR_T +#define __MES_INTPTR_T +#undef intptr_t +typedef long intptr_t; +#endif + +#ifndef __MES_PTRDIFF_T +#define __MES_PTRDIFF_T +#undef ptrdiff_t +typedef long ptrdiff_t; +#endif + #ifndef R_OK #define F_OK 0 #define X_OK 1 @@ -72,6 +90,12 @@ char *getcwd (char *buf, size_t size); int isatty (int fd); off_t lseek (int fd, off_t offset, int whence); ssize_t read (int fd, void *buffer, size_t size); +#if __SBRK_CHAR_PTRDIFF +/* xmalloc in binutils <= 2.10.1 uses this old prototype */ +char * sbrk (ptrdiff_t delta); +#else +void * sbrk (intptr_t delta); +#endif int unlink (char const *file_name); ssize_t write (int filedes, void const *buffer, size_t size); #endif // ! WITH_GLIBC diff --git a/lib/binutils.c b/lib/binutils.c index 393d0bf7..f8addd18 100644 --- a/lib/binutils.c +++ b/lib/binutils.c @@ -20,6 +20,7 @@ #include #include +#include int abs (int x) @@ -117,15 +118,6 @@ perror (char const *message) fprintf (stderr, "%s: %s\n", strerror (errno), message); } -void* -sbrk (ptrdiff_t delta) -{ - void *p = malloc (delta); - if (p <= 0) - return 0; - return p+delta; -} - int setitimer (int which, struct itimerval const *new, struct itimerval *old) @@ -209,3 +201,48 @@ utime (int x) eputs ("utime stub\n"); return 0; } + +// binutils-2.10.1 +int +fscanf (FILE *stream, char const *template, ...) +{ + eputs ("fscan stub\n"); + return 0; +} + +int +isascii (int c) +{ + return c >= 0 && c <= 127; +} + +void * +#if __MESC__ +bsearch (void const *key, void const *array, size_t count, size_t size, void (*compare) ()) +#else +bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare) +#endif +{ + eputs ("bsearch stub\n"); + return 0; +} + +struct tm * +gmtime (time_t const *time) +{ + eputs ("gmtime stub\n"); + return localtime (time); +} + +#if __SBRK_CHAR_PTRDIFF +char * +sbrk (ptrdiff_t) +#else +void * +sbrk (intptr_t delta) +#endif +{ + if (delta >= 0) + return malloc (delta); + return g_brk; +} diff --git a/lib/libg.c b/lib/libg.c index ee463cad..bf511f03 100644 --- a/lib/libg.c +++ b/lib/libg.c @@ -48,3 +48,24 @@ __cleanup () eputs ("__cleanup stub\n"); return 0; } + +int +__libc_subinit () +{ + eputs ("__libc_subinit stub\n"); + return 0; +} + +int +__syscall_error () +{ + eputs ("__syscall_error stub\n"); + return 0; +} + +int +__fpu_control () +{ + eputs ("__fpu_control stub\n"); + return 0; +}