errno2result.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2011-2013  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 /*! \file */
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  * Convert a POSIX errno value into an isc_result_t.  The
00032  * list of supported errno values is not complete; new users
00033  * of this function should add any expected errors that are
00034  * not already there.
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:            /* XXX sometimes this is not for files */
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                  * XXXDCL would be nice if perhaps this function could
00120                  * return the system's error string, so the caller
00121                  * might have something more descriptive than "unexpected
00122                  * error" to log with.
00123                  */
00124                 return (ISC_R_UNEXPECTED);
00125         }
00126 }

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha