summaryrefslogtreecommitdiff
path: root/libc/stdio/perror.c
blob: 04cd688d829b184da65d5b2001af8f74f4176a08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <errno.h>

/*
 * Manuel Novoa III           Feb 2001
 *
 * Replaced old version that did write(2,...)'s with a version using
 * stream functions.  If the program is calling perror, it's a safe
 * bet that printf and friends are used as well.  It is also possible
 * that the calling program could buffer stderr, or reassign it.
 * Also, the old version did not conform the standards when the 
 * passed char * was either NULL or pointed to an empty string.
 */

void perror(__const char *str)
{
	static const char perror_str[] = ": ";
	const char *sep;

	sep = perror_str;
	if (!(str && *str)) {		/* Caller did not supply a prefix message */
		sep += 2;				/* or passed an empty string. */
		str = sep;
	}
	fprintf(stderr, "%s%s%s\n", str, sep, strerror(errno));
}