try to make display narrower
[unix-history] / usr / src / lib / libc / net / herror.c
CommitLineData
5b6e7185
KB
1/*
2 * Copyright (c) 1987 Regents of the University of California.
6b2f9dd0
KB
3 * All rights reserved.
4 *
269a7923 5 * %sccs.include.redist.c%
5b6e7185
KB
6 */
7
ebfe7813 8#if defined(LIBC_SCCS) && !defined(lint)
24fac7d8 9static char sccsid[] = "@(#)herror.c 6.6 (Berkeley) %G%";
6b2f9dd0 10#endif /* LIBC_SCCS and not lint */
5b6e7185
KB
11
12#include <sys/types.h>
13#include <sys/uio.h>
24fac7d8
KB
14#include <netdb.h>
15#include <unistd.h>
16#include <string.h>
5b6e7185
KB
17
18char *h_errlist[] = {
19 "Error 0",
20 "Unknown host", /* 1 HOST_NOT_FOUND */
21 "Host name lookup failure", /* 2 TRY_AGAIN */
22 "Unknown server error", /* 3 NO_RECOVERY */
23 "No address associated with name", /* 4 NO_ADDRESS */
24};
25int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
26
27extern int h_errno;
28
29/*
30 * herror --
31 * print the error indicated by the h_errno value.
32 */
24fac7d8 33void
5b6e7185 34herror(s)
24fac7d8 35 const char *s;
5b6e7185
KB
36{
37 struct iovec iov[4];
38 register struct iovec *v = iov;
39
40 if (s && *s) {
24fac7d8 41 v->iov_base = (char *)s;
5b6e7185
KB
42 v->iov_len = strlen(s);
43 v++;
44 v->iov_base = ": ";
45 v->iov_len = 2;
46 v++;
47 }
60fcc3d0
KB
48 v->iov_base = (u_int)h_errno < h_nerr ?
49 h_errlist[h_errno] : "Unknown error";
5b6e7185
KB
50 v->iov_len = strlen(v->iov_base);
51 v++;
52 v->iov_base = "\n";
53 v->iov_len = 1;
24fac7d8 54 writev(STDERR_FILENO, iov, (v - iov) + 1);
5b6e7185 55}