gets.c 861 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. link_warning(gets, "the 'gets' function is dangerous and should not be used.")
  9. /* UNSAFE FUNCTION -- do not bother optimizing */
  10. /* disable macro, force actual function call */
  11. #undef getchar_unlocked
  12. char *gets(char *s)
  13. {
  14. register char *p = s;
  15. int c;
  16. __STDIO_AUTO_THREADLOCK_VAR;
  17. __STDIO_AUTO_THREADLOCK(stdin);
  18. /* Note: don't worry about performance here... this shouldn't be used!
  19. * Therefore, force actual function call. */
  20. while (((c = getchar_unlocked()) != EOF) && ((*p = c) != '\n')) {
  21. ++p;
  22. }
  23. if ((c == EOF) || (s == p)) {
  24. s = NULL;
  25. } else {
  26. *p = 0;
  27. }
  28. __STDIO_AUTO_THREADUNLOCK(stdin);
  29. return s;
  30. }