|
Packit |
fc043f |
/* code-from-errno.c - Mapping errnos to error codes.
|
|
Packit |
fc043f |
Copyright (C) 2003 g10 Code GmbH
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
This file is part of libgpg-error.
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
libgpg-error is free software; you can redistribute it and/or
|
|
Packit |
fc043f |
modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
fc043f |
as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
fc043f |
the License, or (at your option) any later version.
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
libgpg-error is distributed in the hope that it will be useful, but
|
|
Packit |
fc043f |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
fc043f |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
fc043f |
Lesser General Public License for more details.
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
fc043f |
License along with libgpg-error; if not, write to the Free
|
|
Packit |
fc043f |
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
Packit |
fc043f |
02111-1307, USA. */
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#if HAVE_CONFIG_H
|
|
Packit |
fc043f |
#include <config.h>
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include <errno.h>
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include <gpg-error.h>
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include "code-from-errno.h"
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Retrieve the error code for the system error ERR. This returns
|
|
Packit |
fc043f |
GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
|
|
Packit |
fc043f |
this). */
|
|
Packit |
fc043f |
gpg_err_code_t
|
|
Packit |
fc043f |
_gpg_err_code_from_errno (int err)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
int idx;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
if (!err)
|
|
Packit |
fc043f |
return GPG_ERR_NO_ERROR;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
idx = errno_to_idx (err);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
if (idx < 0)
|
|
Packit |
fc043f |
return GPG_ERR_UNKNOWN_ERRNO;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx];
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Retrieve the error code directly from the ERRNO variable. This
|
|
Packit |
fc043f |
returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
|
|
Packit |
fc043f |
(report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
|
|
Packit |
fc043f |
gpg_err_code_t
|
|
Packit |
fc043f |
_gpg_err_code_from_syserror (void)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
int err = errno;
|
|
Packit |
fc043f |
int idx;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
if (!err)
|
|
Packit |
fc043f |
return GPG_ERR_MISSING_ERRNO;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
idx = errno_to_idx (err);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
if (idx < 0)
|
|
Packit |
fc043f |
return GPG_ERR_UNKNOWN_ERRNO;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx];
|
|
Packit |
fc043f |
}
|