xref: /csrg-svn/lib/libc/stdio/perror.c (revision 35303)
11974Swnj /*
2*35303Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*35303Sbostic  * All rights reserved.
4*35303Sbostic  *
5*35303Sbostic  * Redistribution and use in source and binary forms are permitted
6*35303Sbostic  * provided that the above copyright notice and this paragraph are
7*35303Sbostic  * duplicated in all such forms and that any documentation,
8*35303Sbostic  * advertising materials, and other materials related to such
9*35303Sbostic  * distribution and use acknowledge that the software was developed
10*35303Sbostic  * by the University of California, Berkeley.  The name of the
11*35303Sbostic  * University may not be used to endorse or promote products derived
12*35303Sbostic  * from this software without specific prior written permission.
13*35303Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*35303Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*35303Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1621351Sdist  */
1721351Sdist 
1826574Sdonn #if defined(LIBC_SCCS) && !defined(lint)
19*35303Sbostic static char sccsid[] = "@(#)perror.c	5.4 (Berkeley) 08/02/88";
20*35303Sbostic #endif /* LIBC_SCCS and not lint */
2121351Sdist 
2213488Ssam #include <sys/types.h>
2313488Ssam #include <sys/uio.h>
241974Swnj 
251974Swnj int	errno;
2632293Sbostic extern int	sys_nerr;
2732293Sbostic extern char	*sys_errlist[];
281974Swnj perror(s)
2913488Ssam 	char *s;
301974Swnj {
3113488Ssam 	struct iovec iov[4];
3213488Ssam 	register struct iovec *v = iov;
331974Swnj 
3413488Ssam 	if (s && *s) {
3513488Ssam 		v->iov_base = s;
3613488Ssam 		v->iov_len = strlen(s);
3713488Ssam 		v++;
3813488Ssam 		v->iov_base = ": ";
3913488Ssam 		v->iov_len = 2;
4013488Ssam 		v++;
411974Swnj 	}
4213488Ssam 	v->iov_base = errno < sys_nerr ? sys_errlist[errno] : "Unknown error";
4313488Ssam 	v->iov_len = strlen(v->iov_base);
4413488Ssam 	v++;
4513488Ssam 	v->iov_base = "\n";
4613488Ssam 	v->iov_len = 1;
47*35303Sbostic 	(void)writev(2, iov, (v - iov) + 1);
481974Swnj }
49