1 /* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)perror.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 #include <sys/uio.h> 14 #include <unistd.h> 15 #include <errno.h> 16 #include <stdio.h> 17 #include <string.h> 18 19 void 20 perror(s) 21 const char *s; 22 { 23 register struct iovec *v; 24 struct iovec iov[4]; 25 26 v = iov; 27 if (s && *s) { 28 v->iov_base = (char *)s; 29 v->iov_len = strlen(s); 30 v++; 31 v->iov_base = ": "; 32 v->iov_len = 2; 33 v++; 34 } 35 v->iov_base = strerror(errno); 36 v->iov_len = strlen(v->iov_base); 37 v++; 38 v->iov_base = "\n"; 39 v->iov_len = 1; 40 (void)writev(STDERR_FILENO, iov, (v - iov) + 1); 41 } 42