blob: 8b943e46797f8de260a6606f7f701eb5972dbacd [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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#ifdef __UCLIBC_MJN3_ONLY__
12#warning CONSIDER: Increase buffer size for error message (non-%m case)?
13#endif
14
15void perror(register const char *s)
16{
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. */
20
21 register const char *sep;
22
23 sep = ": ";
24 if (!(s && *s)) { /* Caller did not supply a prefix message */
25 s = (sep += 2); /* or passed an empty string. */
26 }
27
28#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
29 fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
30#else
31 {
32 char buf[64];
33 fprintf(stderr, "%s%s%s\n", s, sep,
34 __glibc_strerror_r(errno, buf, sizeof(buf)));
35 }
36#endif
37}
38libc_hidden_def(perror)