// 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;
{
while( (ich = __getc(h)) && isspace(ich) )
nch ++;
+ if(ich) __rewind(h);
continue ;
}
{
// 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
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
fch = *format++;
} while( fch && fch != ']' );
+ if( maxlen == 0 )
+ maxlen = -1;
ich = 0;
while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) )
{
}
if( maxlen >= 0 && ich )
__rewind(h);
+ if(ptr._char) *ptr._char++ = 0;
valtype = _VCSCANF_NOTYPE;
break;
case 'p': // read back printf("%p")
valtype = _VCSCANF_NOTYPE;
break;
}
-
+
+ if(fail)
+ break;
+
switch(valtype)
{
case _VCSCANF_NOTYPE:
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)
{
}\r
else {\r
ret = _SysRead(fp->FD, ptr, size*num);\r
+ if( ret == (size_t)-1)\r
+ return -1;\r
+ if( ret == 0 && size*num > 0 ) {\r
+ fp->Flags |= FILE_FLAG_EOF;\r
+ return 0;\r
+ }\r
ret /= size;\r
}\r
\r
EXPORT int fgetc(FILE *fp)\r
{\r
char ret = 0;\r
- if( fread(&ret, 1, 1, fp) == (size_t)-1 )\r
+ if( fread(&ret, 1, 1, fp) != 1 )\r
return -1;\r
return ret;\r
}\r