3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
11 #include <_PDCLIB_glue.h>
13 char * gets( char * s )
15 if ( _PDCLIB_prepread( stdin ) == EOF )
20 while ( ( *dest = stdin->buffer[stdin->bufidx++] ) != '\n' )
23 if ( stdin->bufidx == stdin->bufend )
25 if ( _PDCLIB_fillbuffer( stdin ) == EOF )
32 return ( dest == s ) ? NULL : s;
38 #include <_PDCLIB_test.h>
45 char const * gets_test = "foo\nbar\0baz\nweenie";
46 TESTCASE( ( fh = fopen( testfile, "wb" ) ) != NULL );
47 TESTCASE( fwrite( gets_test, 1, 18, fh ) == 18 );
48 TESTCASE( fclose( fh ) == 0 );
49 TESTCASE( ( fh = freopen( testfile, "rb", stdin ) ) != NULL );
50 TESTCASE( gets( buffer ) == buffer );
51 TESTCASE( strcmp( buffer, "foo" ) == 0 );
52 TESTCASE( gets( buffer ) == buffer );
53 TESTCASE( memcmp( buffer, "bar\0baz\0", 8 ) == 0 );
54 TESTCASE( gets( buffer ) == buffer );
55 TESTCASE( strcmp( buffer, "weenie" ) == 0 );
56 TESTCASE( feof( fh ) );
57 TESTCASE( fseek( fh, -1, SEEK_END ) == 0 );
58 TESTCASE( gets( buffer ) == buffer );
59 TESTCASE( strcmp( buffer, "e" ) == 0 );
60 TESTCASE( feof( fh ) );
61 TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
62 TESTCASE( gets( buffer ) == NULL );
63 TESTCASE( fclose( fh ) == 0 );
64 TESTCASE( remove( testfile ) == 0 );