OSDN Git Service

8a5fd4087b5062ebf53a3220cfdfdae2fef4066d
[uclinux-h8/uClibc.git] / libc / stdio / fputs.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(fputs_unlocked)
11
12 /* Experimentally off - libc_hidden_proto(strlen) */
13 libc_hidden_proto(fwrite_unlocked)
14
15 /* Note: The standard says fputs returns a nonnegative number on
16  * success.  In this implementation, we return the length of the
17  * string written on success.
18  */
19
20 #ifdef __DO_UNLOCKED
21
22 int fputs_unlocked(register const char * __restrict s,
23                                          FILE * __restrict stream)
24 {
25         size_t n = strlen(s);
26
27         return ((fwrite_unlocked(s, 1, n, stream) == n) ? n : EOF);
28 }
29 libc_hidden_def(fputs_unlocked)
30
31 #ifndef __UCLIBC_HAS_THREADS__
32 libc_hidden_proto(fputs)
33 strong_alias(fputs_unlocked,fputs)
34 libc_hidden_def(fputs)
35 #endif
36
37 #elif defined __UCLIBC_HAS_THREADS__
38
39 libc_hidden_proto(fputs)
40 int fputs(const char * __restrict s, register FILE * __restrict stream)
41 {
42         int retval;
43         __STDIO_AUTO_THREADLOCK_VAR;
44
45         __STDIO_AUTO_THREADLOCK(stream);
46
47         retval = fputs_unlocked(s, stream);
48
49         __STDIO_AUTO_THREADUNLOCK(stream);
50
51         return retval;
52 }
53 libc_hidden_def(fputs)
54
55 #endif