Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #include "stdio_impl.h" |
Rich Felker | 835f9f9 | 2012-11-08 16:39:41 -0500 | [diff] [blame] | 2 | #include <limits.h> |
| 3 | #include <string.h> |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 4 | |
| 5 | char *gets(char *s) |
| 6 | { |
Rich Felker | b202057 | 2019-02-13 18:48:04 -0500 | [diff] [blame] | 7 | size_t i=0; |
| 8 | int c; |
| 9 | FLOCK(stdin); |
| 10 | while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c; |
| 11 | s[i] = 0; |
| 12 | if (c != '\n' && (!feof(stdin) || !i)) s = 0; |
| 13 | FUNLOCK(stdin); |
| 14 | return s; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 15 | } |