132631Sbostic /* 232631Sbostic * Copyright (c) 1987 Regents of the University of California. 333679Sbostic * All rights reserved. 433679Sbostic * 533679Sbostic * Redistribution and use in source and binary forms are permitted 6*34816Sbostic * provided that the above copyright notice and this paragraph are 7*34816Sbostic * duplicated in all such forms and that any documentation, 8*34816Sbostic * advertising materials, and other materials related to such 9*34816Sbostic * distribution and use acknowledge that the software was developed 10*34816Sbostic * by the University of California, Berkeley. The name of the 11*34816Sbostic * University may not be used to endorse or promote products derived 12*34816Sbostic * from this software without specific prior written permission. 13*34816Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34816Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34816Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1632631Sbostic */ 1732631Sbostic 1832755Skarels #if defined(LIBC_SCCS) && !defined(lint) 19*34816Sbostic static char sccsid[] = "@(#)herror.c 6.3 (Berkeley) 06/27/88"; 2033679Sbostic #endif /* LIBC_SCCS and not lint */ 2132631Sbostic 2232631Sbostic #include <sys/types.h> 2332631Sbostic #include <sys/uio.h> 2432631Sbostic 2532631Sbostic char *h_errlist[] = { 2632631Sbostic "Error 0", 2732631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 2832631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 2932631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 3032631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 3132631Sbostic }; 3232631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 3332631Sbostic 3432631Sbostic extern int h_errno; 3532631Sbostic 3632631Sbostic /* 3732631Sbostic * herror -- 3832631Sbostic * print the error indicated by the h_errno value. 3932631Sbostic */ 4032631Sbostic herror(s) 4132631Sbostic char *s; 4232631Sbostic { 4332631Sbostic struct iovec iov[4]; 4432631Sbostic register struct iovec *v = iov; 4532631Sbostic 4632631Sbostic if (s && *s) { 4732631Sbostic v->iov_base = s; 4832631Sbostic v->iov_len = strlen(s); 4932631Sbostic v++; 5032631Sbostic v->iov_base = ": "; 5132631Sbostic v->iov_len = 2; 5232631Sbostic v++; 5332631Sbostic } 5432631Sbostic v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error"; 5532631Sbostic v->iov_len = strlen(v->iov_base); 5632631Sbostic v++; 5732631Sbostic v->iov_base = "\n"; 5832631Sbostic v->iov_len = 1; 5932631Sbostic writev(2, iov, (v - iov) + 1); 6032631Sbostic } 61