PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/libgpg-error/libgpg-error-1.0/src/gpg-error.h.in

https://bitbucket.org/lkalif/emerald-snowglobe
Autoconf | 211 lines | 137 code | 48 blank | 26 comment | 14 complexity | 012fbd41dccb2f225c29acf039cbffc8 MD5 | raw file
  1/* gpg-error.h - Public interface to libgpg-error.
  2   Copyright (C) 2003, 2004 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 libgpg-error; if not, write to the Free
 18   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 19   02111-1307, USA.  */
 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#ifdef __cplusplus
 37extern "C" {
 38#if 0 /* just to make Emacs auto-indent happy */
 39}
 40#endif
 41#endif /* __cplusplus */
 42
 43/* The GnuPG project consists of many components.  Error codes are
 44   exchanged between all components.  The common error codes and their
 45   user-presentable descriptions are kept into a shared library to
 46   allow adding new error codes and components without recompiling any
 47   of the other components.  The interface will not change in a
 48   backward incompatible way.
 49
 50   An error code together with an error source build up an error
 51   value.  As the error value is been passed from one component to
 52   another, it preserver the information about the source and nature
 53   of the error.
 54
 55   A component of the GnuPG project can define the following macro to
 56   tune the behaviour of the library:
 57
 58   GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
 59   gpg_err_source_t to make that source the default for gpg_error().
 60   Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default.  */
 61
 62
 63/* The error source type gpg_err_source_t.
 64
 65   Where as the Poo out of a welle small
 66   Taketh his firste springing and his sours.
 67					--Chaucer.  */
 68
 69/* Only use free slots, never change or reorder the existing
 70   entries.  */
 71typedef enum
 72  {
 73@include err-sources.h.in
 74
 75    /* This is one more than the largest allowed entry.  */
 76    GPG_ERR_SOURCE_DIM = 256
 77  } gpg_err_source_t;
 78
 79
 80/* The error code type gpg_err_code_t.  */
 81
 82/* Only use free slots, never change or reorder the existing
 83   entries.  */
 84typedef enum
 85  {
 86@include err-codes.h.in
 87
 88    /* The following error codes are used to map system errors.  */
 89#define GPG_ERR_SYSTEM_ERROR	(1 << 15)
 90@include errnos.in
 91
 92    /* This is one more than the largest allowed entry.  */
 93    GPG_ERR_CODE_DIM = 65536
 94  } gpg_err_code_t;
 95
 96
 97/* The error value type gpg_error_t.  */
 98
 99/* We would really like to use bit-fields in a struct, but using
100   structs as return values can cause binary compatibility issues, in
101   particular if you want to do it effeciently (also see
102   -freg-struct-return option to GCC).  */
103typedef unsigned int gpg_error_t;
104
105/* We use the lowest 16 bits of gpg_error_t for error codes.  The 16th
106   bit indicates system errors.  */
107#define GPG_ERR_CODE_MASK	(GPG_ERR_CODE_DIM - 1)
108
109/* Bits 17 to 24 are reserved.  */
110
111/* We use the upper 8 bits of gpg_error_t for error sources.  */
112#define GPG_ERR_SOURCE_MASK	(GPG_ERR_SOURCE_DIM - 1)
113#define GPG_ERR_SOURCE_SHIFT	24
114
115
116/* Constructor and accessor functions.  */
117
118/* Construct an error value from an error code and source.  Within a
119   subsystem, use gpg_error.  */
120static GPG_ERR_INLINE gpg_error_t
121gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
122{
123  return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
124    : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
125       | (code & GPG_ERR_CODE_MASK));
126}
127
128
129/* The user should define GPG_ERR_SOURCE_DEFAULT before including this
130   file to specify a default source for gpg_error.  */
131#ifndef GPG_ERR_SOURCE_DEFAULT
132#define GPG_ERR_SOURCE_DEFAULT	GPG_ERR_SOURCE_UNKNOWN
133#endif
134
135static GPG_ERR_INLINE gpg_error_t
136gpg_error (gpg_err_code_t code)
137{
138  return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
139}
140
141
142/* Retrieve the error code from an error value.  */
143static GPG_ERR_INLINE gpg_err_code_t
144gpg_err_code (gpg_error_t err)
145{
146  return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
147}
148
149
150/* Retrieve the error source from an error value.  */
151static GPG_ERR_INLINE gpg_err_source_t
152gpg_err_source (gpg_error_t err)
153{
154  return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
155			     & GPG_ERR_SOURCE_MASK);
156}
157
158
159/* String functions.  */
160
161/* Return a pointer to a string containing a description of the error
162   code in the error value ERR.  This function is not thread-safe.  */
163const char *gpg_strerror (gpg_error_t err);
164
165/* Return the error string for ERR in the user-supplied buffer BUF of
166   size BUFLEN.  This function is, in contrast to gpg_strerror,
167   thread-safe if a thread-safe strerror_r() function is provided by
168   the system.  If the function succeeds, 0 is returned and BUF
169   contains the string describing the error.  If the buffer was not
170   large enough, ERANGE is returned and BUF contains as much of the
171   beginning of the error string as fits into the buffer.  */
172int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
173
174/* Return a pointer to a string containing a description of the error
175   source in the error value ERR.  */
176const char *gpg_strsource (gpg_error_t err);
177
178
179/* Mapping of system errors (errno).  */
180
181/* Retrieve the error code for the system error ERR.  This returns
182   GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
183   this).  */
184gpg_err_code_t gpg_err_code_from_errno (int err);
185
186
187/* Retrieve the system error for the error code CODE.  This returns 0
188   if CODE is not a system error code.  */
189int gpg_err_code_to_errno (gpg_err_code_t code);
190
191
192/* Self-documenting convenience functions.  */
193
194static GPG_ERR_INLINE gpg_error_t
195gpg_err_make_from_errno (gpg_err_source_t source, int err)
196{
197  return gpg_err_make (source, gpg_err_code_from_errno (err));
198}
199
200
201static GPG_ERR_INLINE gpg_error_t
202gpg_error_from_errno (int err)
203{
204  return gpg_error (gpg_err_code_from_errno (err));
205}
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif	/* GPG_ERROR_H */