1 /* code-from-errno.c - Mapping errnos to error codes.
2 Copyright (C) 2003 g10 Code GmbH
4 This file is part of libgpg-error.
6 libgpg-error is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License
8 as published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 libgpg-error is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with libgpg-error; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <gpg-error.h>
29 #include "code-from-errno.h"
31 /* Retrieve the error code for the system error ERR. This returns
32 GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
35 gpg_err_code_from_errno (int err)
40 return GPG_ERR_NO_ERROR;
42 idx = errno_to_idx (err);
45 return GPG_ERR_UNKNOWN_ERRNO;
47 return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx];
51 /* Retrieve the error code directly from the ERRNO variable. This
52 returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
53 (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
55 gpg_err_code_from_syserror (void)
61 return GPG_ERR_MISSING_ERRNO;
63 idx = errno_to_idx (err);
66 return GPG_ERR_UNKNOWN_ERRNO;
68 return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx];