]> pd.if.org Git - pdclib/blob - functions/stdio/gets.c
9dbc515f88cc8ae213c0be6c333160ba674d33b7
[pdclib] / functions / stdio / gets.c
1 /* $Id$ */
2
3 /* gets( char * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10
11 #ifndef REGTEST
12
13 #define _PDCLIB_GLUE_H _PDCLIB_GLUE_H
14 #include <_PDCLIB_glue.h>
15
16 char * gets( char * s )
17 {
18     if ( _PDCLIB_prepread( stdin ) == EOF )
19     {
20         return NULL;
21     }
22     char * dest = s;
23     while ( ( *dest = stdin->buffer[stdin->bufidx++] ) != '\n' )
24     {
25         if ( stdin->bufidx == stdin->bufend )
26         {
27             if ( _PDCLIB_fillbuffer( stdin ) == EOF )
28             {
29                 return NULL;
30             }
31         }
32         ++dest;
33     }
34     *dest = '\n';
35     return s;
36 }
37
38 #endif
39
40 #ifdef TEST
41 #include <_PDCLIB_test.h>
42
43 int main( void )
44 {
45     TESTCASE( NO_TESTDRIVER );
46     return TEST_RESULTS;
47 }
48
49 #endif
50