1 /* 2 * Copyright (c) 1987 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #if defined(LIBC_SCCS) && !defined(lint) 19 static char sccsid[] = "@(#)herror.c 6.3 (Berkeley) 06/27/88"; 20 #endif /* LIBC_SCCS and not lint */ 21 22 #include <sys/types.h> 23 #include <sys/uio.h> 24 25 char *h_errlist[] = { 26 "Error 0", 27 "Unknown host", /* 1 HOST_NOT_FOUND */ 28 "Host name lookup failure", /* 2 TRY_AGAIN */ 29 "Unknown server error", /* 3 NO_RECOVERY */ 30 "No address associated with name", /* 4 NO_ADDRESS */ 31 }; 32 int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 33 34 extern int h_errno; 35 36 /* 37 * herror -- 38 * print the error indicated by the h_errno value. 39 */ 40 herror(s) 41 char *s; 42 { 43 struct iovec iov[4]; 44 register struct iovec *v = iov; 45 46 if (s && *s) { 47 v->iov_base = s; 48 v->iov_len = strlen(s); 49 v++; 50 v->iov_base = ": "; 51 v->iov_len = 2; 52 v++; 53 } 54 v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error"; 55 v->iov_len = strlen(v->iov_base); 56 v++; 57 v->iov_base = "\n"; 58 v->iov_len = 1; 59 writev(2, iov, (v - iov) + 1); 60 } 61