PageRenderTime 67ms CodeModel.GetById 47ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/libgpg-error/libgpg-error-1.8/src/gpg-error.h.in

https://bitbucket.org/thelearninglabs/uclinux-distro-tll-public
Autoconf | 270 lines | 165 code | 64 blank | 41 comment | 16 complexity | a3bd891d85b9d000e1ce3ecf1b14a7d6 MD5 | raw file
  1/* gpg-error.h - Public interface to libgpg-error.
  2   Copyright (C) 2003, 2004, 2010 g10 Code GmbH
  3
  4   This file is part of libgpg-error.
  5 
  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.
 10 
 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.
 15 
 16   You should have received a copy of the GNU Lesser General Public
 17   License along with this program; if not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20
 21#ifndef GPG_ERROR_H
 22#define GPG_ERROR_H	1
 23
 24#include <stddef.h>
 25
 26#ifdef __GNUC__
 27#define GPG_ERR_INLINE __inline__
 28#elif __STDC_VERSION__ >= 199901L
 29#define GPG_ERR_INLINE inline
 30#else
 31#ifndef GPG_ERR_INLINE
 32#define GPG_ERR_INLINE
 33#endif 
 34#endif
 35
 36
 37#ifdef __cplusplus
 38extern "C" {
 39#if 0 /* just to make Emacs auto-indent happy */
 40}
 41#endif
 42#endif /* __cplusplus */
 43
 44/* The GnuPG project consists of many components.  Error codes are
 45   exchanged between all components.  The common error codes and their
 46   user-presentable descriptions are kept into a shared library to
 47   allow adding new error codes and components without recompiling any
 48   of the other components.  The interface will not change in a
 49   backward incompatible way.
 50
 51   An error code together with an error source build up an error
 52   value.  As the error value is been passed from one component to
 53   another, it preserver the information about the source and nature
 54   of the error.
 55
 56   A component of the GnuPG project can define the following macros to
 57   tune the behaviour of the library:
 58
 59   GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
 60   gpg_err_source_t to make that source the default for gpg_error().
 61   Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default.
 62
 63   GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the
 64   internal gettext API to standard names.  This has only an effect on
 65   Windows platforms.  */
 66
 67
 68/* The error source type gpg_err_source_t.
 69
 70   Where as the Poo out of a welle small
 71   Taketh his firste springing and his sours.
 72					--Chaucer.  */
 73
 74/* Only use free slots, never change or reorder the existing
 75   entries.  */
 76typedef enum
 77  {
 78@include err-sources.h.in
 79
 80    /* This is one more than the largest allowed entry.  */
 81    GPG_ERR_SOURCE_DIM = 128
 82  } gpg_err_source_t;
 83
 84
 85/* The error code type gpg_err_code_t.  */
 86
 87/* Only use free slots, never change or reorder the existing
 88   entries.  */
 89typedef enum
 90  {
 91@include err-codes.h.in
 92
 93    /* The following error codes are used to map system errors.  */
 94#define GPG_ERR_SYSTEM_ERROR	(1 << 15)
 95@include errnos.in
 96
 97    /* This is one more than the largest allowed entry.  */
 98    GPG_ERR_CODE_DIM = 65536
 99  } gpg_err_code_t;
