X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fscanf.c;h=3d45ed13aca9776151dc37b1baa01578eb47265e;hb=b770132cdb8e79f27f3d429f24d94284dd6fe970;hp=3a561c4bc21e23e12f6679ef470ea1ba61639caf;hpb=0eb50bc9e604f654bdb0409bb66da03b733f906c;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/scanf.c b/Usermode/Libraries/libc.so_src/scanf.c index 3a561c4b..3d45ed13 100644 --- a/Usermode/Libraries/libc.so_src/scanf.c +++ b/Usermode/Libraries/libc.so_src/scanf.c @@ -148,9 +148,12 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char } ptr; long long ival; //long double rval; - int maxlen = 0, offset = -1; + int maxlen = 0; + // int offset = -1; enum e_vcscanf_sizes size = _VCSCANF_UNDEF; enum e_vcscanf_types valtype; + int fail = 0; + int nnewch; const char *set_start; int set_len; @@ -160,6 +163,7 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char { while( (ich = __getc(h)) && isspace(ich) ) nch ++; + if(ich) __rewind(h); continue ; } @@ -185,12 +189,14 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char } // %n$ - Direct offset selection, shouldn't be mixed with just % + #if 0 for( ; isdigit(fch); fch = *format++ ) maxlen = maxlen * 10 + (fch - '0'); if( fch == '$' ) { offset = maxlen; maxlen = 0; } + #endif // Supress assignemnt? if( fch == '*' ) @@ -259,22 +265,30 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char { // Decimal integer case 'd': - nch += _vcscanf_int(__getc, __rewind, h, 10, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 10, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // variable-base integer case 'i': - nch += _vcscanf_int(__getc, __rewind, h, 0, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 0, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // Octal integer case 'o': - nch += _vcscanf_int(__getc, __rewind, h, 8, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 8, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // Hexadecimal integer case 'x': case 'X': - nch += _vcscanf_int(__getc, __rewind, h, 16, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 16, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // strtod format float @@ -301,13 +315,14 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char maxlen = -1; ich = 0; - while( maxlen -- && (ich = __getc(h)) && !isblank(ich) ) + while( maxlen -- && (ich = __getc(h)) && !isspace(ich) ) { if(ptr._char) *ptr._char++ = ich; nch ++; } if( maxlen >= 0 && ich ) __rewind(h); + if(ptr._char) *ptr._char++ = 0; valtype = _VCSCANF_NOTYPE; break; // match a set of characters @@ -326,6 +341,8 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char fch = *format++; } while( fch && fch != ']' ); + if( maxlen == 0 ) + maxlen = -1; ich = 0; while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) ) { @@ -334,6 +351,7 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char } if( maxlen >= 0 && ich ) __rewind(h); + if(ptr._char) *ptr._char++ = 0; valtype = _VCSCANF_NOTYPE; break; case 'p': // read back printf("%p") @@ -351,7 +369,10 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char valtype = _VCSCANF_NOTYPE; break; } - + + if(fail) + break; + switch(valtype) { case _VCSCANF_NOTYPE: @@ -403,7 +424,8 @@ int vsscanf(const char *str, const char *format, va_list ap) int _vfscanf_getc(void *h) { - return fgetc(h); // TODO: Handle -1 -> 0 + int ch = fgetc(h); + return ch == -1 ? 0 : ch; } void _vfscanf_rewind(void *h) {