xref: /original-bsd/lib/libc/stdio/perror.c (revision 237fdba6)
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.9 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/uio.h>
14 
15 perror(s)
16 	char *s;
17 {
18 	extern int errno;
19 	register struct iovec *v;
20 	struct iovec iov[4];
21 	char *strerror();
22 
23 	v = iov;
24 	if (s && *s) {
25 		v->iov_base = s;
26 		v->iov_len = strlen(s);
27 		v++;
28 		v->iov_base = ": ";
29 		v->iov_len = 2;
30 		v++;
31 	}
32 	v->iov_base = strerror(errno);
33 	v->iov_len = strlen(v->iov_base);
34 	v++;
35 	v->iov_base = "\n";
36 	v->iov_len = 1;
37 	(void)writev(2, iov, (v - iov) + 1);
38 }
39