xref: /csrg-svn/lib/libc/stdio/perror.c (revision 42625)
11974Swnj /*
235303Sbostic  * Copyright (c) 1988 Regents of the University of California.
335303Sbostic  * All rights reserved.
435303Sbostic  *
5*42625Sbostic  * %sccs.include.redist.c%
621351Sdist  */
721351Sdist 
826574Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*42625Sbostic static char sccsid[] = "@(#)perror.c	5.9 (Berkeley) 06/01/90";
1035303Sbostic #endif /* LIBC_SCCS and not lint */
1121351Sdist 
1213488Ssam #include <sys/types.h>
1313488Ssam #include <sys/uio.h>
141974Swnj 
151974Swnj perror(s)
1613488Ssam 	char *s;
171974Swnj {
1837341Sbostic 	extern int errno;
1937341Sbostic 	register struct iovec *v;
2013488Ssam 	struct iovec iov[4];
2137341Sbostic 	char *strerror();
221974Swnj 
2337341Sbostic 	v = iov;
2413488Ssam 	if (s && *s) {
2513488Ssam 		v->iov_base = s;
2613488Ssam 		v->iov_len = strlen(s);
2713488Ssam 		v++;
2813488Ssam 		v->iov_base = ": ";
2913488Ssam 		v->iov_len = 2;
3013488Ssam 		v++;
311974Swnj 	}
3237341Sbostic 	v->iov_base = strerror(errno);
3313488Ssam 	v->iov_len = strlen(v->iov_base);
3413488Ssam 	v++;
3513488Ssam 	v->iov_base = "\n";
3613488Ssam 	v->iov_len = 1;
3735303Sbostic 	(void)writev(2, iov, (v - iov) + 1);
381974Swnj }
39