libc: fix MIPS N64 fork
[uclibc-ng.git] / libc / stdio / perror.c
blob8b943e46797f8de260a6606f7f701eb5972dbacd
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.
6 */
8 #include "_stdio.h"
11 #ifdef __UCLIBC_MJN3_ONLY__
12 #warning CONSIDER: Increase buffer size for error message (non-%m case)?
13 #endif
15 void perror(register const char *s)
17 /* If the program is calling perror, it's a safe bet that printf and
18 * friends are used as well. It is also possible that the calling
19 * program could buffer stderr, or reassign it. */
21 register const char *sep;
23 sep = ": ";
24 if (!(s && *s)) { /* Caller did not supply a prefix message */
25 s = (sep += 2); /* or passed an empty string. */
28 #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
29 fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
30 #else
32 char buf[64];
33 fprintf(stderr, "%s%s%s\n", s, sep,
34 __glibc_strerror_r(errno, buf, sizeof(buf)));
36 #endif
38 libc_hidden_def(perror)