OSDN Git Service

mkostemp: fix implementation
[uclinux-h8/uClibc.git] / libc / stdio / puts.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
11 int puts(register const char * __restrict s)
12 {
13         register FILE *stream = stdout; /* This helps bcc optimize. */
14         int n;
15         __STDIO_AUTO_THREADLOCK_VAR;
16
17         __STDIO_AUTO_THREADLOCK(stream);
18
19         /* Note: Don't try to optimize by switching to FBF until the newline.
20          * If the string itself contained a newline a write error occurred,
21          * then we could have a newline in the buffer of an LBF stream. */
22
23         /* Note: Nonportable as fputs need only return nonnegative on success. */
24         if ((n = fputs_unlocked(s, stream)) != EOF) {
25                 ++n;
26                 if (__fputc_unlocked('\n', stream) == EOF) {
27                         n = EOF;
28                 }
29         }
30
31         __STDIO_AUTO_THREADUNLOCK(stream);
32
33         return n;
34 }