xref: /original-bsd/lib/libc/stdio/perror.c (revision baf24c0d)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)perror.c	5.10 (Berkeley) 11/28/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/errno.h>
14 #include <sys/uio.h>
15 #include <unistd.h>
16 #include <string.h>
17 
18 perror(s)
19 	char *s;
20 {
21 	register struct iovec *v;
22 	struct iovec iov[4];
23 
24 	v = iov;
25 	if (s && *s) {
26 		v->iov_base = s;
27 		v->iov_len = strlen(s);
28 		v++;
29 		v->iov_base = ": ";
30 		v->iov_len = 2;
31 		v++;
32 	}
33 	v->iov_base = strerror(errno);
34 	v->iov_len = strlen(v->iov_base);
35 	v++;
36 	v->iov_base = "\n";
37 	v->iov_len = 1;
38 	(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
39 }
40