2 * Copyright (C) 2004, 2005, 2007 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 2007/06/19 23:47:18 tbox Exp $ */
24 #include <isc/result.h>
25 #include <isc/strerror.h>
28 #include "errno2result.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__errno2result(int posixerrno) {
38 char strbuf[ISC_STRERRORSIZE];
43 case EINVAL: /* XXX sometimes this is not for files */
46 return (ISC_R_INVALIDFILE);
48 return (ISC_R_FILENOTFOUND);
51 return (ISC_R_NOPERM);
53 return (ISC_R_FILEEXISTS);
55 return (ISC_R_IOERROR);
57 return (ISC_R_NOMEMORY);
60 return (ISC_R_TOOMANYOPENFILES);
68 return (ISC_R_CONNECTIONRESET);
71 return (ISC_R_NOTCONNECTED);
75 return (ISC_R_TIMEDOUT);
79 return (ISC_R_NORESOURCES);
83 return (ISC_R_FAMILYNOSUPPORT);
87 return (ISC_R_NETDOWN);
91 return (ISC_R_HOSTDOWN);
95 return (ISC_R_NETUNREACH);
99 return (ISC_R_HOSTUNREACH);
103 return (ISC_R_ADDRINUSE);
106 return (ISC_R_ADDRNOTAVAIL);
108 return (ISC_R_CONNREFUSED);
110 isc__strerror(posixerrno, strbuf, sizeof(strbuf));
111 UNEXPECTED_ERROR(__FILE__, __LINE__,
112 "unable to convert errno "
113 "to isc_result: %d: %s",
116 * XXXDCL would be nice if perhaps this function could
117 * return the system's error string, so the caller
118 * might have something more descriptive than "unexpected
119 * error" to log with.
121 return (ISC_R_UNEXPECTED);