}
else
{
- return *((status->s)++);
+ return ( *status->s == '\0' ) ? EOF : *((status->s)++);
}
}
strtol() will return zero. In both cases, endptr will point to the
rest of the conversion specifier - just what we need.
*/
+ char const * prev_spec = spec;
status->width = (int)strtol( spec, (char**)&spec, 10 );
+ if ( spec == prev_spec )
+ {
+ status->width = SIZE_MAX;
+ }
/* Optional length modifier
We step one character ahead in any case, and step back only if we find
*(c++) = rc;
value_parsed = true;
}
- return value_parsed ? spec : NULL;
+ if ( value_parsed )
+ {
+ ++status->n;
+ return ++spec;
+ }
+ else
+ {
+ /* FIXME: Need two kinds of "no match" here: zero width, and input error */
+ return NULL;
+ }
}
case 's':
{
if ( value_parsed )
{
*c = '\0';
- return spec;
+ ++status->n;
+ return ++spec;
}
else
{
/* ASSIGN( E_size | E_unsigned, unsigned size_t ); */
ASSIGN( E_ptrdiff, ptrdiff_t );
/* ASSIGN( E_ptrdiff | E_unsigned, unsigned ptrdiff_t ); */
+ default:
+ puts( "UNSUPPORTED SCANF FLAG COMBINATION" );
+ return NULL;
}
- return spec;
+ return ++spec;
}
/* TODO: Floats. */
return NULL;
#ifdef TEST
#include <_PDCLIB_test.h>
+#include <limits.h>
+
+
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ /* Testing covered by fscanf.c */
return TEST_RESULTS;
}