PageRenderTime 50ms CodeModel.GetById 25ms 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
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0
  1. /* gpg-error.h - Public interface to libgpg-error.
  2. Copyright (C) 2003, 2004 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 libgpg-error; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef GPG_ERROR_H
  17. #define GPG_ERROR_H 1
  18. #include <stddef.h>
  19. #ifdef __GNUC__
  20. #define GPG_ERR_INLINE __inline__
  21. #elif __STDC_VERSION__ >= 199901L
  22. #define GPG_ERR_INLINE inline
  23. #else
  24. #ifndef GPG_ERR_INLINE
  25. #define GPG_ERR_INLINE
  26. #endif
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #if 0 /* just to make Emacs auto-indent happy */
  31. }
  32. #endif
  33. #endif /* __cplusplus */
  34. /* The GnuPG project consists of many components. Error codes are
  35. exchanged between all components. The common error codes and their
  36. user-presentable descriptions are kept into a shared library to
  37. allow adding new error codes and components without recompiling any
  38. of the other components. The interface will not change in a
  39. backward incompatible way.
  40. An error code together with an error source build up an error
  41. value. As the error value is been passed from one component to
  42. another, it preserver the information about the source and nature
  43. of the error.
  44. A component of the GnuPG project can define the following macro to
  45. tune the behaviour of the library:
  46. GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
  47. gpg_err_source_t to make that source the default for gpg_error().
  48. Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default. */
  49. /* The error source type gpg_err_source_t.
  50. Where as the Poo out of a welle small
  51. Taketh his firste springing and his sours.
  52. --Chaucer. */
  53. /* Only use free slots, never change or reorder the existing
  54. entries. */
  55. typedef enum
  56. {
  57. @include err-sources.h.in
  58. /* This is one more than the largest allowed entry. */
  59. GPG_ERR_SOURCE_DIM = 256
  60. } gpg_err_source_t;
  61. /* The error code type gpg_err_code_t. */
  62. /* Only use free slots, never change or reorder the existing
  63. entries. */
  64. typedef enum
  65. {
  66. @include err-codes.h.in
  67. /* The following error codes are used to map system errors. */
  68. #define GPG_ERR_SYSTEM_ERROR (1 << 15)
  69. @include errnos.in
  70. /* This is one more than the largest allowed entry. */
  71. GPG_ERR_CODE_DIM = 65536
  72. } gpg_err_code_t;
  73. /* The error value type gpg_error_t. */
  74. /* We would really like to use bit-fields in a struct, but using
  75. structs as return values can cause binary compatibility issues, in
  76. particular if you want to do it effeciently (also see
  77. -freg-struct-return option to GCC). */
  78. typedef unsigned int gpg_error_t;
  79. /* We use the lowest 16 bits of gpg_error_t for error codes. The 16th
  80. bit indicates system errors. */
  81. #define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1)
  82. /* Bits 17 to 24 are reserved. */
  83. /* We use the upper 8 bits of gpg_error_t for error sources. */
  84. #define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
  85. #define GPG_ERR_SOURCE_SHIFT 24
  86. /* Constructor and accessor functions. */
  87. /* Construct an error value from an error code and source. Within a
  88. subsystem, use gpg_error. */
  89. static GPG_ERR_INLINE gpg_error_t
  90. gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
  91. {
  92. return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
  93. : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
  94. | (code & GPG_ERR_CODE_MASK));
  95. }
  96. /* The user should define GPG_ERR_SOURCE_DEFAULT before including this
  97. file to specify a default source for gpg_error. */
  98. #ifndef GPG_ERR_SOURCE_DEFAULT
  99. #define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN
  100. #endif
  101. static GPG_ERR_INLINE gpg_error_t
  102. gpg_error (gpg_err_code_t code)
  103. {
  104. return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
  105. }
  106. /* Retrieve the error code from an error value. */
  107. static GPG_ERR_INLINE gpg_err_code_t
  108. gpg_err_code (gpg_error_t err)
  109. {
  110. return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
  111. }
  112. /* Retrieve the error source from an error value. */
  113. static GPG_ERR_INLINE gpg_err_source_t
  114. gpg_err_source (gpg_error_t err)
  115. {
  116. return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
  117. & GPG_ERR_SOURCE_MASK);
  118. }
  119. /* String functions. */
  120. /* Return a pointer to a string containing a description of the error
  121. code in the error value ERR. This function is not thread-safe. */
  122. const char *gpg_strerror (gpg_error_t err);
  123. /* Return the error string for ERR in the user-supplied buffer BUF of
  124. size BUFLEN. This function is, in contrast to gpg_strerror,
  125. thread-safe if a thread-safe strerror_r() function is provided by
  126. the system. If the function succeeds, 0 is returned and BUF
  127. contains the string describing the error. If the buffer was not
  128. large enough, ERANGE is returned and BUF contains as much of the
  129. beginning of the error string as fits into the buffer. */
  130. int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
  131. /* Return a pointer to a string containing a description of the error
  132. source in the error value ERR. */
  133. const char *gpg_strsource (gpg_error_t err);
  134. /* Mapping of system errors (errno). */
  135. /* Retrieve the error code for the system error ERR. This returns
  136. GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
  137. this). */
  138. gpg_err_code_t gpg_err_code_from_errno (int err);
  139. /* Retrieve the system error for the error code CODE. This returns 0
  140. if CODE is not a system error code. */
  141. int gpg_err_code_to_errno (gpg_err_code_t code);
  142. /* Self-documenting convenience functions. */
  143. static GPG_ERR_INLINE gpg_error_t
  144. gpg_err_make_from_errno (gpg_err_source_t source, int err)
  145. {
  146. return gpg_err_make (source, gpg_err_code_from_errno (err));
  147. }
  148. static GPG_ERR_INLINE gpg_error_t
  149. gpg_error_from_errno (int err)
  150. {
  151. return gpg_error (gpg_err_code_from_errno (err));
  152. }
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif /* GPG_ERROR_H */