getchar.c 908 B

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