gets.c 781 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * GNU Library General Public License (LGPL) version 2 or later.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #include "_stdio.h"
  8. /* UNSAFE FUNCTION -- do not bother optimizing */
  9. /* disable macro, force actual function call */
  10. #undef getchar_unlocked
  11. char *gets(char *s)
  12. {
  13. register char *p = s;
  14. int c;
  15. __STDIO_AUTO_THREADLOCK_VAR;
  16. __STDIO_AUTO_THREADLOCK(stdin);
  17. /* Note: don't worry about performance here... this shouldn't be used!
  18. * Therefore, force actual function call. */
  19. while (((c = getchar_unlocked()) != EOF) && ((*p = c) != '\n')) {
  20. ++p;
  21. }
  22. if ((c == EOF) || (s == p)) {
  23. s = NULL;
  24. } else {
  25. *p = 0;
  26. }
  27. __STDIO_AUTO_THREADUNLOCK(stdin);
  28. return s;
  29. }