4 * Copyright (C) 2004, 2005, 2007 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 2007/06/19 23:47:18 tbox Exp */
26 #include <isc/result.h>
27 #include <isc/strerror.h>
30 #include "errno2result.h"
33 * Convert a POSIX errno value into an isc_result_t. The
34 * list of supported errno values is not complete; new users
35 * of this function should add any expected errors that are
39 isc__errno2result(int posixerrno
) {
40 char strbuf
[ISC_STRERRORSIZE
];
45 case EINVAL
: /* XXX sometimes this is not for files */
48 return (ISC_R_INVALIDFILE
);
50 return (ISC_R_FILENOTFOUND
);
53 return (ISC_R_NOPERM
);
55 return (ISC_R_FILEEXISTS
);
57 return (ISC_R_IOERROR
);
59 return (ISC_R_NOMEMORY
);
62 return (ISC_R_TOOMANYOPENFILES
);
70 return (ISC_R_CONNECTIONRESET
);
73 return (ISC_R_NOTCONNECTED
);
77 return (ISC_R_TIMEDOUT
);
81 return (ISC_R_NORESOURCES
);
85 return (ISC_R_FAMILYNOSUPPORT
);
89 return (ISC_R_NETDOWN
);
93 return (ISC_R_HOSTDOWN
);
97 return (ISC_R_NETUNREACH
);
101 return (ISC_R_HOSTUNREACH
);
105 return (ISC_R_ADDRINUSE
);
108 return (ISC_R_ADDRNOTAVAIL
);
110 return (ISC_R_CONNREFUSED
);
112 isc__strerror(posixerrno
, strbuf
, sizeof(strbuf
));
113 UNEXPECTED_ERROR(__FILE__
, __LINE__
,
114 "unable to convert errno "
115 "to isc_result: %d: %s",
118 * XXXDCL would be nice if perhaps this function could
119 * return the system's error string, so the caller
120 * might have something more descriptive than "unexpected
121 * error" to log with.
123 return (ISC_R_UNEXPECTED
);