Commit | Line | Data |
---|---|---|
5b6e7185 KB |
1 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
7 | #ifndef lint | |
8 | char copyright[] = | |
9 | "@(#) Copyright (c) 1987 Regents of the University of California.\n\ | |
10 | All rights reserved.\n"; | |
11 | #endif /* !lint */ | |
12 | ||
13 | #ifndef lint | |
14 | static char sccsid[] = "@(#)herror.c 1.1 (Berkeley) %G%"; | |
15 | #endif /* !lint */ | |
16 | ||
17 | #include <sys/types.h> | |
18 | #include <sys/uio.h> | |
19 | ||
20 | char *h_errlist[] = { | |
21 | "Error 0", | |
22 | "Unknown host", /* 1 HOST_NOT_FOUND */ | |
23 | "Host name lookup failure", /* 2 TRY_AGAIN */ | |
24 | "Unknown server error", /* 3 NO_RECOVERY */ | |
25 | "No address associated with name", /* 4 NO_ADDRESS */ | |
26 | }; | |
27 | int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; | |
28 | ||
29 | extern int h_errno; | |
30 | ||
31 | /* | |
32 | * herror -- | |
33 | * print the error indicated by the h_errno value. | |
34 | */ | |
35 | herror(s) | |
36 | char *s; | |
37 | { | |
38 | struct iovec iov[4]; | |
39 | register struct iovec *v = iov; | |
40 | ||
41 | if (s && *s) { | |
42 | v->iov_base = s; | |
43 | v->iov_len = strlen(s); | |
44 | v++; | |
45 | v->iov_base = ": "; | |
46 | v->iov_len = 2; | |
47 | v++; | |
48 | } | |
49 | v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error"; | |
50 | v->iov_len = strlen(v->iov_base); | |
51 | v++; | |
52 | v->iov_base = "\n"; | |
53 | v->iov_len = 1; | |
54 | writev(2, iov, (v - iov) + 1); | |
55 | } |