perror.c revision 40731
1251881Speter/*
2251881Speter * Copyright (c) 1988, 1993
3251881Speter *	The Regents of the University of California.  All rights reserved.
4251881Speter *
5251881Speter * Redistribution and use in source and binary forms, with or without
6251881Speter * modification, are permitted provided that the following conditions
7251881Speter * are met:
8251881Speter * 1. Redistributions of source code must retain the above copyright
9251881Speter *    notice, this list of conditions and the following disclaimer.
10251881Speter * 2. Redistributions in binary form must reproduce the above copyright
11251881Speter *    notice, this list of conditions and the following disclaimer in the
12251881Speter *    documentation and/or other materials provided with the distribution.
13251881Speter * 3. All advertising materials mentioning features or use of this software
14251881Speter *    must display the following acknowledgement:
15251881Speter *	This product includes software developed by the University of
16251881Speter *	California, Berkeley and its contributors.
17251881Speter * 4. Neither the name of the University nor the names of its contributors
18251881Speter *    may be used to endorse or promote products derived from this software
19251881Speter *    without specific prior written permission.
20251881Speter *
21251881Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22251881Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23251881Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24251881Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25251881Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26251881Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27251881Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28251881Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29251881Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30251881Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31251881Speter * SUCH DAMAGE.
32251881Speter */
33251881Speter
34251881Speter#if defined(LIBC_SCCS) && !defined(lint)
35251881Speterstatic char sccsid[] = "@(#)perror.c	8.1 (Berkeley) 6/4/93";
36251881Speter#endif /* LIBC_SCCS and not lint */
37251881Speter
38251881Speter#include <sys/types.h>
39251881Speter#include <sys/uio.h>
40251881Speter#include <unistd.h>
41251881Speter#include <errno.h>
42251881Speter#include <stdio.h>
43251881Speter#include <string.h>
44251881Speter
45251881Spetervoid
46251881Speterperror(s)
47251881Speter	const char *s;
48251881Speter{
49251881Speter	register struct iovec *v;
50251881Speter	struct iovec iov[4];
51251881Speter
52251881Speter	v = iov;
53251881Speter	if (s != NULL && *s != '\0') {
54251881Speter		v->iov_base = (char *)s;
55251881Speter		v->iov_len = strlen(s);
56251881Speter		v++;
57251881Speter		v->iov_base = ": ";
58251881Speter		v->iov_len = 2;
59251881Speter		v++;
60251881Speter	}
61251881Speter	v->iov_base = strerror(errno);
62251881Speter	v->iov_len = strlen(v->iov_base);
63251881Speter	v++;
64251881Speter	v->iov_base = "\n";
65251881Speter	v->iov_len = 1;
66251881Speter	(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
67251881Speter}
68251881Speter