errno2result.c revision 40f53fa8d9c6a4fc38c0014495e7a42b08f52481
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence/*
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * Copyright (C) 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * Permission to use, copy, modify, and distribute this software for any
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * purpose with or without fee is hereby granted, provided that the above
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence */
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence/* $Id: errno2result.c,v 1.4 2000/08/01 01:31:14 tale Exp $ */
cb4a97bb1c84fcab089136f0a4686ab5fea6a07cDavid Lawrence
cb4a97bb1c84fcab089136f0a4686ab5fea6a07cDavid Lawrence#include <config.h>
cb4a97bb1c84fcab089136f0a4686ab5fea6a07cDavid Lawrence
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence#include <errno.h>
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence#include <isc/result.h>
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence#include "errno2result.h"
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence/*
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * Convert a POSIX errno value into an isc_result_t. The
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * list of supported errno values is not complete; new users
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * of this function should add any expected errors that are
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * not already there.
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence */
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrenceisc_result_t
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrenceisc__errno2result(int posixerrno) {
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence switch (posixerrno) {
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case ENOTDIR:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case ELOOP:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case EINVAL:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case ENAMETOOLONG:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case EBADF:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_INVALIDFILE);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case ENOENT:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_FILENOTFOUND);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case EACCES:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_NOPERM);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case EEXIST:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_FILEEXISTS);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case EIO:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_IOERROR);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence case ENOMEM:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_NOMEMORY);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence default:
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence /*
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * XXXDCL would be nice if perhaps this function could
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * return the system's error string, so the caller
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * might have something more descriptive than "unexpected
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * error" to log with.
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence */
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence return (ISC_R_UNEXPECTED);
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence }
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence}