lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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 | |
| 8 | #include "_stdio.h" |
| 9 | |
| 10 | |
| 11 | #undef getchar |
| 12 | #ifdef __DO_UNLOCKED |
| 13 | |
| 14 | /* the only use of the hidden getchar_unlocked is in gets.c */ |
| 15 | #undef getchar_unlocked |
| 16 | int getchar_unlocked(void) |
| 17 | { |
| 18 | register FILE *stream = stdin; |
| 19 | |
| 20 | return __GETC_UNLOCKED_MACRO(stream); |
| 21 | } |
| 22 | libc_hidden_def(getchar_unlocked) |
| 23 | |
| 24 | #ifndef __UCLIBC_HAS_THREADS__ |
| 25 | strong_alias(getchar_unlocked,getchar) |
| 26 | #endif |
| 27 | |
| 28 | #elif defined __UCLIBC_HAS_THREADS__ |
| 29 | |
| 30 | int getchar(void) |
| 31 | { |
| 32 | register FILE *stream = stdin; |
| 33 | |
| 34 | if (stream->__user_locking != 0) { |
| 35 | return __GETC_UNLOCKED_MACRO(stream); |
| 36 | } else { |
| 37 | int retval; |
| 38 | __STDIO_ALWAYS_THREADLOCK(stream); |
| 39 | retval = __GETC_UNLOCKED_MACRO(stream); |
| 40 | __STDIO_ALWAYS_THREADUNLOCK(stream); |
| 41 | return retval; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | #endif |