getchar.c 946 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. libc_hidden_proto(__fgetc_unlocked)
  9. #undef getchar
  10. #ifdef __DO_UNLOCKED
  11. /* the only use of the hidden getchar_unlocked is in gets.c */
  12. #undef getchar_unlocked
  13. libc_hidden_proto(getchar_unlocked)
  14. int getchar_unlocked(void)
  15. {
  16. register FILE *stream = stdin;
  17. return __GETC_UNLOCKED_MACRO(stream);
  18. }
  19. #ifndef __UCLIBC_HAS_THREADS__
  20. strong_alias(getchar_unlocked,getchar)
  21. #endif
  22. #elif defined __UCLIBC_HAS_THREADS__
  23. int getchar(void)
  24. {
  25. register FILE *stream = stdin;
  26. if (stream->__user_locking != 0) {
  27. return __GETC_UNLOCKED_MACRO(stream);
  28. } else {
  29. int retval;
  30. __STDIO_ALWAYS_THREADLOCK(stream);
  31. retval = __GETC_UNLOCKED_MACRO(stream);
  32. __STDIO_ALWAYS_THREADUNLOCK(stream);
  33. return retval;
  34. }
  35. }
  36. #endif