errno2result.c revision 280849
191100Sdes/* 292289Sdes * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC") 391100Sdes * Copyright (C) 2000-2002 Internet Software Consortium. 491100Sdes * 591100Sdes * Permission to use, copy, modify, and/or distribute this software for any 699158Sdes * purpose with or without fee is hereby granted, provided that the above 799158Sdes * copyright notice and this permission notice appear in all copies. 899158Sdes * 991100Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 1091100Sdes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 1191100Sdes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 1291100Sdes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 1391100Sdes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 1491100Sdes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 1591100Sdes * PERFORMANCE OF THIS SOFTWARE. 1691100Sdes */ 1791100Sdes 1891100Sdes/* $Id: errno2result.c,v 1.17 2008/09/12 04:46:25 marka Exp $ */ 1991100Sdes 2091100Sdes#include <config.h> 2191100Sdes 2291100Sdes#include <winsock2.h> 2391100Sdes#include "errno2result.h" 2491100Sdes#include <isc/result.h> 2591100Sdes#include <isc/strerror.h> 2691100Sdes#include <isc/util.h> 2791100Sdes 2891100Sdes/* 2991100Sdes * Convert a POSIX errno value into an isc_result_t. The 3091100Sdes * list of supported errno values is not complete; new users 3191100Sdes * of this function should add any expected errors that are 3291100Sdes * not already there. 3391100Sdes */ 3499158Sdesisc_result_t 3591100Sdesisc__errno2resultx(int posixerrno, const char *file, int line) { 3691100Sdes char strbuf[ISC_STRERRORSIZE]; 3791100Sdes 3891100Sdes switch (posixerrno) { 3991100Sdes case ENOTDIR: 4091100Sdes case WSAELOOP: 4191100Sdes case WSAEINVAL: 4291100Sdes case EINVAL: /* XXX sometimes this is not for files */ 4391100Sdes case ENAMETOOLONG: 4491100Sdes case WSAENAMETOOLONG: 4591100Sdes case EBADF: 4691100Sdes case WSAEBADF: 4791100Sdes return (ISC_R_INVALIDFILE); 4891100Sdes case ENOENT: 4991100Sdes return (ISC_R_FILENOTFOUND); 5091100Sdes case EACCES: 5191100Sdes case WSAEACCES: 5291100Sdes case EPERM: 5391100Sdes return (ISC_R_NOPERM); 5491100Sdes case EEXIST: 5591100Sdes return (ISC_R_FILEEXISTS); 5691100Sdes case EIO: 5791100Sdes return (ISC_R_IOERROR); 5891100Sdes case ENOMEM: 5991100Sdes return (ISC_R_NOMEMORY); 6091100Sdes case ENFILE: 6191100Sdes case EMFILE: 6291100Sdes case WSAEMFILE: 6391100Sdes return (ISC_R_TOOMANYOPENFILES); 6491100Sdes case ERROR_CANCELLED: 6591100Sdes return (ISC_R_CANCELED); 66 case ERROR_CONNECTION_REFUSED: 67 case WSAECONNREFUSED: 68 return (ISC_R_CONNREFUSED); 69 case WSAENOTCONN: 70 case ERROR_CONNECTION_INVALID: 71 return (ISC_R_NOTCONNECTED); 72 case ERROR_HOST_UNREACHABLE: 73 case WSAEHOSTUNREACH: 74 return (ISC_R_HOSTUNREACH); 75 case ERROR_NETWORK_UNREACHABLE: 76 case WSAENETUNREACH: 77 return (ISC_R_NETUNREACH); 78 case ERROR_NO_NETWORK: 79 return (ISC_R_NETUNREACH); 80 case ERROR_PORT_UNREACHABLE: 81 return (ISC_R_HOSTUNREACH); 82 case ERROR_SEM_TIMEOUT: 83 return (ISC_R_TIMEDOUT); 84 case WSAECONNRESET: 85 case WSAENETRESET: 86 case WSAECONNABORTED: 87 case WSAEDISCON: 88 case ERROR_OPERATION_ABORTED: 89 case ERROR_CONNECTION_ABORTED: 90 case ERROR_REQUEST_ABORTED: 91 return (ISC_R_CONNECTIONRESET); 92 case WSAEADDRNOTAVAIL: 93 return (ISC_R_ADDRNOTAVAIL); 94 case ERROR_NETNAME_DELETED: 95 case WSAENETDOWN: 96 return (ISC_R_NETUNREACH); 97 case WSAEHOSTDOWN: 98 return (ISC_R_HOSTUNREACH); 99 case WSAENOBUFS: 100 return (ISC_R_NORESOURCES); 101 default: 102 isc__strerror(posixerrno, strbuf, sizeof(strbuf)); 103 UNEXPECTED_ERROR(file, line, "unable to convert errno " 104 "to isc_result: %d: %s", posixerrno, strbuf); 105 /* 106 * XXXDCL would be nice if perhaps this function could 107 * return the system's error string, so the caller 108 * might have something more descriptive than "unexpected 109 * error" to log with. 110 */ 111 return (ISC_R_UNEXPECTED); 112 } 113} 114