From 5baf31fcd4ec90827f62f7fbded545fda85ecdbb Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 22 Jul 2013 20:08:01 +0800 Subject: [PATCH] Usermode/libc - Fixing errors from clang, disabled heap for native build --- Usermode/Libraries/libc.so_src/Makefile | 2 +- Usermode/Libraries/libc.so_src/errno.c | 14 +++++++++++++- Usermode/Libraries/libc.so_src/include_exp/errno.h | 5 +++-- .../Libraries/libc.so_src/include_exp/stdlib.h | 6 ++++++ Usermode/Libraries/libc.so_src/printf.c | 6 ------ Usermode/Libraries/libc.so_src/scanf.c | 11 ++++++----- Usermode/Libraries/libc.so_src/string.c | 4 ++-- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index 1414b1cc..c8f4e5d3 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -18,7 +18,7 @@ OBJ += arch/$(ARCHDIR).ao DEPFILES := $(OBJ:%.o=%.d) BIN = libc.so ifeq ($(ARCHDIR),native) - #OBJ := $(filter-out heap.o,$(OBJ)) + OBJ := $(filter-out heap.o,$(OBJ)) #LDFLAGS += -l c BIN = libc_acess.so endif diff --git a/Usermode/Libraries/libc.so_src/errno.c b/Usermode/Libraries/libc.so_src/errno.c index f1c3c4d1..b5fe9587 100644 --- a/Usermode/Libraries/libc.so_src/errno.c +++ b/Usermode/Libraries/libc.so_src/errno.c @@ -8,13 +8,14 @@ #include "lib.h" #include #include +#include EXPORT int *libc_geterrno() { return &_errno; } -EXPORT const char *strerror(int errnum) +EXPORT char *strerror(int errnum) { switch(errnum) { @@ -27,7 +28,18 @@ EXPORT const char *strerror(int errnum) case EPERM: return "Permissions error"; default: _SysDebug("strerror: errnum=%i unk", errnum); + errno = EINVAL; return "unknown error"; } } +EXPORT int strerror_r(int errnum, char *buf, size_t bufsiz) +{ + const char *str = strerror(errnum); + if(!str) + return -1; + + strncpy(buf, str, bufsiz); + return 0; +} + diff --git a/Usermode/Libraries/libc.so_src/include_exp/errno.h b/Usermode/Libraries/libc.so_src/include_exp/errno.h index a808379b..f06706ff 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/errno.h +++ b/Usermode/Libraries/libc.so_src/include_exp/errno.h @@ -8,12 +8,13 @@ #ifndef _LIBC_ERRNO_H_ #define _LIBC_ERRNO_H_ -// TODO: Fully implement errno.h, make sure it matches the kernel one +#include // size_t extern int *libc_geterrno(void); #define errno (*libc_geterrno()) -extern const char *strerror(int errnum); +extern int strerror_r(int errnum, char *buf, size_t buflen); +extern char *strerror(int errnum); #include "errno.enum.h" diff --git a/Usermode/Libraries/libc.so_src/include_exp/stdlib.h b/Usermode/Libraries/libc.so_src/include_exp/stdlib.h index f692dddb..bbf76eba 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/stdlib.h +++ b/Usermode/Libraries/libc.so_src/include_exp/stdlib.h @@ -37,6 +37,12 @@ # define bsearch acess_bsearch # define qsort acess_qsort +# define free acess_free +# define malloc acess_malloc +# define calloc acess_calloc +# define realloc acess_realloc +# define IsHeap acess_IsHeap + # define srand acess_srand # define rand acess_rand # define rand_p acess_rand_p diff --git a/Usermode/Libraries/libc.so_src/printf.c b/Usermode/Libraries/libc.so_src/printf.c index 2568ae82..905f790b 100644 --- a/Usermode/Libraries/libc.so_src/printf.c +++ b/Usermode/Libraries/libc.so_src/printf.c @@ -44,7 +44,6 @@ size_t _printf_ftoa(printf_puts_t puts_cb, void *puts_h, long double num, size_t */ EXPORT int _vcprintf_int(printf_puts_t puts_cb, void *puts_h, const char *format, va_list args) { - char tmp[65]; int c, minSize, precision, len; size_t pos = 0; char *p; @@ -60,8 +59,6 @@ EXPORT int _vcprintf_int(printf_puts_t puts_cb, void *puts_h, const char *format pos ++; \ } while(0) - tmp[32] = '\0'; - while((c = *format++) != 0) { // Non-control character @@ -165,9 +162,6 @@ EXPORT int _vcprintf_int(printf_puts_t puts_cb, void *puts_h, const char *format } } - // Just help things along later - p = tmp; - // Get Type switch( c ) { diff --git a/Usermode/Libraries/libc.so_src/scanf.c b/Usermode/Libraries/libc.so_src/scanf.c index 3d45ed13..6fff1764 100644 --- a/Usermode/Libraries/libc.so_src/scanf.c +++ b/Usermode/Libraries/libc.so_src/scanf.c @@ -326,11 +326,11 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char valtype = _VCSCANF_NOTYPE; break; // match a set of characters - case '[': - fch = *format++; - if( fch == '^' ) { + case '[': { + int invert = 0; + if( *format++ == '^' ) { // Invert - fch = *format; + invert = 1; } set_start = format; set_len = 0; @@ -344,7 +344,7 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char if( maxlen == 0 ) maxlen = -1; ich = 0; - while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) ) + while( maxlen -- && (ich = __getc(h)) && invert == !memchr(set_start, set_len, ich) ) { if(ptr._char) *ptr._char++ = ich; nch ++; @@ -354,6 +354,7 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char if(ptr._char) *ptr._char++ = 0; valtype = _VCSCANF_NOTYPE; break; + } case 'p': // read back printf("%p") valtype = _VCSCANF_NOTYPE; break; diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index 3d30f1c6..2ab271f5 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -200,13 +200,13 @@ EXPORT char *strrchr(const char *str, int character) * \fn EXPORT char *strstr(char *str1, const char *str2) * \brief Search a \a str1 for the first occurance of \a str2 */ -EXPORT char *strstr(char *str1, const char *str2) +EXPORT char *strstr(const char *str1, const char *str2) { const char *test = str2; for(;*str1;str1++) { - if(*test == '\0') return str1; + if(*test == '\0') return (char*)str1; if(*str1 == *test) test++; else test = str2; } -- 2.20.1