Blame lib/isc/unix/errno2result.c

Packit Service ae04f2
/*
Packit Service ae04f2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit Service ae04f2
 *
Packit Service ae04f2
 * This Source Code Form is subject to the terms of the Mozilla Public
Packit Service ae04f2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service ae04f2
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit Service ae04f2
 *
Packit Service ae04f2
 * See the COPYRIGHT file distributed with this work for additional
Packit Service ae04f2
 * information regarding copyright ownership.
Packit Service ae04f2
 */
Packit Service ae04f2
Packit Service ae04f2
Packit Service ae04f2
/*! \file */
Packit Service ae04f2
Packit Service ae04f2
#include <config.h>
Packit Service ae04f2
Packit Service ae04f2
#include <stdbool.h>
Packit Service ae04f2
Packit Service ae04f2
#include <isc/result.h>
Packit Service ae04f2
#include <isc/strerror.h>
Packit Service ae04f2
#include <isc/util.h>
Packit Service ae04f2
Packit Service ae04f2
#include "errno2result.h"
Packit Service ae04f2
Packit Service ae04f2
/*%
Packit Service ae04f2
 * Convert a POSIX errno value into an isc_result_t.  The
Packit Service ae04f2
 * list of supported errno values is not complete; new users
Packit Service ae04f2
 * of this function should add any expected errors that are
Packit Service ae04f2
 * not already there.
Packit Service ae04f2
 */
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc___errno2result(int posixerrno, bool dolog,
Packit Service ae04f2
		   const char *file, unsigned int line)
Packit Service ae04f2
{
Packit Service ae04f2
	char strbuf[ISC_STRERRORSIZE];
Packit Service ae04f2
Packit Service ae04f2
	switch (posixerrno) {
Packit Service ae04f2
	case ENOTDIR:
Packit Service ae04f2
	case ELOOP:
Packit Service ae04f2
	case EINVAL:		/* XXX sometimes this is not for files */
Packit Service ae04f2
	case ENAMETOOLONG:
Packit Service ae04f2
	case EBADF:
Packit Service 5febac
	case EISDIR:
Packit Service ae04f2
		return (ISC_R_INVALIDFILE);
Packit Service ae04f2
	case ENOENT:
Packit Service ae04f2
		return (ISC_R_FILENOTFOUND);
Packit Service ae04f2
	case EACCES:
Packit Service ae04f2
	case EPERM:
Packit Service ae04f2
		return (ISC_R_NOPERM);
Packit Service ae04f2
	case EEXIST:
Packit Service ae04f2
		return (ISC_R_FILEEXISTS);
Packit Service ae04f2
	case EIO:
Packit Service ae04f2
		return (ISC_R_IOERROR);
Packit Service ae04f2
	case ENOMEM:
Packit Service ae04f2
		return (ISC_R_NOMEMORY);
Packit Service ae04f2
	case ENFILE:
Packit Service ae04f2
	case EMFILE:
Packit Service ae04f2
		return (ISC_R_TOOMANYOPENFILES);
Packit Service ae04f2
#ifdef EDQUOT
Packit Service ae04f2
	case EDQUOT:
Packit Service ae04f2
		return (ISC_R_DISCQUOTA);
Packit Service ae04f2
#endif
Packit Service ae04f2
	case ENOSPC:
Packit Service ae04f2
		return (ISC_R_DISCFULL);
Packit Service ae04f2
#ifdef EOVERFLOW
Packit Service ae04f2
	case EOVERFLOW:
Packit Service ae04f2
		return (ISC_R_RANGE);
Packit Service ae04f2
#endif
Packit Service ae04f2
	case EPIPE:
Packit Service ae04f2
#ifdef ECONNRESET
Packit Service ae04f2
	case ECONNRESET:
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef ECONNABORTED
Packit Service ae04f2
	case ECONNABORTED:
Packit Service ae04f2
#endif
Packit Service ae04f2
		return (ISC_R_CONNECTIONRESET);
Packit Service ae04f2
#ifdef ENOTCONN
Packit Service ae04f2
	case ENOTCONN:
Packit Service ae04f2
		return (ISC_R_NOTCONNECTED);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef ETIMEDOUT
Packit Service ae04f2
	case ETIMEDOUT:
Packit Service ae04f2
		return (ISC_R_TIMEDOUT);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef ENOBUFS
Packit Service ae04f2
	case ENOBUFS:
Packit Service ae04f2
		return (ISC_R_NORESOURCES);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef EAFNOSUPPORT
Packit Service ae04f2
	case EAFNOSUPPORT:
Packit Service ae04f2
		return (ISC_R_FAMILYNOSUPPORT);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef ENETDOWN
Packit Service ae04f2
	case ENETDOWN:
Packit Service ae04f2
		return (ISC_R_NETDOWN);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef EHOSTDOWN
Packit Service ae04f2
	case EHOSTDOWN:
Packit Service ae04f2
		return (ISC_R_HOSTDOWN);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef ENETUNREACH
Packit Service ae04f2
	case ENETUNREACH:
Packit Service ae04f2
		return (ISC_R_NETUNREACH);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef EHOSTUNREACH
Packit Service ae04f2
	case EHOSTUNREACH:
Packit Service ae04f2
		return (ISC_R_HOSTUNREACH);
Packit Service ae04f2
#endif
Packit Service ae04f2
#ifdef EADDRINUSE
Packit Service ae04f2
	case EADDRINUSE:
Packit Service ae04f2
		return (ISC_R_ADDRINUSE);
Packit Service ae04f2
#endif
Packit Service ae04f2
	case EADDRNOTAVAIL:
Packit Service ae04f2
		return (ISC_R_ADDRNOTAVAIL);
Packit Service ae04f2
	case ECONNREFUSED:
Packit Service ae04f2
		return (ISC_R_CONNREFUSED);
Packit Service ae04f2
	default:
Packit Service ae04f2
		if (dolog) {
Packit Service ae04f2
			isc__strerror(posixerrno, strbuf, sizeof(strbuf));
Packit Service ae04f2
			UNEXPECTED_ERROR(file, line, "unable to convert errno "
Packit Service ae04f2
					 "to isc_result: %d: %s",
Packit Service ae04f2
					 posixerrno, strbuf);
Packit Service ae04f2
		}
Packit Service ae04f2
		/*
Packit Service ae04f2
		 * XXXDCL would be nice if perhaps this function could
Packit Service ae04f2
		 * return the system's error string, so the caller
Packit Service ae04f2
		 * might have something more descriptive than "unexpected
Packit Service ae04f2
		 * error" to log with.
Packit Service ae04f2
		 */
Packit Service ae04f2
		return (ISC_R_UNEXPECTED);
Packit Service ae04f2
	}
Packit Service ae04f2
}