From: John Hodge Date: Sun, 11 May 2014 07:00:05 +0000 (+0800) Subject: Usermode/libc - Fixes and additions from curl X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c9d40bdcf6d791c235b7d8e69646925d01e06506;p=tpg%2Facess2.git Usermode/libc - Fixes and additions from curl NOTE - The GCC cross-compiler applies fixincludes to stdio.h --- diff --git a/Usermode/Libraries/libc.so_src/ctype.c b/Usermode/Libraries/libc.so_src/ctype.c index d5a5e97a..18a199c6 100644 --- a/Usermode/Libraries/libc.so_src/ctype.c +++ b/Usermode/Libraries/libc.so_src/ctype.c @@ -22,23 +22,40 @@ int isalnum(int ch) { return isalpha(ch) || isdigit(ch); } -int toupper(int ch) { - if('a'<=ch && ch <='z') - return ch - 'a' + 'A'; - return ch; +int isxdigit(int ch) { + if('0'<=ch&&ch<='9') return 1; + if('a'<=ch&&ch<='f') return 1; + if('F'<=ch&&ch<='F') return 1; + return 0; } -int tolower(int ch) { - if('A'<=ch && ch <='Z') - return ch - 'A' + 'a'; - return ch; + +int isupper(int ch) { + if('A'<=ch && ch <='Z') return 1; + return 0; +} + +int islower(int ch) { + if('a'<=ch && ch <='z') return 1; + return 0; +} + +int ispunct(int ch) { + if( isprint(ch) && !isspace(ch) && !isalnum(ch) ) + return 1; + return 0; } int isprint(int ch ) { - if( ch < ' ' ) return 0; - if( ch > 'z' ) return 0; + if( ' ' <= ch && ch <= 'z' ) return 1; return 1; } +int isgraph(int ch) { + // Anything but space + if( ' ' < ch && ch <= 'z' ) return 1; + return 0; +} + int isspace(int ch) { if(ch == ' ') return 1; if(ch == '\t') return 1; @@ -47,12 +64,17 @@ int isspace(int ch) { return 0; } -int isxdigit(int ch) { - if('0'<=ch&&ch<='9') return 1; - if('a'<=ch&&ch<='f') return 1; - if('F'<=ch&&ch<='F') return 1; - return 0; +int toupper(int ch) { + if('a'<=ch && ch <='z') + return ch - 'a' + 'A'; + return ch; } +int tolower(int ch) { + if('A'<=ch && ch <='Z') + return ch - 'A' + 'a'; + return ch; +} + // C99 int isblank(int ch) { diff --git a/Usermode/Libraries/libc.so_src/errno.c b/Usermode/Libraries/libc.so_src/errno.c index d651ccc6..f5a142a8 100644 --- a/Usermode/Libraries/libc.so_src/errno.c +++ b/Usermode/Libraries/libc.so_src/errno.c @@ -51,7 +51,12 @@ EXPORT char *strerror(int errnum) case EFBIG: return "File too big"; case E2BIG: return "Value too big"; case EALREADY: return "Operation was no-op"; + case ENOSPC: return "No space left on the device"; + case EAFNOSUPPORT: return "Address family not supported"; + case EADDRINUSE: return "Address already in use"; + case ETIMEDOUT: return "Operation timed out"; + case EINTERNAL: return "Internal error"; } _SysDebug("strerror: errnum=%i unk", errnum); diff --git a/Usermode/Libraries/libc.so_src/include_exp/ctype.h b/Usermode/Libraries/libc.so_src/include_exp/ctype.h index 75e4ce88..69067e87 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/ctype.h +++ b/Usermode/Libraries/libc.so_src/include_exp/ctype.h @@ -14,21 +14,27 @@ extern "C" { extern int isalpha(int ch); extern int isdigit(int ch); - extern int isalnum(int ch); +extern int isxdigit(int ch); -extern int toupper(int ch); -extern int tolower(int ch); +extern int islower(int ch); +extern int isupper(int ch); +extern int ispunct(int ch); extern int isprint(int ch); +extern int isgraph(int ch); extern int isspace(int ch); -extern int isxdigit(int ch); +extern int iscntrl(int ch); // C99 extern int isblank(int ch); +// Conversions +extern int toupper(int ch); +extern int tolower(int ch); + #ifdef __cplusplus } #endif diff --git a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h index 5813cc56..be8c882a 100755 --- a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h +++ b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h @@ -30,12 +30,15 @@ enum libc_eErrorNumbers { EAGAIN, // Try again EALREADY, // Operation was a NOP + ENOSPC, // (POSIX) No space left on device EFBIG, // File too large E2BIG, // Argument list too large // psockets EAFNOSUPPORT, + EADDRINUSE, // Specified addres is already in use + ETIMEDOUT, EINTERNAL // Internal Error }; diff --git a/Usermode/Libraries/libc.so_src/include_exp/stdio.h b/Usermode/Libraries/libc.so_src/include_exp/stdio.h index ed1fce58..b2cb8574 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/stdio.h +++ b/Usermode/Libraries/libc.so_src/include_exp/stdio.h @@ -94,7 +94,7 @@ extern FILE *open_memstream(char **bufferptr, size_t *lengthptr); extern FILE *fdopen(int fd, const char *modes); extern FILE *tmpfile(void); extern int fclose(FILE *fp); -extern void fflush(FILE *fp); +extern int fflush(FILE *fp); extern off_t ftell(FILE *fp); extern off_t ftello(FILE *fp); extern int fseek(FILE *fp, long int amt, int whence); diff --git a/Usermode/Libraries/libc.so_src/include_exp/string.h b/Usermode/Libraries/libc.so_src/include_exp/string.h index 7ef1bc7a..028ed27e 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/string.h +++ b/Usermode/Libraries/libc.so_src/include_exp/string.h @@ -29,6 +29,7 @@ extern char *strrchr(const char *str, int character); extern char *strstr(const char *str1, const char *str2); extern size_t strcspn(const char *haystack, const char *reject); extern size_t strspn(const char *haystack, const char *accept); +extern char *strpbrk(const char *haystack, const char *accept); extern char *strtok(char *str, const char *delim); extern char *strtok_r(char *str, const char *delim, char **saveptr); diff --git a/Usermode/Libraries/libc.so_src/stdio.c b/Usermode/Libraries/libc.so_src/stdio.c index 1bb90cd9..7969f4c4 100644 --- a/Usermode/Libraries/libc.so_src/stdio.c +++ b/Usermode/Libraries/libc.so_src/stdio.c @@ -374,22 +374,23 @@ int _fflush_int(FILE *fp) return ret; } -EXPORT void fflush(FILE *fp) +EXPORT int fflush(FILE *fp) { if( !fp || fp->FD == FD_NOTOPEN ) - return ; + return EBADF; // Nothing to do for memory files if( fp->FD == FD_MEMFILE ) - return ; + return 0; // Memory streams, update pointers if( fp->FD == FD_MEMSTREAM ) { *fp->BufPtr = fp->Buffer; *fp->LenPtr = fp->BufferPos; - return ; + return 0; } _fflush_int(fp); + return 0; } EXPORT void clearerr(FILE *fp) diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index aa79ec96..0757c24a 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -369,6 +369,19 @@ EXPORT size_t strspn(const char *haystack, const char *accept) return ret; } +EXPORT char *strpbrk(const char *haystack, const char *accept) +{ + while( *haystack ) + { + for( int i = 0; accept[i]; i ++ ) + { + if( accept[i] == *haystack ) + return (char*)haystack; + } + } + return NULL; +} + char *strtok(char *str, const char *delim) { static char *__saveptr;