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 | |
| 12 | #ifdef __DO_UNLOCKED |
| 13 | |
| 14 | wchar_t *fgetws_unlocked(wchar_t *__restrict ws, int n, |
| 15 | FILE *__restrict stream) |
| 16 | { |
| 17 | register wchar_t *p = ws; |
| 18 | wint_t wi; |
| 19 | |
| 20 | __STDIO_STREAM_VALIDATE(stream); |
| 21 | |
| 22 | while ((n > 1) |
| 23 | && ((wi = fgetwc_unlocked(stream)) != WEOF) |
| 24 | && ((*p++ = wi) != '\n') |
| 25 | ) { |
| 26 | --n; |
| 27 | } |
| 28 | if (p == ws) { |
| 29 | /* TODO -- should we set errno? */ |
| 30 | /* if (n <= 0) { */ |
| 31 | /* errno = EINVAL; */ |
| 32 | /* } */ |
| 33 | return NULL; |
| 34 | } |
| 35 | *p = 0; |
| 36 | return ws; |
| 37 | } |
| 38 | libc_hidden_def(fgetws_unlocked) |
| 39 | |
| 40 | #ifndef __UCLIBC_HAS_THREADS__ |
| 41 | strong_alias(fgetws_unlocked,fgetws) |
| 42 | #endif |
| 43 | |
| 44 | #elif defined __UCLIBC_HAS_THREADS__ |
| 45 | |
| 46 | wchar_t *fgetws(wchar_t *__restrict ws, int n, FILE *__restrict stream) |
| 47 | { |
| 48 | wchar_t *retval; |
| 49 | __STDIO_AUTO_THREADLOCK_VAR; |
| 50 | |
| 51 | __STDIO_AUTO_THREADLOCK(stream); |
| 52 | |
| 53 | retval = fgetws_unlocked(ws, n, stream); |
| 54 | |
| 55 | __STDIO_AUTO_THREADUNLOCK(stream); |
| 56 | |
| 57 | return retval; |
| 58 | } |
| 59 | |
| 60 | #endif |