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 
perror(register const char * s)10 void perror(register const char *s)
11 {
12 	/* If the program is calling perror, it's a safe bet that printf and
13 	 * friends are used as well.  It is also possible that the calling
14 	 * program could buffer stderr, or reassign it. */
15 
16 	register const char *sep;
17 
18 	sep = ": ";
19 	if (!(s && *s)) {			/* Caller did not supply a prefix message */
20 		s = (sep += 2);			/* or passed an empty string. */
21 	}
22 
23 #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
24 	fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
25 #else
26 	{
27 		char buf[64];
28 		fprintf(stderr, "%s%s%s\n", s, sep,
29 				__glibc_strerror_r(errno, buf, sizeof(buf)));
30 	}
31 #endif
32 }
33 libc_hidden_def(perror)
34