getchar.c 863 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. #undef getchar_unlocked
  9. #undef getchar
  10. #ifdef __DO_UNLOCKED
  11. int __getchar_unlocked(void)
  12. {
  13. register FILE *stream = stdin;
  14. return __GETC_UNLOCKED_MACRO(stream);
  15. }
  16. weak_alias(__getchar_unlocked,getchar_unlocked);
  17. #ifndef __UCLIBC_HAS_THREADS__
  18. weak_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