100
101
102/* The error value type gpg_error_t.  */
103
104/* We would really like to use bit-fields in a struct, but using
105   structs as return values can cause binary compatibility issues, in
106   particular if you want to do it effeciently (also see
107   -freg-struct-return option to GCC).  */
108typedef unsigned int gpg_error_t;
109
110/* We use the lowest 16 bits of gpg_error_t for error codes.  The 16th
111   bit indicates system errors.  */
112#define GPG_ERR_CODE_MASK	(GPG_ERR_CODE_DIM - 1)
113
114/* Bits 17 to 24 are reserved.  */
115
116/* We use the upper 7 bits of gpg_error_t for error sources.  */
117#define GPG_ERR_SOURCE_MASK	(GPG_ERR_SOURCE_DIM - 1)
118#define GPG_ERR_SOURCE_SHIFT	24
119
120/* The highest bit is reserved.  It shouldn't be used to prevent
121   potential negative numbers when transmitting error values as
122   text.  */
123
124
125/* GCC feature test.  */
126#undef _GPG_ERR_HAVE_CONSTRUCTOR
127#if __GNUC__
128#define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \
129                            + __GNUC_MINOR__ * 100 \
130                            + __GNUC_PATCHLEVEL__)
131
132#if _GPG_ERR_GCC_VERSION > 30100
133#define _GPG_ERR_CONSTRUCTOR	__attribute__ ((__constructor__))
134#define _GPG_ERR_HAVE_CONSTRUCTOR
135#endif
136#endif
137
138#ifndef _GPG_ERR_CONSTRUCTOR
139#define _GPG_ERR_CONSTRUCTOR
140#endif
141
142
143/* Initialization function.  */
144
145/* Initialize the library.  This function should be run early.  */
146gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR;
147
148/* If this is defined, the library is already initialized by the
149   constructor and does not need to be initialized explicitely.  */
150#undef GPG_ERR_INITIALIZED
151#ifdef _GPG_ERR_HAVE_CONSTRUCTOR
152#define GPG_ERR_INITIALIZED	1
153#endif
154
155
156/* Constructor and accessor functions.  */
157
158/* Construct an error value from an error code and source.  Within a
159   subsystem, use gpg_error.  */
160static GPG_ERR_INLINE gpg_error_t
161gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
162{
163  return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
164    : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
165       | (code & GPG_ERR_CODE_MASK));
166}
167
168
169/* The user should define GPG_ERR_SOURCE_DEFAULT before including this
170   file to specify a default source for gpg_error.  */
171#ifndef GPG_ERR_SOURCE_DEFAULT
172#define GPG_ERR_SOURCE_DEFAULT	GPG_ERR_SOURCE_UNKNOWN
173#endif
174
175static GPG_ERR_INLINE gpg_error_t
176gpg_error (gpg_err_code_t code)
177{
178  return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
179}
180
181
182/* Retrieve the error code from an error value.  */
183static GPG_ERR_INLINE gpg_err_code_t
184gpg_err_code (gpg_error_t err)
185{
186  return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
187}
188
189
190/* Retrieve the error source from an error value.  */
191static GPG_ERR_INLINE gpg_err_source_t
192gpg_err_source (gpg_error_t err)
193{
194  return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
195			     & GPG_ERR_SOURCE_MASK);
196}
197
198
199/* String functions.  */
200
201/* Return a pointer to a string containing a description of the error
202   code in the error value ERR.  This function is not thread-safe.  */
203const char *gpg_strerror (gpg_error_t err);
204
205/* Return the error string for ERR in the user-supplied buffer BUF of
206   size BUFLEN.  This function is, in contrast to gpg_strerror,
207   thread-safe if a thread-safe strerror_r() function is provided by
208   the system.  If the function succeeds, 0 is returned and BUF
209   contains the string describing the error.  If the buffer was not
210   large enough, ERANGE is returned and BUF contains as much of the
211   beginning of the error string as fits into the buffer.  */
212int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
213
214/* Return a pointer to a string containing a description of the error
215   source in the error value ERR.  */
216const char *gpg_strsource (gpg_error_t err);
217
218
219/* Mapping of system errors (errno).  */
220
221/* Retrieve the error code for the system error ERR.  This returns
222   GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
223   this). */
224gpg_err_code_t gpg_err_code_from_errno (int err);
225
226
227/* Retrieve the system error for the error code CODE.  This returns 0
228   if CODE is not a system error code.  */
229int gpg_err_code_to_errno (gpg_err_code_t code);
230
231
232/* Retrieve the error code directly from the ERRNO variable.  This
233   returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
234   (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
235gpg_err_code_t gpg_err_code_from_syserror (void);
236
237
238/* Set the ERRNO variable.  This function is the preferred way to set
239   ERRNO due to peculiarities on WindowsCE.  */
240void gpg_err_set_errno (int err);
241
242@include extra-h.in
243
244/* Self-documenting convenience functions.  */
245
246static GPG_ERR_INLINE gpg_error_t
247gpg_err_make_from_errno (gpg_err_source_t source, int err)
248{
249  return gpg_err_make (source, gpg_err_code_from_errno (err));
250}
251
252
253static GPG_ERR_INLINE gpg_error_t
254gpg_error_from_errno (int err)
255{
256  return gpg_error (gpg_err_code_from_errno (err));
257}
258
259static GPG_ERR_INLINE gpg_error_t
260gpg_error_from_syserror (void)
261{
262  return gpg_error (gpg_err_code_from_syserror ());
263}
264
265#ifdef __cplusplus
266}
267#endif
268
269
270#endif	/* GPG_ERROR_H */