xref: /csrg-svn/lib/libc/stdio/perror.c (revision 61180)
11974Swnj /*
2*61180Sbostic  * Copyright (c) 1988, 1993
3*61180Sbostic  *	The Regents of the University of California.  All rights reserved.
435303Sbostic  *
542625Sbostic  * %sccs.include.redist.c%
621351Sdist  */
721351Sdist 
826574Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61180Sbostic static char sccsid[] = "@(#)perror.c	8.1 (Berkeley) 06/04/93";
1035303Sbostic #endif /* LIBC_SCCS and not lint */
1121351Sdist 
1213488Ssam #include <sys/types.h>
1313488Ssam #include <sys/uio.h>
1445646Sbostic #include <unistd.h>
1546611Sbostic #include <errno.h>
1646611Sbostic #include <stdio.h>
1745646Sbostic #include <string.h>
181974Swnj 
1946611Sbostic void
perror(s)201974Swnj perror(s)
2146611Sbostic 	const char *s;
221974Swnj {
2337341Sbostic 	register struct iovec *v;
2413488Ssam 	struct iovec iov[4];
251974Swnj 
2637341Sbostic 	v = iov;
2713488Ssam 	if (s && *s) {
2846611Sbostic 		v->iov_base = (char *)s;
2913488Ssam 		v->iov_len = strlen(s);
3013488Ssam 		v++;
3113488Ssam 		v->iov_base = ": ";
3213488Ssam 		v->iov_len = 2;
3313488Ssam 		v++;
341974Swnj 	}
3537341Sbostic 	v->iov_base = strerror(errno);
3613488Ssam 	v->iov_len = strlen(v->iov_base);
3713488Ssam 	v++;
3813488Ssam 	v->iov_base = "\n";
3913488Ssam 	v->iov_len = 1;
4045646Sbostic 	(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
411974Swnj }
42