1258945Sroberto/* 2280849Scy * Copyright (C) 2004, 2005, 2007, 2011, 2012 Internet Systems Consortium, Inc. ("ISC") 3258945Sroberto * Copyright (C) 2000-2002 Internet Software Consortium. 4258945Sroberto * 5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any 6258945Sroberto * purpose with or without fee is hereby granted, provided that the above 7258945Sroberto * copyright notice and this permission notice appear in all copies. 8258945Sroberto * 9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11258945Sroberto * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15258945Sroberto * PERFORMANCE OF THIS SOFTWARE. 16258945Sroberto */ 17258945Sroberto 18280849Scy/* $Id$ */ 19258945Sroberto 20258945Sroberto/*! \file */ 21258945Sroberto 22258945Sroberto#include <config.h> 23258945Sroberto 24258945Sroberto#include <isc/result.h> 25258945Sroberto#include <isc/strerror.h> 26258945Sroberto#include <isc/util.h> 27258945Sroberto 28258945Sroberto#include "errno2result.h" 29258945Sroberto 30258945Sroberto/*% 31258945Sroberto * Convert a POSIX errno value into an isc_result_t. The 32258945Sroberto * list of supported errno values is not complete; new users 33258945Sroberto * of this function should add any expected errors that are 34258945Sroberto * not already there. 35258945Sroberto */ 36258945Srobertoisc_result_t 37280849Scyisc___errno2result(int posixerrno, const char *file, unsigned int line) { 38258945Sroberto char strbuf[ISC_STRERRORSIZE]; 39258945Sroberto 40258945Sroberto switch (posixerrno) { 41258945Sroberto case ENOTDIR: 42258945Sroberto case ELOOP: 43258945Sroberto case EINVAL: /* XXX sometimes this is not for files */ 44258945Sroberto case ENAMETOOLONG: 45258945Sroberto case EBADF: 46258945Sroberto return (ISC_R_INVALIDFILE); 47258945Sroberto case ENOENT: 48258945Sroberto return (ISC_R_FILENOTFOUND); 49258945Sroberto case EACCES: 50258945Sroberto case EPERM: 51258945Sroberto return (ISC_R_NOPERM); 52258945Sroberto case EEXIST: 53258945Sroberto return (ISC_R_FILEEXISTS); 54258945Sroberto case EIO: 55258945Sroberto return (ISC_R_IOERROR); 56258945Sroberto case ENOMEM: 57258945Sroberto return (ISC_R_NOMEMORY); 58280849Scy case ENFILE: 59258945Sroberto case EMFILE: 60258945Sroberto return (ISC_R_TOOMANYOPENFILES); 61258945Sroberto case EPIPE: 62258945Sroberto#ifdef ECONNRESET 63258945Sroberto case ECONNRESET: 64258945Sroberto#endif 65258945Sroberto#ifdef ECONNABORTED 66258945Sroberto case ECONNABORTED: 67258945Sroberto#endif 68258945Sroberto return (ISC_R_CONNECTIONRESET); 69258945Sroberto#ifdef ENOTCONN 70258945Sroberto case ENOTCONN: 71258945Sroberto return (ISC_R_NOTCONNECTED); 72258945Sroberto#endif 73258945Sroberto#ifdef ETIMEDOUT 74258945Sroberto case ETIMEDOUT: 75258945Sroberto return (ISC_R_TIMEDOUT); 76258945Sroberto#endif 77258945Sroberto#ifdef ENOBUFS 78258945Sroberto case ENOBUFS: 79258945Sroberto return (ISC_R_NORESOURCES); 80258945Sroberto#endif 81258945Sroberto#ifdef EAFNOSUPPORT 82258945Sroberto case EAFNOSUPPORT: 83258945Sroberto return (ISC_R_FAMILYNOSUPPORT); 84258945Sroberto#endif 85258945Sroberto#ifdef ENETDOWN 86258945Sroberto case ENETDOWN: 87258945Sroberto return (ISC_R_NETDOWN); 88258945Sroberto#endif 89258945Sroberto#ifdef EHOSTDOWN 90258945Sroberto case EHOSTDOWN: 91258945Sroberto return (ISC_R_HOSTDOWN); 92258945Sroberto#endif 93258945Sroberto#ifdef ENETUNREACH 94258945Sroberto case ENETUNREACH: 95258945Sroberto return (ISC_R_NETUNREACH); 96258945Sroberto#endif 97258945Sroberto#ifdef EHOSTUNREACH 98258945Sroberto case EHOSTUNREACH: 99258945Sroberto return (ISC_R_HOSTUNREACH); 100258945Sroberto#endif 101258945Sroberto#ifdef EADDRINUSE 102258945Sroberto case EADDRINUSE: 103258945Sroberto return (ISC_R_ADDRINUSE); 104258945Sroberto#endif 105258945Sroberto case EADDRNOTAVAIL: 106258945Sroberto return (ISC_R_ADDRNOTAVAIL); 107258945Sroberto case ECONNREFUSED: 108258945Sroberto return (ISC_R_CONNREFUSED); 109258945Sroberto default: 110258945Sroberto isc__strerror(posixerrno, strbuf, sizeof(strbuf)); 111280849Scy UNEXPECTED_ERROR(file, line, "unable to convert errno " 112258945Sroberto "to isc_result: %d: %s", 113258945Sroberto posixerrno, strbuf); 114258945Sroberto /* 115258945Sroberto * XXXDCL would be nice if perhaps this function could 116258945Sroberto * return the system's error string, so the caller 117258945Sroberto * might have something more descriptive than "unexpected 118258945Sroberto * error" to log with. 119258945Sroberto */ 120258945Sroberto return (ISC_R_UNEXPECTED); 121258945Sroberto } 122258945Sroberto} 123