1 /* $NetBSD: errno2result.c,v 1.5 2014/12/10 04:38:01 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2011-2013 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.
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
, const char *file
, unsigned int line
) {
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
);
74 return (ISC_R_CONNECTIONRESET
);
77 return (ISC_R_NOTCONNECTED
);
81 return (ISC_R_TIMEDOUT
);
85 return (ISC_R_NORESOURCES
);
89 return (ISC_R_FAMILYNOSUPPORT
);
93 return (ISC_R_NETDOWN
);
97 return (ISC_R_HOSTDOWN
);
101 return (ISC_R_NETUNREACH
);
105 return (ISC_R_HOSTUNREACH
);
109 return (ISC_R_ADDRINUSE
);
112 return (ISC_R_ADDRNOTAVAIL
);
114 return (ISC_R_CONNREFUSED
);
116 isc__strerror(posixerrno
, strbuf
, sizeof(strbuf
));
117 UNEXPECTED_ERROR(file
, line
, "unable to convert errno "
118 "to isc_result: %d: %s",
121 * XXXDCL would be nice if perhaps this function could
122 * return the system's error string, so the caller
123 * might have something more descriptive than "unexpected
124 * error" to log with.
126 return (ISC_R_UNEXPECTED
);