X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=KernelLand%2FKernel%2Flibc.c;h=8674650b1aab68478e638c0ade8c8e9763e81548;hb=ca2cf2eb7207fb9c76e6d060e885d2e9e09762ec;hp=7a7cc0562fcc8937be1d36baa6ec265aad36e1eb;hpb=bd5e8623e509a443d7d6e1b959b79f85b0c285b7;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/libc.c b/KernelLand/Kernel/libc.c index 7a7cc056..8674650b 100644 --- a/KernelLand/Kernel/libc.c +++ b/KernelLand/Kernel/libc.c @@ -49,6 +49,7 @@ EXPORT(tolower); EXPORT(strucmp); EXPORT(strchr); +EXPORT(strrchr); EXPORT(strpos); EXPORT(strlen); EXPORT(strcpy); @@ -183,7 +184,14 @@ void itoa(char *buf, Uint64 num, int base, int minLength, char pad) /** * \brief Append a character the the vsnprintf output */ -#define PUTCH(c) _putch(c) +#define PUTCH(ch) do { \ + if(pos < __maxlen) { \ + if(__s) __s[pos] = ch; \ + } else { \ + (void)ch;\ + } \ + pos ++; \ + } while(0) #define GETVAL() do {\ if(isLongLong) val = va_arg(args, Uint64);\ else val = va_arg(args, unsigned int);\ @@ -202,17 +210,6 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) size_t pos = 0; // Flags int bPadLeft = 0; - - auto void _putch(char ch); - - void _putch(char ch) - { - if(pos < __maxlen) - { - if(__s) __s[pos] = ch; - } - pos ++; - } while((c = *__format++) != 0) { @@ -229,8 +226,14 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) if(c == 'p') { Uint ptr = va_arg(args, Uint); PUTCH('*'); PUTCH('0'); PUTCH('x'); - for( len = BITS/4; len --; ) - PUTCH( cUCDIGITS[ (ptr>>(len*4))&15 ] ); + for( len = BITS/4; len -- && ((ptr>>(len*4))&15) == 0; ) + ; + len ++; + if( len == 0 ) + PUTCH( '0' ); + else + while( len -- ) + PUTCH( cUCDIGITS[ (ptr>>(len*4))&15 ] ); continue ; } @@ -529,6 +532,15 @@ char *strchr(const char *__s, int __c) return NULL; } +char *strrchr(const char *__s, int __c) +{ + size_t ofs = strlen(__s); + while(--ofs && __s[ofs] != __c); + if( __s[ofs] == __c ) + return (char*)__s + ofs; + return NULL; +} + /** * \fn int strpos(const char *Str, char Ch) * \brief Search a string for an ascii character @@ -688,7 +700,6 @@ int rand(void) void *memmove(void *__dest, const void *__src, size_t len) { - size_t block_size; char *dest = __dest; const char *src = __src; void *ret = __dest; @@ -705,6 +716,8 @@ void *memmove(void *__dest, const void *__src, size_t len) if( (tVAddr)dest < (tVAddr)src ) return memcpy(dest, src, len); + #if 0 + size_t block_size; if( (tVAddr)dest < (tVAddr)src ) block_size = (tVAddr)src - (tVAddr)dest; else @@ -721,10 +734,18 @@ void *memmove(void *__dest, const void *__src, size_t len) } memcpy(dest, src, len); return ret; + #else + for( int i = len; i--; ) + { + dest[i] = src[i]; + } + return ret; + #endif } -// NOTE: Strictly not libc, but lib.c is used by userland code too +// NOTE: Strictly not libc, but lib.c is used by userland code too and hence these two +// can't be in it. /** * \name Memory Validation * \{