]> git.sur5r.net Git - cc65/blob - libsrc/common/gets.c
added sleep() implementation
[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 char* gets (char* s)
15 {
16     int c;
17     int i = 0;
18
19     do {
20
21         /* Get next character */
22         if ((c = fgetc (stdin)) == EOF) {
23             /* Error or EOF */
24             s [i] = 0;
25             if (stdin->f_flags & _FERROR) {
26                 /* ERROR */
27                 return 0;
28             } else {
29                 /* EOF */
30                 if (i) {
31                     return s;
32                 } else {
33                     return 0;
34                 }
35             }
36         }
37
38         /* One char more */
39         s [i++] = c;
40
41     } while (c != '\n');
42
43     /* Replace newline by NUL */
44     s [i-1] = '\0';
45
46     /* Done */
47     return s;
48 }
49
50
51