X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flib.c;h=27995b0732f6b0b93c77b57b2bfbe58bd057afc9;hb=311b8047c85b22302153740947694df50d2ce356;hp=3e57d00d721800551bef3568428482a4ec8f4916;hpb=9d85201216cb35e1b1e051b1d7cdc38eaa5befa4;p=tpg%2Facess2.git diff --git a/Kernel/lib.c b/Kernel/lib.c index 3e57d00d..27995b07 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -199,7 +199,7 @@ void itoa(char *buf, Uint64 num, int base, int minLength, char pad) int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) { char c, pad = ' '; - int minSize = 0, len; + int minSize = 0, precision = -1, len; char tmpBuf[34]; // For Integers const char *p = NULL; int isLongLong = 0; @@ -231,7 +231,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) } // - Padding Side Flag - if(c == '+') { + if(c == '-') { bPadLeft = 1; c = *__format++; } @@ -260,7 +260,28 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) } } else - minSize = 1; + minSize = 0; + + // - Precision + precision = -1; + if( c == '.' ) { + c = *__format++; + + if(c == '*') { // Dynamic length + precision = va_arg(args, unsigned int); + c = *__format++; + } + else if('1' <= c && c <= '9') + { + precision = 0; + while('0' <= c && c <= '9') + { + precision *= 10; + precision += c - '0'; + c = *__format++; + } + } + } // - Default, Long or LongLong? isLongLong = 0; @@ -323,12 +344,12 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) // String - Null Terminated Array case 's': p = va_arg(args, char*); // Get Argument - if( !CheckString(p) ) continue; // Avoid #PFs + if( !CheckString(p) ) p = "(inval)"; // Avoid #PFs printString: if(!p) p = "(null)"; len = strlen(p); if( !bPadLeft ) while(len++ < minSize) PUTCH(pad); - while(*p) PUTCH(*p++); + while(*p && precision--) PUTCH(*p++); if( bPadLeft ) while(len++ < minSize) PUTCH(pad); break;