xref: /csrg-svn/lib/libc/stdio/perror.c (revision 45646)
11974Swnj /*
235303Sbostic  * Copyright (c) 1988 Regents of the University of California.
335303Sbostic  * All rights reserved.
435303Sbostic  *
542625Sbostic  * %sccs.include.redist.c%
621351Sdist  */
721351Sdist 
826574Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*45646Sbostic static char sccsid[] = "@(#)perror.c	5.10 (Berkeley) 11/28/90";
1035303Sbostic #endif /* LIBC_SCCS and not lint */
1121351Sdist 
1213488Ssam #include <sys/types.h>
13*45646Sbostic #include <sys/errno.h>
1413488Ssam #include <sys/uio.h>
15*45646Sbostic #include <unistd.h>
16*45646Sbostic #include <string.h>
171974Swnj 
181974Swnj perror(s)
1913488Ssam 	char *s;
201974Swnj {
2137341Sbostic 	register struct iovec *v;
2213488Ssam 	struct iovec iov[4];
231974Swnj 
2437341Sbostic 	v = iov;
2513488Ssam 	if (s && *s) {
2613488Ssam 		v->iov_base = s;
2713488Ssam 		v->iov_len = strlen(s);
2813488Ssam 		v++;
2913488Ssam 		v->iov_base = ": ";
3013488Ssam 		v->iov_len = 2;
3113488Ssam 		v++;
321974Swnj 	}
3337341Sbostic 	v->iov_base = strerror(errno);
3413488Ssam 	v->iov_len = strlen(v->iov_base);
3513488Ssam 	v++;
3613488Ssam 	v->iov_base = "\n";
3713488Ssam 	v->iov_len = 1;
38*45646Sbostic 	(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
391974Swnj }
40