gets.c 790 B

123456789101112131415161718192021222324252627282930313233343536
  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. char *gets(char *s)
  11. {
  12. register char *p = s;
  13. int c;
  14. __STDIO_AUTO_THREADLOCK_VAR;
  15. __STDIO_AUTO_THREADLOCK(stdin);
  16. /* Note: don't worry about performance here... this shouldn't be used!
  17. * Therefore, force actual function call. */
  18. while (((c = __getchar_unlocked()) != EOF) && ((*p = c) != '\n')) {
  19. ++p;
  20. }
  21. if ((c == EOF) || (s == p)) {
  22. s = NULL;
  23. } else {
  24. *p = 0;
  25. }
  26. __STDIO_AUTO_THREADUNLOCK(stdin);
  27. return s;
  28. }