diff options
author | Chris Apers | 2004-05-25 13:36:02 +0000 |
---|---|---|
committer | Chris Apers | 2004-05-25 13:36:02 +0000 |
commit | e228f9b55d66e491e35c28ebc71a0cf8a2e50c72 (patch) | |
tree | f5f6ca263fcc012d10cf1d029ad5a72d6ca89cd0 /backends/PalmOS/Src/missing | |
parent | df71bebd95645b948a89a80fedc5477272a0aec0 (diff) | |
download | scummvm-rg350-e228f9b55d66e491e35c28ebc71a0cf8a2e50c72.tar.gz scummvm-rg350-e228f9b55d66e491e35c28ebc71a0cf8a2e50c72.tar.bz2 scummvm-rg350-e228f9b55d66e491e35c28ebc71a0cf8a2e50c72.zip |
New strtol function, bsearch now use system call, cleanup
svn-id: r13868
Diffstat (limited to 'backends/PalmOS/Src/missing')
-rw-r--r-- | backends/PalmOS/Src/missing/_stdlib.cpp | 42 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/stdlib.h | 19 |
2 files changed, 36 insertions, 25 deletions
diff --git a/backends/PalmOS/Src/missing/_stdlib.cpp b/backends/PalmOS/Src/missing/_stdlib.cpp index 6d242c5df7..0c89ecd0d9 100644 --- a/backends/PalmOS/Src/missing/_stdlib.cpp +++ b/backends/PalmOS/Src/missing/_stdlib.cpp @@ -21,17 +21,31 @@ */ #include "stdlib.h" -/////////////////////////////////////////////////////////////////////////////// -void *bsearch(const void *key, const void *base, UInt32 nmemb, - UInt32 size, int (*compar)(const void *, const void *)) { - UInt32 i; - for (i=0; i<nmemb; i++) - if (compar(key, (void*)((UInt32)base + size * i)) == 0) - return (void*)((UInt32)base + size * i); +void *bsearch(const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *)) { + Int32 position; + + if (SysBinarySearch(base, nmemb, size, (SearchFuncPtr)compar, key, 0, &position, true)) + return (void *)((UInt32)base + size * position); + return NULL; } -/////////////////////////////////////////////////////////////////////////////// + +long strtol(const char *s, char **endptr, int base) { + // WARNING : only base = 10 supported + long val = StrAToI(s); + + if (endptr) { + Char str[maxStrIToALen]; + StrIToA(str, val); + + if (StrNCompare(s, str, StrLen(str)) == 0) + *endptr = (char *)s + StrLen(str); + } + + return val; +} + MemPtr calloc(UInt32 nelem, UInt32 elsize) { MemPtr newP; UInt32 size = nelem*elsize; @@ -43,15 +57,14 @@ MemPtr calloc(UInt32 nelem, UInt32 elsize) { return newP; } -/////////////////////////////////////////////////////////////////////////////// + Err free(MemPtr memP) { if (memP) return MemPtrFree(memP); return memErrInvalidParam; } -/////////////////////////////////////////////////////////////////////////////// -MemPtr realloc(MemPtr oldP, UInt32 size) -{ + +MemPtr realloc(MemPtr oldP, UInt32 size) { if (oldP != NULL) if (MemPtrResize(oldP,size) == 0) @@ -66,9 +79,8 @@ MemPtr realloc(MemPtr oldP, UInt32 size) } return newP; } -/////////////////////////////////////////////////////////////////////////////// -void exit(Int16 status) -{ + +void exit(Int16 status) { // need to change this EventType event; event.eType = keyDownEvent; diff --git a/backends/PalmOS/Src/missing/stdlib.h b/backends/PalmOS/Src/missing/stdlib.h index 709dbac320..5d0337dac2 100644 --- a/backends/PalmOS/Src/missing/stdlib.h +++ b/backends/PalmOS/Src/missing/stdlib.h @@ -25,7 +25,6 @@ #include <PalmOS.h> #include "MemGlue.h" -#include "mathlib.h" #define atoi StrAToI #define atol StrAToI @@ -33,17 +32,17 @@ //#define abs fabs #define malloc(a) MemGluePtrNew(a) //#define free MemPtrFree -#define strtol(a,b,c) StrAToI(a) +//#define strtol(a,b,c) StrAToI(a) #define qsort(a,b,c,d) SysQSort((a), (b), (c), (CmpFuncPtr)(&d), 0); #define rand() SysRandom(0) #define abort() - -MemPtr realloc(MemPtr oldP, UInt32 size); -MemPtr calloc(UInt32 nelem, UInt32 elsize); -Err free(MemPtr memP); -void exit(Int16 status); -void *bsearch(const void *key, const void *base, UInt32 nmemb, - UInt32 size, int (*compar)(const void *, const void *)); - +#define strtoul(a,b,c) ((unsigned long)strtol(a,b,c)) + +void *bsearch (const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *)); +MemPtr calloc (UInt32 nelem, UInt32 elsize); +void exit (Int16 status); +Err free (MemPtr memP); +MemPtr realloc (MemPtr oldP, UInt32 size); +long strtol (const char *s, char **endptr, int base); #endif |