OSDN Git Service

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