getchar.c 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #undef getchar_unlocked
  12. int getchar_unlocked(void)
  13. {
  14. register FILE *stream = stdin;
  15. return __GETC_UNLOCKED_MACRO(stream);
  16. }
  17. #ifndef __UCLIBC_HAS_THREADS__
  18. strong_alias(getchar_unlocked,getchar)
  19. #endif
  20. #elif defined __UCLIBC_HAS_THREADS__
  21. int getchar(void)
  22. {
  23. register FILE *stream = stdin;
  24. if (stream->__user_locking != 0) {
  25. return __GETC_UNLOCKED_MACRO(stream);
  26. } else {
  27. int retval;
  28. __STDIO_ALWAYS_THREADLOCK(stream);
  29. retval = __GETC_UNLOCKED_MACRO(stream);
  30. __STDIO_ALWAYS_THREADUNLOCK(stream);
  31. return retval;
  32. }
  33. }
  34. #endif