Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / unix / errno2result.c
blob9b1eb88d6728b5f96d6559d448445646947adeb2
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: errno2result.c,v 1.8.2.5 2004/03/09 06:12:09 marka Exp $ */
20 #include <config.h>
22 #include <isc/result.h>
23 #include <isc/strerror.h>
24 #include <isc/util.h>
26 #include "errno2result.h"
29 * Convert a POSIX errno value into an isc_result_t. The
30 * list of supported errno values is not complete; new users
31 * of this function should add any expected errors that are
32 * not already there.
34 isc_result_t
35 isc__errno2result(int posixerrno) {
36 char strbuf[ISC_STRERRORSIZE];
38 switch (posixerrno) {
39 case ENOTDIR:
40 case ELOOP:
41 case EINVAL: /* XXX sometimes this is not for files */
42 case ENAMETOOLONG:
43 case EBADF:
44 return (ISC_R_INVALIDFILE);
45 case ENOENT:
46 return (ISC_R_FILENOTFOUND);
47 case EACCES:
48 case EPERM:
49 return (ISC_R_NOPERM);
50 case EEXIST:
51 return (ISC_R_FILEEXISTS);
52 case EIO:
53 return (ISC_R_IOERROR);
54 case ENOMEM:
55 return (ISC_R_NOMEMORY);
56 case ENFILE:
57 case EMFILE:
58 return (ISC_R_TOOMANYOPENFILES);
59 case EPIPE:
60 #ifdef ECONNRESET
61 case ECONNRESET:
62 #endif
63 #ifdef ECONNABORTED
64 case ECONNABORTED:
65 #endif
66 return (ISC_R_CONNECTIONRESET);
67 #ifdef ENOTCONN
68 case ENOTCONN:
69 return (ISC_R_NOTCONNECTED);
70 #endif
71 #ifdef ETIMEDOUT
72 case ETIMEDOUT:
73 return (ISC_R_TIMEDOUT);
74 #endif
75 #ifdef ENOBUFS
76 case ENOBUFS:
77 return (ISC_R_NORESOURCES);
78 #endif
79 #ifdef EAFNOSUPPORT
80 case EAFNOSUPPORT:
81 return (ISC_R_FAMILYNOSUPPORT);
82 #endif
83 #ifdef ENETDOWN
84 case ENETDOWN:
85 return (ISC_R_NETDOWN);
86 #endif
87 #ifdef EHOSTDOWN
88 case EHOSTDOWN:
89 return (ISC_R_HOSTDOWN);
90 #endif
91 #ifdef ENETUNREACH
92 case ENETUNREACH:
93 return (ISC_R_NETUNREACH);
94 #endif
95 #ifdef EHOSTUNREACH
96 case EHOSTUNREACH:
97 return (ISC_R_HOSTUNREACH);
98 #endif
99 #ifdef EADDRINUSE
100 case EADDRINUSE:
101 return (ISC_R_ADDRINUSE);
102 #endif
103 case EADDRNOTAVAIL:
104 return (ISC_R_ADDRNOTAVAIL);
105 case ECONNREFUSED:
106 return (ISC_R_CONNREFUSED);
107 default:
108 isc__strerror(posixerrno, strbuf, sizeof(strbuf));
109 UNEXPECTED_ERROR(__FILE__, __LINE__,
110 "unable to convert errno "
111 "to isc_result: %d: %s",
112 posixerrno, strbuf);
114 * XXXDCL would be nice if perhaps this function could
115 * return the system's error string, so the caller
116 * might have something more descriptive than "unexpected
117 * error" to log with.
119 return (ISC_R_UNEXPECTED);