getchar.c 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. libc_hidden_def(getchar_unlocked)
  20. #ifndef __UCLIBC_HAS_THREADS__
  21. strong_alias(getchar_unlocked,getchar)
  22. #endif
  23. #elif defined __UCLIBC_HAS_THREADS__
  24. int getchar(void)
  25. {
  26. register FILE *stream = stdin;
  27. if (stream->__user_locking != 0) {
  28. return __GETC_UNLOCKED_MACRO(stream);
  29. } else {
  30. int retval;
  31. __STDIO_ALWAYS_THREADLOCK(stream);
  32. retval = __GETC_UNLOCKED_MACRO(stream);
  33. __STDIO_ALWAYS_THREADUNLOCK(stream);
  34. return retval;
  35. }
  36. }
  37. #endif