4 * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: errno2result.c,v 1.17 2008/09/12 04:46:25 marka Exp */
25 #include "errno2result.h"
26 #include <isc/result.h>
27 #include <isc/strerror.h>
31 * Convert a POSIX errno value into an isc_result_t. The
32 * list of supported errno values is not complete; new users
33 * of this function should add any expected errors that are
37 isc__errno2resultx(int posixerrno
, const char *file
, int line
) {
38 char strbuf
[ISC_STRERRORSIZE
];
44 case EINVAL
: /* XXX sometimes this is not for files */
49 return (ISC_R_INVALIDFILE
);
51 return (ISC_R_FILENOTFOUND
);
55 return (ISC_R_NOPERM
);
57 return (ISC_R_FILEEXISTS
);
59 return (ISC_R_IOERROR
);
61 return (ISC_R_NOMEMORY
);
65 return (ISC_R_TOOMANYOPENFILES
);
67 return (ISC_R_CANCELED
);
68 case ERROR_CONNECTION_REFUSED
:
70 return (ISC_R_CONNREFUSED
);
72 case ERROR_CONNECTION_INVALID
:
73 return (ISC_R_NOTCONNECTED
);
74 case ERROR_HOST_UNREACHABLE
:
76 return (ISC_R_HOSTUNREACH
);
77 case ERROR_NETWORK_UNREACHABLE
:
79 return (ISC_R_NETUNREACH
);
80 case ERROR_NO_NETWORK
:
81 return (ISC_R_NETUNREACH
);
82 case ERROR_PORT_UNREACHABLE
:
83 return (ISC_R_HOSTUNREACH
);
84 case ERROR_SEM_TIMEOUT
:
85 return (ISC_R_TIMEDOUT
);
90 case ERROR_OPERATION_ABORTED
:
91 case ERROR_CONNECTION_ABORTED
:
92 case ERROR_REQUEST_ABORTED
:
93 return (ISC_R_CONNECTIONRESET
);
94 case WSAEADDRNOTAVAIL
:
95 return (ISC_R_ADDRNOTAVAIL
);
96 case ERROR_NETNAME_DELETED
:
98 return (ISC_R_NETUNREACH
);
100 return (ISC_R_HOSTUNREACH
);
102 return (ISC_R_NORESOURCES
);
104 isc__strerror(posixerrno
, strbuf
, sizeof(strbuf
));
105 UNEXPECTED_ERROR(file
, line
, "unable to convert errno "
106 "to isc_result: %d: %s", posixerrno
, strbuf
);
108 * XXXDCL would be nice if perhaps this function could
109 * return the system's error string, so the caller
110 * might have something more descriptive than "unexpected
111 * error" to log with.
113 return (ISC_R_UNEXPECTED
);