]> git.sur5r.net Git - cc65/blob - libsrc/common/gets.c
Adjusted C declarations to the changed static driver names.
[cc65] / libsrc / common / gets.c
1 /*
2  * gets.c
3  *
4  * Ullrich von Bassewitz, 11.08.1998
5  */
6
7
8
9 #include <stdio.h>
10 #include "_file.h"
11
12
13
14 /*****************************************************************************/
15 /*                                   Code                                    */
16 /*****************************************************************************/
17
18
19
20 char* __fastcall__ gets (char* s)
21 {
22     register char* p = s;
23     int c;
24     unsigned i = 0;
25
26     while (1) {
27
28         /* Get next character */
29         if ((c = fgetc (stdin)) == EOF) {
30             /* Error or EOF */
31             *p = '\0';
32             if (stdin->f_flags & _FERROR) {
33                 /* ERROR */
34                 return 0;
35             } else {
36                 /* EOF */
37                 if (i) {
38                     return s;
39                 } else {
40                     return 0;
41                 }
42             }
43         }
44
45         /* One char more. Newline ends the input */
46         if ((char) c == '\n') {
47             *p = '\0';
48             break;
49         } else {
50             *p = c;
51             ++p;
52             ++i;
53         }
54
55     }
56
57     /* Done */
58     return s;
59 }
60
61
62
63