netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / fgetws.c
blobb59d74b15080e420b36b90fff00f6a0dab4436e7
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include "_stdio.h"
12 #ifdef __DO_UNLOCKED
14 wchar_t *fgetws_unlocked(wchar_t *__restrict ws, int n,
15 FILE *__restrict stream)
17 register wchar_t *p = ws;
18 wint_t wi;
20 __STDIO_STREAM_VALIDATE(stream);
22 while ((n > 1)
23 && ((wi = fgetwc_unlocked(stream)) != WEOF)
24 && ((*p++ = wi) != '\n')
25 ) {
26 --n;
28 if (p == ws) {
29 /* TODO -- should we set errno? */
30 /* if (n <= 0) { */
31 /* errno = EINVAL; */
32 /* } */
33 return NULL;
35 *p = 0;
36 return ws;
38 libc_hidden_def(fgetws_unlocked)
40 #ifndef __UCLIBC_HAS_THREADS__
41 strong_alias(fgetws_unlocked,fgetws)
42 #endif
44 #elif defined __UCLIBC_HAS_THREADS__
46 wchar_t *fgetws(wchar_t *__restrict ws, int n, FILE *__restrict stream)
48 wchar_t *retval;
49 __STDIO_AUTO_THREADLOCK_VAR;
51 __STDIO_AUTO_THREADLOCK(stream);
53 retval = fgetws_unlocked(ws, n, stream);
55 __STDIO_AUTO_THREADUNLOCK(stream);
57 return retval;
60 #endif