xref: /csrg-svn/lib/libc/stdio/perror.c (revision 21351)
11974Swnj /*
2*21351Sdist  * Copyright (c) 1980 Regents of the University of California.
3*21351Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21351Sdist  * specifies the terms and conditions for redistribution.
5*21351Sdist  */
6*21351Sdist 
7*21351Sdist #ifndef lint
8*21351Sdist static char sccsid[] = "@(#)perror.c	5.1 (Berkeley) 05/30/85";
9*21351Sdist #endif not lint
10*21351Sdist 
11*21351Sdist /*
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