2 * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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.17 2008/09/12 04:46:25 marka Exp $ */
23 #include "errno2result.h"
24 #include <isc/result.h>
25 #include <isc/strerror.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
35 isc__errno2resultx(int posixerrno, const char *file, int line) {
36 char strbuf[ISC_STRERRORSIZE];
42 case EINVAL: /* XXX sometimes this is not for files */
47 return (ISC_R_INVALIDFILE);
49 return (ISC_R_FILENOTFOUND);
53 return (ISC_R_NOPERM);
55 return (ISC_R_FILEEXISTS);
57 return (ISC_R_IOERROR);
59 return (ISC_R_NOMEMORY);
63 return (ISC_R_TOOMANYOPENFILES);
65 return (ISC_R_CANCELED);
66 case ERROR_CONNECTION_REFUSED:
68 return (ISC_R_CONNREFUSED);
70 case ERROR_CONNECTION_INVALID:
71 return (ISC_R_NOTCONNECTED);
72 case ERROR_HOST_UNREACHABLE:
74 return (ISC_R_HOSTUNREACH);
75 case ERROR_NETWORK_UNREACHABLE:
77 return (ISC_R_NETUNREACH);
78 case ERROR_NO_NETWORK:
79 return (ISC_R_NETUNREACH);
80 case ERROR_PORT_UNREACHABLE:
81 return (ISC_R_HOSTUNREACH);
82 case ERROR_SEM_TIMEOUT:
83 return (ISC_R_TIMEDOUT);
88 case ERROR_OPERATION_ABORTED:
89 case ERROR_CONNECTION_ABORTED:
90 case ERROR_REQUEST_ABORTED:
91 return (ISC_R_CONNECTIONRESET);
92 case WSAEADDRNOTAVAIL:
93 return (ISC_R_ADDRNOTAVAIL);
94 case ERROR_NETNAME_DELETED:
96 return (ISC_R_NETUNREACH);
98 return (ISC_R_HOSTUNREACH);
100 return (ISC_R_NORESOURCES);
102 isc__strerror(posixerrno, strbuf, sizeof(strbuf));
103 UNEXPECTED_ERROR(file, line, "unable to convert errno "
104 "to isc_result: %d: %s", posixerrno, strbuf);
106 * XXXDCL would be nice if perhaps this function could
107 * return the system's error string, so the caller
108 * might have something more descriptive than "unexpected
109 * error" to log with.
111 return (ISC_R_UNEXPECTED);