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