00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include <isc/result.h>
00025 #include <isc/strerror.h>
00026 #include <isc/util.h>
00027
00028 #include "errno2result.h"
00029
00030
00031
00032
00033
00034
00035
00036 isc_result_t
00037 isc___errno2result(int posixerrno, const char *file, unsigned int line) {
00038 char strbuf[ISC_STRERRORSIZE];
00039
00040 switch (posixerrno) {
00041 case ENOTDIR:
00042 case ELOOP:
00043 case EINVAL:
00044 case ENAMETOOLONG:
00045 case EBADF:
00046 return (ISC_R_INVALIDFILE);
00047 case ENOENT:
00048 return (ISC_R_FILENOTFOUND);
00049 case EACCES:
00050 case EPERM:
00051 return (ISC_R_NOPERM);
00052 case EEXIST:
00053 return (ISC_R_FILEEXISTS);
00054 case EIO:
00055 return (ISC_R_IOERROR);
00056 case ENOMEM:
00057 return (ISC_R_NOMEMORY);
00058 case ENFILE:
00059 case EMFILE:
00060 return (ISC_R_TOOMANYOPENFILES);
00061 #ifdef EOVERFLOW
00062 case EOVERFLOW:
00063 return (ISC_R_RANGE);
00064 #endif
00065 case EPIPE:
00066 #ifdef ECONNRESET
00067 case ECONNRESET:
00068 #endif
00069 #ifdef ECONNABORTED
00070 case ECONNABORTED:
00071 #endif
00072 return (ISC_R_CONNECTIONRESET);
00073 #ifdef ENOTCONN
00074 case ENOTCONN:
00075 return (ISC_R_NOTCONNECTED);
00076 #endif
00077 #ifdef ETIMEDOUT
00078 case ETIMEDOUT:
00079 return (ISC_R_TIMEDOUT);
00080 #endif
00081 #ifdef ENOBUFS
00082 case ENOBUFS:
00083 return (ISC_R_NORESOURCES);
00084 #endif
00085 #ifdef EAFNOSUPPORT
00086 case EAFNOSUPPORT:
00087 return (ISC_R_FAMILYNOSUPPORT);
00088 #endif
00089 #ifdef ENETDOWN
00090 case ENETDOWN:
00091 return (ISC_R_NETDOWN);
00092 #endif
00093 #ifdef EHOSTDOWN
00094 case EHOSTDOWN:
00095 return (ISC_R_HOSTDOWN);
00096 #endif
00097 #ifdef ENETUNREACH
00098 case ENETUNREACH:
00099 return (ISC_R_NETUNREACH);
00100 #endif
00101 #ifdef EHOSTUNREACH
00102 case EHOSTUNREACH:
00103 return (ISC_R_HOSTUNREACH);
00104 #endif
00105 #ifdef EADDRINUSE
00106 case EADDRINUSE:
00107 return (ISC_R_ADDRINUSE);
00108 #endif
00109 case EADDRNOTAVAIL:
00110 return (ISC_R_ADDRNOTAVAIL);
00111 case ECONNREFUSED:
00112 return (ISC_R_CONNREFUSED);
00113 default:
00114 isc__strerror(posixerrno, strbuf, sizeof(strbuf));
00115 UNEXPECTED_ERROR(file, line, "unable to convert errno "
00116 "to isc_result: %d: %s",
00117 posixerrno, strbuf);
00118
00119
00120
00121
00122
00123
00124 return (ISC_R_UNEXPECTED);
00125 }
00126 }