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.
10 libc_hidden_proto(fgets_unlocked)
14 libc_hidden_proto(__fgetc_unlocked)
16 char *fgets_unlocked(char *__restrict s, int n,
17 register FILE * __restrict stream)
22 __STDIO_STREAM_VALIDATE(stream);
24 #ifdef __UCLIBC_MJN3_ONLY__
25 #warning CONSIDER: What should fgets do if n <= 0?
26 #endif /* __UCLIBC_MJN3_ONLY__ */
27 /* Should we assert here? Or set errno? Or just fail... */
29 /* __set_errno(EINVAL); */
36 if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream)) {
37 if ((*p++ = __STDIO_STREAM_BUFFER_GET(stream)) == '\n') {
41 if ((c = __fgetc_unlocked(stream)) == EOF) {
42 if (__FERROR_UNLOCKED(stream)) {
47 if ((*p++ = c) == '\n') {
53 #ifdef __UCLIBC_MJN3_ONLY__
54 #warning CONSIDER: If n==1 and not at EOF, should fgets return an empty string?
55 #endif /* __UCLIBC_MJN3_ONLY__ */
64 libc_hidden_def(fgets_unlocked)
66 #ifndef __UCLIBC_HAS_THREADS__
67 strong_alias(fgets_unlocked,fgets)
68 libc_hidden_proto(fgets)
69 libc_hidden_def(fgets)
72 #elif defined __UCLIBC_HAS_THREADS__
74 char *fgets(char *__restrict s, int n,
75 register FILE * __restrict stream)
78 __STDIO_AUTO_THREADLOCK_VAR;
80 __STDIO_AUTO_THREADLOCK(stream);
82 retval = fgets_unlocked(s, n, stream);
84 __STDIO_AUTO_THREADUNLOCK(stream);
88 libc_hidden_proto(fgets)
89 libc_hidden_def(fgets)