X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flib.c;h=76cc4286268fa0a84f4d2cae83656226fc1ccb91;hb=8de6b4e1a2050289458d6489551eb61b6c1d3645;hp=369b7b0b8593848ffd3523d8fcd03bc2707c697f;hpb=c0a6af0e8c4840c370e819cd44925502fae8c4ba;p=tpg%2Facess2.git diff --git a/Kernel/lib.c b/Kernel/lib.c index 369b7b0b..76cc4286 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -191,11 +191,7 @@ void itoa(char *buf, Uint64 num, int base, int minLength, char pad) /** * \brief Append a character the the vsnprintf output */ -#define PUTCH(c) do{\ - char ch=(c);\ - if(pos==__maxlen){return pos;}\ - if(__s){__s[pos++]=ch;}else{pos++;}\ - }while(0) +#define PUTCH(c) _putch(c) #define GETVAL() do {\ if(isLongLong) val = va_arg(args, Uint64);\ else val = va_arg(args, unsigned int);\ @@ -215,15 +211,24 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) // Flags int bPadLeft = 0; - //Log("vsnprintf: (__s=%p, __maxlen=%i, __format='%s', ...)", __s, __maxlen, __format); - + auto void _putch(char ch); + + void _putch(char ch) + { + if(pos < __maxlen) + { + if(__s) __s[pos] = ch; + pos ++; + } + } + while((c = *__format++) != 0) { // Non control character if(c != '%') { PUTCH(c); continue; } - + c = *__format++; - //Log("pos = %i", pos); + if(c == '\0') break; // Literal % if(c == '%') { PUTCH('%'); continue; } @@ -232,9 +237,9 @@ 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'); - itoa(tmpBuf, ptr, 16, BITS/4, '0'); - p = tmpBuf; - goto printString; + for( len = BITS/4; len --; ) + PUTCH( cUCDIGITS[ (ptr>>(len*4))&15 ] ); + continue ; } // - Padding Side Flag @@ -490,11 +495,11 @@ char *strcpy(char *__str1, const char *__str2) * \brief Copy a string to a new location * \note Copies at most `max` chars */ -char *strncpy(char *__str1, const char *__str2, size_t max) +char *strncpy(char *__str1, const char *__str2, size_t __max) { - while(*__str2 && max-- >= 1) + while(*__str2 && __max-- >= 1) *__str1++ = *__str2++; - if(max) + if(__max) *__str1 = '\0'; // Terminate String return __str1; } @@ -720,37 +725,39 @@ int WriteUTF8(Uint8 *str, Uint32 Val) { // ASCII if( Val < 128 ) { - *str = Val; + if( str ) { + *str = Val; + } return 1; } // Two Byte if( Val < 0x8000 ) { - *str = 0xC0 | (Val >> 6); - str ++; - *str = 0x80 | (Val & 0x3F); + if( str ) { + *str++ = 0xC0 | (Val >> 6); + *str++ = 0x80 | (Val & 0x3F); + } return 2; } // Three Byte if( Val < 0x10000 ) { - *str = 0xE0 | (Val >> 12); - str ++; - *str = 0x80 | ((Val >> 6) & 0x3F); - str ++; - *str = 0x80 | (Val & 0x3F); + if( str ) { + *str++ = 0xE0 | (Val >> 12); + *str++ = 0x80 | ((Val >> 6) & 0x3F); + *str++ = 0x80 | (Val & 0x3F); + } return 3; } // Four Byte if( Val < 0x110000 ) { - *str = 0xF0 | (Val >> 18); - str ++; - *str = 0x80 | ((Val >> 12) & 0x3F); - str ++; - *str = 0x80 | ((Val >> 6) & 0x3F); - str ++; - *str = 0x80 | (Val & 0x3F); + if( str ) { + *str++ = 0xF0 | (Val >> 18); + *str++ = 0x80 | ((Val >> 12) & 0x3F); + *str++ = 0x80 | ((Val >> 6) & 0x3F); + *str++ = 0x80 | (Val & 0x3F); + } return 4; }