OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / stdio / perror.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(fprintf)
11 libc_hidden_proto(__glibc_strerror_r)
12
13 #ifdef __UCLIBC_MJN3_ONLY__
14 #warning CONSIDER: Increase buffer size for error message (non-%m case)?
15 #endif
16
17 void perror(register const char *s)
18 {
19         /* If the program is calling perror, it's a safe bet that printf and
20          * friends are used as well.  It is also possible that the calling
21          * program could buffer stderr, or reassign it. */
22
23         register const char *sep;
24
25         sep = ": ";
26         if (!(s && *s)) {                       /* Caller did not supply a prefix message */
27                 s = (sep += 2);                 /* or passed an empty string. */
28         }
29
30 #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
31         fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
32 #else
33         {
34                 char buf[64];
35                 fprintf(stderr, "%s%s%s\n", s, sep,
36                                 __glibc_strerror_r(errno, buf, sizeof(buf)));
37         }
38 #endif
39 }
40 libc_hidden_proto(perror)
41 libc_hidden_def(perror)