From 0eb50bc9e604f654bdb0409bb66da03b733f906c Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Tue, 16 Oct 2012 14:46:04 +0800 Subject: [PATCH] Usermode/libc - scanf() and many other cleanups --- Usermode/Libraries/libc.so_src/Makefile | 2 +- Usermode/Libraries/libc.so_src/fileIO.c | 251 ++++++++---- Usermode/Libraries/libc.so_src/heap.c | 4 +- .../Libraries/libc.so_src/include_exp/ctype.h | 6 + Usermode/Libraries/libc.so_src/lib.h | 2 + Usermode/Libraries/libc.so_src/scanf.c | 386 +++++++++++++++++- Usermode/Libraries/libc.so_src/stdio_int.h | 35 +- Usermode/Libraries/libc.so_src/stdlib.c | 2 +- Usermode/Libraries/libc.so_src/string.c | 2 +- Usermode/Libraries/libc.so_src/stub.c | 2 +- 10 files changed, 595 insertions(+), 97 deletions(-) diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index defdb58a..3dfe1fb9 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -4,7 +4,7 @@ -include ../Makefile.cfg CPPFLAGS += -CFLAGS += +CFLAGS += -Werror -Wextra ASFLAGS += LDFLAGS += -soname libc.so -Map map.txt -lgcc diff --git a/Usermode/Libraries/libc.so_src/fileIO.c b/Usermode/Libraries/libc.so_src/fileIO.c index c0013c98..af8f0072 100644 --- a/Usermode/Libraries/libc.so_src/fileIO.c +++ b/Usermode/Libraries/libc.so_src/fileIO.c @@ -30,56 +30,80 @@ struct sFILE *stderr; // Standard Error ///\note Initialised in SoMain // === CODE === +int _fopen_modetoflags(const char *mode) +{ + int flags = 0; + + // Get main mode + switch(*mode) + { + case 'r': flags = FILE_FLAG_MODE_READ; break; + case 'w': flags = FILE_FLAG_MODE_WRITE; break; + case 'a': flags = FILE_FLAG_MODE_APPEND; break; + case 'x': flags = FILE_FLAG_MODE_EXEC; break; // Acess addon + default: + return -1; + } + mode ++; + + // Get Modifiers + for( ; *mode; mode ++ ) + { + switch(*mode) + { + case 'b': flags |= FILE_FLAG_M_BINARY; break; + case '+': flags |= FILE_FLAG_M_EXT; break; + default: + return -1; + } + } + + return flags; +} + /** * \fn FILE *freopen(char *file, char *mode, FILE *fp) */ EXPORT FILE *freopen(const char *file, const char *mode, FILE *fp) { int openFlags = 0; - int i; // Sanity Check Arguments if(!fp || !file || !mode) return NULL; - if(fp->Flags) { + if(fp->FD != -1) { fflush(fp); - } else - fp->FD = -1; - - // Get main mode - switch(mode[0]) - { - case 'r': fp->Flags = FILE_FLAG_MODE_READ; break; - case 'w': fp->Flags = FILE_FLAG_MODE_WRITE; break; - case 'a': fp->Flags = FILE_FLAG_MODE_APPEND; break; - case 'x': fp->Flags = FILE_FLAG_MODE_EXEC; break; - default: - return NULL; - } - // Get Modifiers - for(i=1;mode[i];i++) - { - switch(mode[i]) - { - case '+': fp->Flags |= FILE_FLAG_M_EXT; - } } + + // Get stdio flags + fp->Flags = _fopen_modetoflags(mode); + if(fp->Flags == -1) + return NULL; // Get Open Flags - switch(mode[0]) + switch(fp->Flags & FILE_FLAG_MODE_MASK) { // Read - case 'r': openFlags = OPENFLAG_READ; + case FILE_FLAG_MODE_READ: + openFlags = OPENFLAG_READ; if(fp->Flags & FILE_FLAG_M_EXT) openFlags |= OPENFLAG_WRITE; break; // Write - case 'w': openFlags = OPENFLAG_WRITE; + case FILE_FLAG_MODE_WRITE: + openFlags = OPENFLAG_WRITE; if(fp->Flags & FILE_FLAG_M_EXT) openFlags |= OPENFLAG_READ; break; // Execute - case 'x': openFlags = OPENFLAG_EXEC; + case FILE_FLAG_MODE_APPEND: + openFlags = OPENFLAG_APPEND; + if(fp->Flags & FILE_FLAG_M_EXT) + openFlags |= OPENFLAG_READ; + break; + // Execute + case FILE_FLAG_MODE_EXEC: + openFlags = OPENFLAG_EXEC; break; } @@ -93,7 +117,7 @@ EXPORT FILE *freopen(const char *file, const char *mode, FILE *fp) return NULL; } - if(mode[0] == 'a') { + if( (fp->Flags & FILE_FLAG_MODE_MASK) == FILE_FLAG_MODE_APPEND ) { seek(fp->FD, 0, SEEK_END); //SEEK_END } @@ -118,9 +142,34 @@ EXPORT FILE *fopen(const char *file, const char *mode) return freopen(file, mode, retFile); } +EXPORT FILE *fmemopen(void *buffer, size_t length, const char *mode) +{ + FILE *ret; + + if( !buffer || !mode ) return NULL; + + ret = get_file_struct(); + + ret->FD = -2; + ret->Flags = _fopen_modetoflags(mode); + if(ret->Flags == -1) { + ret->Flags = 0; + return NULL; + } + + ret->Buffer = buffer; + ret->BufferStart = 0; + ret->BufferSize = length; + + return ret; +} + EXPORT int fclose(FILE *fp) { - close(fp->FD); + fflush(fp); + if( fp->FD != -1 ) { + close(fp->FD); + } fp->Flags = 0; fp->FD = -1; return 0; @@ -128,21 +177,36 @@ EXPORT int fclose(FILE *fp) EXPORT void fflush(FILE *fp) { - ///\todo Implement + if( !fp || fp->FD == -1 ) + return ; + + if( !(fp->Flags & FILE_FLAG_DIRTY) ) + return ; + + // Nothing to do for memory files + if( fp->FD == -2 ) + return ; } -EXPORT void clearerr(FILE *stream) +EXPORT void clearerr(FILE *fp) { - /// \todo Impliment + if( !fp || fp->FD == -1 ) + return ; + + // TODO: Impliment clearerr() } -EXPORT int feof(FILE *stream) +EXPORT int feof(FILE *fp) { - return 0; //stream->; // ? + if( !fp || fp->FD == -1 ) + return 0; + return !!(fp->Flags & FILE_FLAG_EOF); } -EXPORT int ferror(FILE *stream) +EXPORT int ferror(FILE *fp) { + if( !fp || fp->FD == -1 ) + return 0; return 0; } EXPORT int fileno(FILE *stream) @@ -152,16 +216,42 @@ EXPORT int fileno(FILE *stream) EXPORT off_t ftell(FILE *fp) { - if(!fp || !fp->FD) return -1; - - return tell(fp->FD); + if(!fp || fp->FD == -1) return -1; + + if( fp->FD == -2 ) + return fp->Pos; + else + return tell(fp->FD); } EXPORT int fseek(FILE *fp, long int amt, int whence) { - if(!fp || !fp->FD) return -1; - - return seek(fp->FD, amt, whence); + if(!fp || fp->FD == -1) return -1; + + if( fp->FD == -2 ) { + switch(whence) + { + case SEEK_CUR: + fp->Pos += amt; + break; + case SEEK_SET: + fp->Pos = amt; + break; + case SEEK_END: + if( fp->BufferSize < (size_t)amt ) + fp->Pos = 0; + else + fp->Pos = fp->BufferSize - amt; + break; + } + if(fp->Pos > (off_t)fp->BufferSize) { + fp->Pos = fp->BufferSize; + fp->Flags |= FILE_FLAG_EOF; + } + return 0; + } + else + return seek(fp->FD, amt, whence); } @@ -183,10 +273,7 @@ EXPORT int vfprintf(FILE *fp, const char *format, va_list args) vsnprintf(buf, size+1, (char*)format, args); // Write to stream - write(fp->FD, buf, size); - - // Free buffer - free(buf); + fwrite(buf, size, 1, fp); // Return written byte count return size; @@ -215,10 +302,25 @@ EXPORT int fprintf(FILE *fp, const char *format, ...) */ EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp) { - int ret; - if(!fp || !fp->FD) return -1; - - ret = write(fp->FD, ptr, size*num); + size_t ret; + + if(!fp || fp->FD == -1) + return -1; + + if( fp->FD == -2 ) { + size_t avail = (fp->BufferSize - fp->Pos) / size; + if( avail == 0 ) + fp->Flags |= FILE_FLAG_EOF; + if( num > avail ) num = avail; + size_t bytes = num * size; + memcpy((char*)fp->Buffer + fp->Pos, ptr, bytes); + fp->Pos += bytes; + ret = num; + } + else { + ret = write(fp->FD, ptr, size*num); + ret /= size; + } return ret; } @@ -229,12 +331,26 @@ EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp) */ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) { - int ret; - if(!fp || !fp->FD) return -1; - - // TODO: Fit the spec better with the return value - ret = read(fp->FD, ptr, size*num); - + size_t ret; + + if(!fp || fp->FD == -1) + return -1; + + if( fp->FD == -2 ) { + size_t avail = (fp->BufferSize - fp->Pos) / size; + if( avail == 0 ) + fp->Flags |= FILE_FLAG_EOF; + if( num > avail ) num = avail; + size_t bytes = num * size; + memcpy(ptr, (char*)fp->Buffer + fp->Pos, bytes); + fp->Pos += bytes; + ret = num; + } + else { + ret = read(fp->FD, ptr, size*num); + ret /= size; + } + return ret; } @@ -244,8 +360,7 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) */ EXPORT int fputc(int c, FILE *fp) { - if(!fp || !fp->FD) return -1; - return write(fp->FD, &c, 1); + return fwrite(&c, 1, 1, fp); } EXPORT int putchar(int c) @@ -261,8 +376,8 @@ EXPORT int putchar(int c) EXPORT int fgetc(FILE *fp) { char ret = 0; - if(!fp) return -1; - if(read(fp->FD, &ret, 1) == -1) return -1; + if( fread(&ret, 1, 1, fp) == (size_t)-1 ) + return -1; return ret; } @@ -283,7 +398,12 @@ FILE *get_file_struct() int i; for(i=0;isize); //Unify Right - if((intptr_t)head + head->size < (intptr_t)_heap_end) + if((uintptr_t)head + head->size < (uintptr_t)_heap_end) { heap_head *nextHead = (heap_head*)((intptr_t)head + head->size); if(nextHead->magic == MAGIC_FREE) { //Is the next block free @@ -194,7 +194,7 @@ EXPORT void free(void *mem) } } //Unify Left - if((intptr_t)head - sizeof(heap_foot) > (intptr_t)_heap_start) + if((uintptr_t)head - sizeof(heap_foot) > (uintptr_t)_heap_start) { heap_head *prevHead; heap_foot *prevFoot = (heap_foot *)((intptr_t)head - sizeof(heap_foot)); diff --git a/Usermode/Libraries/libc.so_src/include_exp/ctype.h b/Usermode/Libraries/libc.so_src/include_exp/ctype.h index 4c5613b6..ddb0a614 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/ctype.h +++ b/Usermode/Libraries/libc.so_src/include_exp/ctype.h @@ -35,5 +35,11 @@ static inline int isspace(int ch) { if(ch == '\n') return 1; return 0; } +// C99 +static inline int isblank(int ch) { + if(ch == ' ') return 1; + if(ch == '\t') return 1; + return 0; +} #endif diff --git a/Usermode/Libraries/libc.so_src/lib.h b/Usermode/Libraries/libc.so_src/lib.h index 9f773dce..9e91c9f0 100644 --- a/Usermode/Libraries/libc.so_src/lib.h +++ b/Usermode/Libraries/libc.so_src/lib.h @@ -18,6 +18,8 @@ #define LOCAL #endif +#define UNUSED(type, param) __attribute__((unused)) type UNUSED__##param + extern void *memcpy(void *dest, const void *src, size_t n); typedef struct sCPUID tCPUID; diff --git a/Usermode/Libraries/libc.so_src/scanf.c b/Usermode/Libraries/libc.so_src/scanf.c index 196ef3dc..3a561c4b 100644 --- a/Usermode/Libraries/libc.so_src/scanf.c +++ b/Usermode/Libraries/libc.so_src/scanf.c @@ -7,18 +7,388 @@ */ #include #include +#include +#include + +extern void _SysDebug(const char *format, ...); + +enum e_vcscanf_types +{ + _VCSCANF_NOTYPE, + _VCSCANF_INT, + _VCSCANF_REAL, +}; + +enum e_vcscanf_sizes +{ + _VCSCANF_UNDEF, + _VCSCANF_CHAR, + _VCSCANF_SHORT, + _VCSCANF_LONG, + _VCSCANF_LONGLONG, + _VCSCANF_INTMAX, + _VCSCANF_SIZET, + _VCSCANF_PTRDIFF, + _VCSCANF_LONGDOUBLE +}; // === CODE === -int _vcscanf(int (*__getc)(void *), void *h, const char *format, va_list ap) +int _vcscanf_int(int (*__getc)(void *), void (*__rewind)(void*), void *h, int base, int maxlen, long long *outval) { - // TODO: Impliment - return 0; + char ich; + int sgn = 1; + long long int ret = 0; + int n_read = 0; + + // Initialise output to something sane + *outval = 0; + + // First character + // - maxlen == 0 means no limit + ich = __getc(h); + n_read ++; + + // Sign? + if( ich == '-' || ich == '+' ) { + sgn = (ich == '-' ? -1 : 1); + if( n_read == maxlen ) + return n_read; + ich = __getc(h); + n_read ++; + } + + // Determine base + if( base == 0 ) { + if( ich != '0' ) { + base = 10; + } + else { + if( n_read == maxlen ) + return n_read; + ich = __getc(h); + n_read ++; + if( ich != 'x' ) { + base = 8; + } + else { + base = 16; + if( n_read == maxlen ) + return n_read; + ich = __getc(h); + n_read ++; + } + } + } + + if( ich == 0 ) { + // Oops? + return n_read; + } + + while( ich ) + { + int next = -1; + + // Get the digit value + if( base <= 10 ) { + if( '0' <= ich && ich <= '0'+base-1 ) + next = ich - '0'; + } + else { + if( '0' <= ich && ich <= '9' ) + next = ich - '0'; + if( 'A' <= ich && ich <= 'A'+base-10-1 ) + next = ich - 'A' + 10; + if( 'a' <= ich && ich <= 'a'+base-10-1 ) + next = ich - 'a' + 10; + } + // if it's not a digit, rewind and break + if( next < 0 ) { + __rewind(h); + n_read --; + break; + } + + // Add to the result + ret *= base; + ret += next; + //_SysDebug("- %i/%i read, 0x%x val", n_read, maxlen, ret); + + // Check if we've reached the limit + if( n_read == maxlen ) + break ; + + // Next character + ich = __getc(h); + n_read ++; + } + + // Apply sign + if( sgn == -1 ) + ret = -ret; + + *outval = ret; + return n_read; +} + +int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char *format, va_list ap) +{ + char fch, ich; + int ret = 0, nch = 0; + + while( (fch = *format++) ) + { + union { + void *_void; + char *_char; + short *_short; + int *_int; + long *_long; + long long *_longlong; + } ptr; + long long ival; + //long double rval; + int maxlen = 0, offset = -1; + enum e_vcscanf_sizes size = _VCSCANF_UNDEF; + enum e_vcscanf_types valtype; + + const char *set_start; + int set_len; + + // Whitespace matches any ammount of whitespace (including none) + if( isspace(fch) ) + { + while( (ich = __getc(h)) && isspace(ich) ) + nch ++; + continue ; + } + + // Any non-whitespace and non-% characters must match exactly + if( fch != '%' ) + { + if( __getc(h) != fch ) + break; + nch ++; + continue ; + } + + // Format specifier + fch = *format++; + if(!fch) break; + + // Catch '%%' early + if( fch == '%' ) { + if( __getc(h) != '%' ) + break; + nch ++; + continue ; + } + + // %n$ - Direct offset selection, shouldn't be mixed with just % + for( ; isdigit(fch); fch = *format++ ) + maxlen = maxlen * 10 + (fch - '0'); + if( fch == '$' ) { + offset = maxlen; + maxlen = 0; + } + + // Supress assignemnt? + if( fch == '*' ) + { + fch = *format++; + ptr._void = NULL; + ret --; + } + else + ptr._void = va_arg(ap, void*); + + // Max field length + while( isdigit(fch) ) + { + maxlen = maxlen * 10 + fch - '0'; + fch = *format++; + } + + // Length modifier + switch( fch ) + { + case 'h': + // 'short' + size = _VCSCANF_SHORT; + fch = *format++; + if( fch == 'h' ) { + // 'char' + size = _VCSCANF_CHAR; + fch = *format++; + } + break; + case 'l': + // 'long' + size = _VCSCANF_LONG; + fch = *format++; + if( fch == 'l' ) { + // 'long long' + size = _VCSCANF_LONGLONG; + fch = *format++; + } + break; + case 'j': + // '(u)intmax_t' + size = _VCSCANF_INTMAX; + fch = *format++; + break; + case 'z': + // 'size_t' + size = _VCSCANF_SIZET; + fch = *format++; + break; + case 't': + // 'ptrdiff_t' + size = _VCSCANF_PTRDIFF; + fch = *format++; + break; + case 'L': + // 'long double' (a, A, e, E, f, F, g, G) + size = _VCSCANF_LONGDOUBLE; + fch = *format++; + break; + } + + // Format specifiers + switch( fch ) + { + // Decimal integer + case 'd': + nch += _vcscanf_int(__getc, __rewind, h, 10, maxlen, &ival); + valtype = _VCSCANF_INT; + break; + // variable-base integer + case 'i': + nch += _vcscanf_int(__getc, __rewind, h, 0, maxlen, &ival); + valtype = _VCSCANF_INT; + break; + // Octal integer + case 'o': + nch += _vcscanf_int(__getc, __rewind, h, 8, maxlen, &ival); + valtype = _VCSCANF_INT; + break; + // Hexadecimal integer + case 'x': case 'X': + nch += _vcscanf_int(__getc, __rewind, h, 16, maxlen, &ival); + valtype = _VCSCANF_INT; + break; + // strtod format float + case 'a': case 'A': + case 'e': case 'E': + case 'f': case 'F': + case 'g': case 'G': + valtype = _VCSCANF_REAL; + break; + // `maxlen` or 1 characters + case 'c': + if( maxlen == 0 ) + maxlen = 1; + while( maxlen -- && (ich = __getc(h)) ) + { + if(ptr._char) *ptr._char++ = ich; + nch ++; + } + valtype = _VCSCANF_NOTYPE; + break; + // sequence of non-whitespace characters + case 's': + if( maxlen == 0 ) + maxlen = -1; + + ich = 0; + while( maxlen -- && (ich = __getc(h)) && !isblank(ich) ) + { + if(ptr._char) *ptr._char++ = ich; + nch ++; + } + if( maxlen >= 0 && ich ) + __rewind(h); + valtype = _VCSCANF_NOTYPE; + break; + // match a set of characters + case '[': + fch = *format++; + if( fch == '^' ) { + // Invert + fch = *format; + } + set_start = format; + set_len = 0; + // if the first character is ']' it's part of the set + do { + // permissable character + set_len ++; + fch = *format++; + } while( fch && fch != ']' ); + + ich = 0; + while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) ) + { + if(ptr._char) *ptr._char++ = ich; + nch ++; + } + if( maxlen >= 0 && ich ) + __rewind(h); + valtype = _VCSCANF_NOTYPE; + break; + case 'p': // read back printf("%p") + valtype = _VCSCANF_NOTYPE; + break; + case 'n': // number of read characters to this point + if(ptr._int) { + *ptr._int = nch; + ret --; // negates the ret ++ at the end + } + valtype = _VCSCANF_NOTYPE; + break; + default: + // Implimentation defined + valtype = _VCSCANF_NOTYPE; + break; + } + + switch(valtype) + { + case _VCSCANF_NOTYPE: + // Used when assignment is done above + break; + case _VCSCANF_INT: + switch(size) + { + case _VCSCANF_UNDEF: *ptr._int = ival; break; + case _VCSCANF_CHAR: *ptr._char = ival; break; + case _VCSCANF_SHORT: *ptr._short = ival; break; + case _VCSCANF_LONG: *ptr._long = ival; break; + case _VCSCANF_LONGLONG: *ptr._longlong = ival; break; + default: // ??? + break; + } + break; + case _VCSCANF_REAL: + break; + } + + ret ++; + } + + return ret; } int _vsscanf_getc(void *h) { const char **ibuf = h; - return *(*ibuf)++; // Dereference, read, increment + return *(*ibuf)++; // Dereference, read for return, increment +} + +void _vsscanf_rewind(void *h) +{ + const char **ibuf = h; + (*ibuf) --; // NOTE: Breaks if there's a rewind before a getc, but that shouldn't happen } int vscanf(const char *format, va_list ap) @@ -28,17 +398,21 @@ int vscanf(const char *format, va_list ap) int vsscanf(const char *str, const char *format, va_list ap) { - return _vcscanf(_vsscanf_getc, &str, format, ap); + return _vcscanf(_vsscanf_getc, _vsscanf_rewind, &str, format, ap); } int _vfscanf_getc(void *h) { return fgetc(h); // TODO: Handle -1 -> 0 } +void _vfscanf_rewind(void *h) +{ + fseek(h, -1, SEEK_CUR); +} int vfscanf(FILE *stream, const char *format, va_list ap) { - return _vcscanf(_vfscanf_getc, stream, format, ap); + return _vcscanf(_vfscanf_getc, _vfscanf_rewind, stream, format, ap); } int scanf(const char *format, ...) diff --git a/Usermode/Libraries/libc.so_src/stdio_int.h b/Usermode/Libraries/libc.so_src/stdio_int.h index 5bfbf986..f87da812 100644 --- a/Usermode/Libraries/libc.so_src/stdio_int.h +++ b/Usermode/Libraries/libc.so_src/stdio_int.h @@ -4,28 +4,35 @@ * Configuration Options */ #ifndef _STDIO_INT_H -# define _STDIO_INT_H +#define _STDIO_INT_H + +#include +#include // === CONSTANTS === -#define FILE_FLAG_MODE_MASK 0x07 -#define FILE_FLAG_MODE_READ 0x01 -#define FILE_FLAG_MODE_WRITE 0x02 -#define FILE_FLAG_MODE_EXEC 0x03 -#define FILE_FLAG_MODE_APPEND 0x04 -#define FILE_FLAG_M_EXT 0x10 +#define FILE_FLAG_MODE_MASK 0x0007 +#define FILE_FLAG_MODE_READ 0x0001 +#define FILE_FLAG_MODE_WRITE 0x0002 +#define FILE_FLAG_MODE_EXEC 0x0003 +#define FILE_FLAG_MODE_APPEND 0x0004 +#define FILE_FLAG_M_EXT 0x0010 +#define FILE_FLAG_M_BINARY 0x0020 +#define FILE_FLAG_EOF 0x0100 +#define FILE_FLAG_DIRTY 0x0200 +#define FILE_FLAG_ALLOC 0x1000 // === TYPES === struct sFILE { - int FD; int Flags; + int FD; + off_t Pos; + #if DEBUG_BUILD - char *FileName; - #endif - #if STDIO_LOCAL_BUFFER - char *Buffer; - Uint64 BufferStart; - int BufferSize; + char *FileName; // heap #endif + void *Buffer; + off_t BufferStart; + size_t BufferSize; }; #endif diff --git a/Usermode/Libraries/libc.so_src/stdlib.c b/Usermode/Libraries/libc.so_src/stdlib.c index c91106c4..469f51c9 100644 --- a/Usermode/Libraries/libc.so_src/stdlib.c +++ b/Usermode/Libraries/libc.so_src/stdlib.c @@ -48,7 +48,7 @@ EXPORT void exit(int status) */ EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) { - int i, j, min; + size_t i, j, min; // With 0 items, there's nothing to do and with 1 its already sorted if(nmemb == 0 || nmemb == 1) return; diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index 3cadee90..d8d08721 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -273,7 +273,7 @@ EXPORT void *memmove(void *dest, const void *src, size_t count) char *sp = (char *)src; char *dp = (char *)dest; // Check if the areas overlap - if( (intptr_t)src < (intptr_t)dest && (intptr_t)dest < (intptr_t)src+count ) + if( (uintptr_t)src < (uintptr_t)dest && (uintptr_t)dest < (uintptr_t)src+count ) for(;count--;) dp[count] = sp[count]; else diff --git a/Usermode/Libraries/libc.so_src/stub.c b/Usermode/Libraries/libc.so_src/stub.c index 2494fc28..7cde4c1b 100644 --- a/Usermode/Libraries/libc.so_src/stub.c +++ b/Usermode/Libraries/libc.so_src/stub.c @@ -44,7 +44,7 @@ tCPUID gCPU_Features; * \param argv Unused - Arguments (NULL for current version of ld-acess) * \param envp Environment Pointer */ -int SoMain(unsigned int BaseAddress, int argc, char **argv, char **envp) +int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp) { // Init for env.c _envp = envp; -- 2.20.1