PageRenderTime 46ms CodeModel.GetById 22ms 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
Possible License(s): LGPL-2.1, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, Unlicense, GPL-2.0, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0, ISC, MIT, 0BSD, LGPL-2.0
  1. /* gpg-error.h - Public interface to libgpg-error.
  2. Copyright (C) 2003, 2004, 2010 g10 Code GmbH
  3. This file is part of libgpg-error.
  4. libgpg-error is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public License
  6. as published by the Free Software Foundation; either version 2.1 of
  7. the License, or (at your option) any later version.
  8. libgpg-error is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this program; if not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef GPG_ERROR_H
  16. #define GPG_ERROR_H 1
  17. #include <stddef.h>
  18. #ifdef __GNUC__
  19. #define GPG_ERR_INLINE __inline__
  20. #elif __STDC_VERSION__ >= 199901L
  21. #define GPG_ERR_INLINE inline
  22. #else
  23. #ifndef GPG_ERR_INLINE
  24. #define GPG_ERR_INLINE
  25. #endif
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #if 0 /* just to make Emacs auto-indent happy */
  30. }
  31. #endif
  32. #endif /* __cplusplus */
  33. /* The GnuPG project consists of many components. Error codes are
  34. exchanged between all components. The common error codes and their
  35. user-presentable descriptions are kept into a shared library to
  36. allow adding new error codes and components without recompiling any
  37. of the other components. The interface will not change in a
  38. backward incompatible way.
  39. An error code together with an error source build up an error
  40. value. As the error value is been passed from one component to
  41. another, it preserver the information about the source and nature
  42. of the error.
  43. A component of the GnuPG project can define the following macros to
  44. tune the behaviour of the library:
  45. GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
  46. gpg_err_source_t to make that source the default for gpg_error().
  47. Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default.
  48. GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the
  49. internal gettext API to standard names. This has only an effect on
  50. Windows platforms. */
  51. /* The error source type gpg_err_source_t.
  52. Where as the Poo out of a welle small
  53. Taketh his firste springing and his sours.
  54. --Chaucer. */
  55. /* Only use free slots, never change or reorder the existing
  56. entries. */
  57. typedef enum
  58. {
  59. @include err-sources.h.in
  60. /* This is one more than the largest allowed entry. */
  61. GPG_ERR_SOURCE_DIM = 128
  62. } gpg_err_source_t;
  63. /* The error code type gpg_err_code_t. */
  64. /* Only use free slots, never change or reorder the existing
  65. entries. */
  66. typedef enum
  67. {
  68. @include err-codes.h.in
  69. /* The following error codes are used to map system errors. */
  70. #define GPG_ERR_SYSTEM_ERROR (1 << 15)
  71. @include errnos.in
  72. /* This is one more than the largest allowed entry. */
  73. GPG_ERR_CODE_DIM = 65536
  74. } gpg_err_code_t;
  75. /* The error value type gpg_error_t. */
  76. /* We would really like to use bit-fields in a struct, but using
  77. structs as return values can cause binary compatibility issues, in
  78. particular if you want to do it effeciently (also see
  79. -freg-struct-return option to GCC). */
  80. typedef unsigned int gpg_error_t;
  81. /* We use the lowest 16 bits of gpg_error_t for error codes. The 16th
  82. bit indicates system errors. */
  83. #define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1)
  84. /* Bits 17 to 24 are reserved. */
  85. /* We use the upper 7 bits of gpg_error_t for error sources. */
  86. #define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
  87. #define GPG_ERR_SOURCE_SHIFT 24
  88. /* The highest bit is reserved. It shouldn't be used to prevent
  89. potential negative numbers when transmitting error values as
  90. text. */
  91. /* GCC feature test. */
  92. #undef _GPG_ERR_HAVE_CONSTRUCTOR
  93. #if __GNUC__
  94. #define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \
  95. + __GNUC_MINOR__ * 100 \
  96. + __GNUC_PATCHLEVEL__)
  97. #if _GPG_ERR_GCC_VERSION > 30100
  98. #define _GPG_ERR_CONSTRUCTOR __attribute__ ((__constructor__))
  99. #define _GPG_ERR_HAVE_CONSTRUCTOR
  100. #endif
  101. #endif
  102. #ifndef _GPG_ERR_CONSTRUCTOR
  103. #define _GPG_ERR_CONSTRUCTOR
  104. #endif
  105. /* Initialization function. */
  106. /* Initialize the library. This function should be run early. */
  107. gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR;
  108. /* If this is defined, the library is already initialized by the
  109. constructor and does not need to be initialized explicitely. */
  110. #undef GPG_ERR_INITIALIZED
  111. #ifdef _GPG_ERR_HAVE_CONSTRUCTOR
  112. #define GPG_ERR_INITIALIZED 1
  113. #endif
  114. /* Constructor and accessor functions. */
  115. /* Construct an error value from an error code and source. Within a
  116. subsystem, use gpg_error. */
  117. static GPG_ERR_INLINE gpg_error_t
  118. gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
  119. {
  120. return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
  121. : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
  122. | (code & GPG_ERR_CODE_MASK));
  123. }
  124. /* The user should define GPG_ERR_SOURCE_DEFAULT before including this
  125. file to specify a default source for gpg_error. */
  126. #ifndef GPG_ERR_SOURCE_DEFAULT
  127. #define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN
  128. #endif
  129. static GPG_ERR_INLINE gpg_error_t
  130. gpg_error (gpg_err_code_t code)
  131. {
  132. return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
  133. }
  134. /* Retrieve the error code from an error value. */
  135. static GPG_ERR_INLINE gpg_err_code_t
  136. gpg_err_code (gpg_error_t err)
  137. {
  138. return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
  139. }
  140. /* Retrieve the error source from an error value. */
  141. static GPG_ERR_INLINE gpg_err_source_t
  142. gpg_err_source (gpg_error_t err)
  143. {
  144. return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
  145. & GPG_ERR_SOURCE_MASK);
  146. }
  147. /* String functions. */
  148. /* Return a pointer to a string containing a description of the error
  149. code in the error value ERR. This function is not thread-safe. */
  150. const char *gpg_strerror (gpg_error_t err);
  151. /* Return the error string for ERR in the user-supplied buffer BUF of
  152. size BUFLEN. This function is, in contrast to gpg_strerror,
  153. thread-safe if a thread-safe strerror_r() function is provided by
  154. the system. If the function succeeds, 0 is returned and BUF
  155. contains the string describing the error. If the buffer was not
  156. large enough, ERANGE is returned and BUF contains as much of the
  157. beginning of the error string as fits into the buffer. */
  158. int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
  159. /* Return a pointer to a string containing a description of the error
  160. source in the error value ERR. */
  161. const char *gpg_strsource (gpg_error_t err);
  162. /* Mapping of system errors (errno). */
  163. /* Retrieve the error code for the system error ERR. This returns
  164. GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
  165. this). */
  166. gpg_err_code_t gpg_err_code_from_errno (int err);
  167. /* Retrieve the system error for the error code CODE. This returns 0
  168. if CODE is not a system error code. */
  169. int gpg_err_code_to_errno (gpg_err_code_t code);
  170. /* Retrieve the error code directly from the ERRNO variable. This
  171. returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
  172. (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
  173. gpg_err_code_t gpg_err_code_from_syserror (void);
  174. /* Set the ERRNO variable. This function is the preferred way to set
  175. ERRNO due to peculiarities on WindowsCE. */
  176. void gpg_err_set_errno (int err);
  177. @include extra-h.in
  178. /* Self-documenting convenience functions. */
  179. static GPG_ERR_INLINE gpg_error_t
  180. gpg_err_make_from_errno (gpg_err_source_t source, int err)
  181. {
  182. return gpg_err_make (source, gpg_err_code_from_errno (err));
  183. }
  184. static GPG_ERR_INLINE gpg_error_t
  185. gpg_error_from_errno (int err)
  186. {
  187. return gpg_error (gpg_err_code_from_errno (err));
  188. }
  189. static GPG_ERR_INLINE gpg_error_t
  190. gpg_error_from_syserror (void)
  191. {
  192. return gpg_error (gpg_err_code_from_syserror ());
  193. }
  194. #ifdef __cplusplus
  195. }
  196. #endif
  197. #endif /* GPG_ERROR_H */