/src/ntp-dev/lib/isc/unix/errno2result.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2004, 2005, 2007, 2011, 2012 Internet Systems Consortium, Inc. ("ISC") |
3 | | * Copyright (C) 2000-2002 Internet Software Consortium. |
4 | | * |
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. |
8 | | * |
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. |
16 | | */ |
17 | | |
18 | | /* $Id$ */ |
19 | | |
20 | | /*! \file */ |
21 | | |
22 | | #include <config.h> |
23 | | |
24 | | #include <isc/result.h> |
25 | | #include <isc/strerror.h> |
26 | | #include <isc/util.h> |
27 | | |
28 | | #include "errno2result.h" |
29 | | |
30 | | /*% |
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 |
34 | | * not already there. |
35 | | */ |
36 | | isc_result_t |
37 | 0 | isc___errno2result(int posixerrno, const char *file, unsigned int line) { |
38 | 0 | char strbuf[ISC_STRERRORSIZE]; |
39 | |
|
40 | 0 | switch (posixerrno) { |
41 | 0 | case ENOTDIR: |
42 | 0 | case ELOOP: |
43 | 0 | case EINVAL: /* XXX sometimes this is not for files */ |
44 | 0 | case ENAMETOOLONG: |
45 | 0 | case EBADF: |
46 | 0 | return (ISC_R_INVALIDFILE); |
47 | 0 | case ENOENT: |
48 | 0 | return (ISC_R_FILENOTFOUND); |
49 | 0 | case EACCES: |
50 | 0 | case EPERM: |
51 | 0 | return (ISC_R_NOPERM); |
52 | 0 | case EEXIST: |
53 | 0 | return (ISC_R_FILEEXISTS); |
54 | 0 | case EIO: |
55 | 0 | return (ISC_R_IOERROR); |
56 | 0 | case ENOMEM: |
57 | 0 | return (ISC_R_NOMEMORY); |
58 | 0 | case ENFILE: |
59 | 0 | case EMFILE: |
60 | 0 | return (ISC_R_TOOMANYOPENFILES); |
61 | 0 | case EPIPE: |
62 | 0 | #ifdef ECONNRESET |
63 | 0 | case ECONNRESET: |
64 | 0 | #endif |
65 | 0 | #ifdef ECONNABORTED |
66 | 0 | case ECONNABORTED: |
67 | 0 | #endif |
68 | 0 | return (ISC_R_CONNECTIONRESET); |
69 | 0 | #ifdef ENOTCONN |
70 | 0 | case ENOTCONN: |
71 | 0 | return (ISC_R_NOTCONNECTED); |
72 | 0 | #endif |
73 | 0 | #ifdef ETIMEDOUT |
74 | 0 | case ETIMEDOUT: |
75 | 0 | return (ISC_R_TIMEDOUT); |
76 | 0 | #endif |
77 | 0 | #ifdef ENOBUFS |
78 | 0 | case ENOBUFS: |
79 | 0 | return (ISC_R_NORESOURCES); |
80 | 0 | #endif |
81 | 0 | #ifdef EAFNOSUPPORT |
82 | 0 | case EAFNOSUPPORT: |
83 | 0 | return (ISC_R_FAMILYNOSUPPORT); |
84 | 0 | #endif |
85 | 0 | #ifdef ENETDOWN |
86 | 0 | case ENETDOWN: |
87 | 0 | return (ISC_R_NETDOWN); |
88 | 0 | #endif |
89 | 0 | #ifdef EHOSTDOWN |
90 | 0 | case EHOSTDOWN: |
91 | 0 | return (ISC_R_HOSTDOWN); |
92 | 0 | #endif |
93 | 0 | #ifdef ENETUNREACH |
94 | 0 | case ENETUNREACH: |
95 | 0 | return (ISC_R_NETUNREACH); |
96 | 0 | #endif |
97 | 0 | #ifdef EHOSTUNREACH |
98 | 0 | case EHOSTUNREACH: |
99 | 0 | return (ISC_R_HOSTUNREACH); |
100 | 0 | #endif |
101 | 0 | #ifdef EADDRINUSE |
102 | 0 | case EADDRINUSE: |
103 | 0 | return (ISC_R_ADDRINUSE); |
104 | 0 | #endif |
105 | 0 | case EADDRNOTAVAIL: |
106 | 0 | return (ISC_R_ADDRNOTAVAIL); |
107 | 0 | case ECONNREFUSED: |
108 | 0 | return (ISC_R_CONNREFUSED); |
109 | 0 | default: |
110 | 0 | isc__strerror(posixerrno, strbuf, sizeof(strbuf)); |
111 | 0 | UNEXPECTED_ERROR(file, line, "unable to convert errno " |
112 | 0 | "to isc_result: %d: %s", |
113 | 0 | posixerrno, strbuf); |
114 | | /* |
115 | | * XXXDCL would be nice if perhaps this function could |
116 | | * return the system's error string, so the caller |
117 | | * might have something more descriptive than "unexpected |
118 | | * error" to log with. |
119 | | */ |
120 | 0 | return (ISC_R_UNEXPECTED); |
121 | 0 | } |
122 | 0 | } |