git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Usermode/libc - Fix strchr and strrchr behavior
[tpg/acess2.git]
/
Usermode
/
Libraries
/
libc.so_src
/
scanf.c
diff --git
a/Usermode/Libraries/libc.so_src/scanf.c
b/Usermode/Libraries/libc.so_src/scanf.c
index
3a561c4
..
6fff176
100644
(file)
--- 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;
} 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;
enum e_vcscanf_sizes size = _VCSCANF_UNDEF;
enum e_vcscanf_types valtype;
+ int fail = 0;
+ int nnewch;
const char *set_start;
int set_len;
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 ++;
{
while( (ich = __getc(h)) && isspace(ich) )
nch ++;
+ if(ich) __rewind(h);
continue ;
}
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 %
}
// %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;
}
for( ; isdigit(fch); fch = *format++ )
maxlen = maxlen * 10 + (fch - '0');
if( fch == '$' ) {
offset = maxlen;
maxlen = 0;
}
+ #endif
// Supress assignemnt?
if( fch == '*' )
// Supress assignemnt?
if( fch == '*' )
@@
-259,22
+265,30
@@
int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char
{
// Decimal integer
case 'd':
{
// 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':
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':
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':
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
valtype = _VCSCANF_INT;
break;
// strtod format float
@@
-301,21
+315,22
@@
int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char
maxlen = -1;
ich = 0;
maxlen = -1;
ich = 0;
- while( maxlen -- && (ich = __getc(h)) && !is
blank
(ich) )
+ while( maxlen -- && (ich = __getc(h)) && !is
space
(ich) )
{
if(ptr._char) *ptr._char++ = ich;
nch ++;
}
if( maxlen >= 0 && ich )
__rewind(h);
{
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
valtype = _VCSCANF_NOTYPE;
break;
// match a set of characters
- case '[':
-
fch = *format++
;
- if(
fch
== '^' ) {
+ case '[':
{
+
int invert = 0
;
+ if(
*format++
== '^' ) {
// Invert
// Invert
-
fch = *format
;
+
invert = 1
;
}
set_start = format;
set_len = 0;
}
set_start = format;
set_len = 0;
@@
-326,16
+341,20
@@
int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char
fch = *format++;
} while( fch && fch != ']' );
fch = *format++;
} while( fch && fch != ']' );
+ if( maxlen == 0 )
+ maxlen = -1;
ich = 0;
ich = 0;
- while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) )
+ while( maxlen -- && (ich = __getc(h)) &&
invert == !
memchr(set_start, set_len, ich) )
{
if(ptr._char) *ptr._char++ = ich;
nch ++;
}
if( maxlen >= 0 && ich )
__rewind(h);
{
if(ptr._char) *ptr._char++ = ich;
nch ++;
}
if( maxlen >= 0 && ich )
__rewind(h);
+ if(ptr._char) *ptr._char++ = 0;
valtype = _VCSCANF_NOTYPE;
break;
valtype = _VCSCANF_NOTYPE;
break;
+ }
case 'p': // read back printf("%p")
valtype = _VCSCANF_NOTYPE;
break;
case 'p': // read back printf("%p")
valtype = _VCSCANF_NOTYPE;
break;
@@
-351,7
+370,10
@@
int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char
valtype = _VCSCANF_NOTYPE;
break;
}
valtype = _VCSCANF_NOTYPE;
break;
}
-
+
+ if(fail)
+ break;
+
switch(valtype)
{
case _VCSCANF_NOTYPE:
switch(valtype)
{
case _VCSCANF_NOTYPE:
@@
-403,7
+425,8
@@
int vsscanf(const char *str, const char *format, va_list ap)
int _vfscanf_getc(void *h)
{
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)
{
}
void _vfscanf_rewind(void *h)
{
UCC
git Repository :: git.ucc.asn.au