gets.c 277 B

123456789101112131415
  1. #include "stdio_impl.h"
  2. #include <limits.h>
  3. #include <string.h>
  4. char *gets(char *s)
  5. {
  6. size_t i=0;
  7. int c;
  8. FLOCK(stdin);
  9. while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c;
  10. s[i] = 0;
  11. if (c != '\n' && (!feof(stdin) || !i)) s = 0;
  12. FUNLOCK(stdin);
  13. return s;
  14. }