xref: /csrg-svn/lib/libc/stdio/perror.c (revision 26574)
11974Swnj /*
221351Sdist  * Copyright (c) 1980 Regents of the University of California.
321351Sdist  * All rights reserved.  The Berkeley software License Agreement
421351Sdist  * specifies the terms and conditions for redistribution.
521351Sdist  */
621351Sdist 
7*26574Sdonn #if defined(LIBC_SCCS) && !defined(lint)
8*26574Sdonn static char sccsid[] = "@(#)perror.c	5.2 (Berkeley) 03/09/86";
9*26574Sdonn #endif LIBC_SCCS and not lint
1021351Sdist 
1121351Sdist /*
121974Swnj  * Print the error indicated
131974Swnj  * in the cerror cell.
141974Swnj  */
1513488Ssam #include <sys/types.h>
1613488Ssam #include <sys/uio.h>
171974Swnj 
181974Swnj int	errno;
191974Swnj int	sys_nerr;
201974Swnj char	*sys_errlist[];
211974Swnj perror(s)
2213488Ssam 	char *s;
231974Swnj {
2413488Ssam 	struct iovec iov[4];
2513488Ssam 	register struct iovec *v = iov;
261974Swnj 
2713488Ssam 	if (s && *s) {
2813488Ssam 		v->iov_base = s;
2913488Ssam 		v->iov_len = strlen(s);
3013488Ssam 		v++;
3113488Ssam 		v->iov_base = ": ";
3213488Ssam 		v->iov_len = 2;
3313488Ssam 		v++;
341974Swnj 	}
3513488Ssam 	v->iov_base = errno < sys_nerr ? sys_errlist[errno] : "Unknown error";
3613488Ssam 	v->iov_len = strlen(v->iov_base);
3713488Ssam 	v++;
3813488Ssam 	v->iov_base = "\n";
3913488Ssam 	v->iov_len = 1;
4013488Ssam 	writev(2, iov, (v - iov) + 1);
411974Swnj }
42