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.
14 char *fgets_unlocked(char *__restrict s
, int n
,
15 register FILE * __restrict stream
)
20 __STDIO_STREAM_VALIDATE(stream
);
22 #ifdef __UCLIBC_MJN3_ONLY__
23 #warning CONSIDER: What should fgets do if n <= 0?
24 #endif /* __UCLIBC_MJN3_ONLY__ */
25 /* Should we assert here? Or set errno? Or just fail... */
27 /* __set_errno(EINVAL); */
34 if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream
)) {
35 if ((*p
++ = __STDIO_STREAM_BUFFER_GET(stream
)) == '\n') {
39 if ((c
= __fgetc_unlocked(stream
)) == EOF
) {
40 if (__FERROR_UNLOCKED(stream
)) {
45 if ((*p
++ = c
) == '\n') {
51 #ifdef __UCLIBC_MJN3_ONLY__
52 #warning CONSIDER: If n==1 and not at EOF, should fgets return an empty string?
53 #endif /* __UCLIBC_MJN3_ONLY__ */
62 libc_hidden_def(fgets_unlocked
)
64 #ifndef __UCLIBC_HAS_THREADS__
65 strong_alias(fgets_unlocked
,fgets
)
66 libc_hidden_def(fgets
)
69 #elif defined __UCLIBC_HAS_THREADS__
71 char *fgets(char *__restrict s
, int n
,
72 register FILE * __restrict stream
)
75 __STDIO_AUTO_THREADLOCK_VAR
;
77 __STDIO_AUTO_THREADLOCK(stream
);
79 retval
= fgets_unlocked(s
, n
, stream
);
81 __STDIO_AUTO_THREADUNLOCK(stream
);
85 libc_hidden_def(fgets
)