Coverage Report

Created: 2022-12-08 06:09

/src/libgpg-error/src/gpg-error.h
Line
Count
Source (jump to first uncovered line)
1
/* gpg-error.h or gpgrt.h - Common code for GnuPG and others.    -*- c -*-
2
 * Copyright (C) 2001-2020 g10 Code GmbH
3
 *
4
 * This file is part of libgpg-error (aka libgpgrt).
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 <https://www.gnu.org/licenses/>.
18
 * SPDX-License-Identifier: LGPL-2.1+
19
 *
20
 * Do not edit.  Generated from gpg-error.h.in for:
21
                 x86_64-unknown-linux-gnu (x86_64-pc-linux-gnu)
22
 */
23
24
/* The GnuPG project consists of many components.  Error codes are
25
 * exchanged between all components.  The common error codes and their
26
 * user-presentable descriptions are kept into a shared library to
27
 * allow adding new error codes and components without recompiling any
28
 * of the other components.  In addition to error codes this library
29
 * also features several other groups of functions which are common to
30
 * all GnuPG components.  They may be used by independet project as
31
 * well.  The interfaces will not change in a backward incompatible way.
32
 *
33
 * An error code together with an error source build up an error
34
 * value.  As the error value is been passed from one component to
35
 * another, it preserves the information about the source and nature
36
 * of the error.
37
 *
38
 * A component of the GnuPG project can define the following macros to
39
 * tune the behaviour of the library:
40
 *
41
 * GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
42
 * gpg_err_source_t to make that source the default for gpg_error().
43
 * Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default.
44
 *
45
 * GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the
46
 * internal gettext API to standard names.  This has only an effect on
47
 * Windows platforms.
48
 *
49
 * GPGRT_ENABLE_ES_MACROS: Define to provide "es_" macros for the
50
 * estream functions.
51
 *
52
 * GPGRT_ENABLE_LOG_MACROS: Define to provide short versions of the
53
 * log functions.
54
 *
55
 * GPGRT_ENABLE_ARGPARSE_MACROS: Needs to be defined to provide the
56
 * mandatory macros of the argparse interface.
57
 */
58
59
#ifndef GPG_ERROR_H
60
#define GPG_ERROR_H 1
61
#ifndef GPGRT_H
62
#define GPGRT_H 1
63
64
#include <stddef.h>
65
#include <stdio.h>
66
#include <stdarg.h>
67
68
/* The version string of this header. */
69
#define GPG_ERROR_VERSION "1.47"
70
#define GPGRT_VERSION     "1.47"
71
72
/* The version number of this header. */
73
#define GPG_ERROR_VERSION_NUMBER 0x012f00
74
#define GPGRT_VERSION_NUMBER     0x012f00
75
76
77
#ifdef __GNUC__
78
# define GPG_ERR_INLINE __inline__
79
#elif defined(_MSC_VER) && _MSC_VER >= 1300
80
# define GPG_ERR_INLINE __inline
81
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
82
# define GPG_ERR_INLINE inline
83
#else
84
# ifndef GPG_ERR_INLINE
85
#  define GPG_ERR_INLINE
86
# endif
87
#endif
88
89
#ifdef __cplusplus
90
extern "C" {
91
#if 0 /* just to make Emacs auto-indent happy */
92
}
93
#endif
94
#endif /* __cplusplus */
95
96
97

98
/* The error source type gpg_err_source_t.
99
 *
100
 * Where as the Poo out of a welle small
101
 * Taketh his firste springing and his sours.
102
 *          --Chaucer.
103
 */
104
105
/* Only use free slots, never change or reorder the existing
106
 * entries.  */
107
typedef enum
108
  {
109
    GPG_ERR_SOURCE_UNKNOWN = 0,
110
    GPG_ERR_SOURCE_GCRYPT = 1,
111
    GPG_ERR_SOURCE_GPG = 2,
112
    GPG_ERR_SOURCE_GPGSM = 3,
113
    GPG_ERR_SOURCE_GPGAGENT = 4,
114
    GPG_ERR_SOURCE_PINENTRY = 5,
115
    GPG_ERR_SOURCE_SCD = 6,
116
    GPG_ERR_SOURCE_GPGME = 7,
117
    GPG_ERR_SOURCE_KEYBOX = 8,
118
    GPG_ERR_SOURCE_KSBA = 9,
119
    GPG_ERR_SOURCE_DIRMNGR = 10,
120
    GPG_ERR_SOURCE_GSTI = 11,
121
    GPG_ERR_SOURCE_GPA = 12,
122
    GPG_ERR_SOURCE_KLEO = 13,
123
    GPG_ERR_SOURCE_G13 = 14,
124
    GPG_ERR_SOURCE_ASSUAN = 15,
125
    GPG_ERR_SOURCE_TPM2D = 16,
126
    GPG_ERR_SOURCE_TLS = 17,
127
    GPG_ERR_SOURCE_ANY = 31,
128
    GPG_ERR_SOURCE_USER_1 = 32,
129
    GPG_ERR_SOURCE_USER_2 = 33,
130
    GPG_ERR_SOURCE_USER_3 = 34,
131
    GPG_ERR_SOURCE_USER_4 = 35,
132
133
    /* This is one more than the largest allowed entry.  */
134
    GPG_ERR_SOURCE_DIM = 128
135
  } gpg_err_source_t;
136
137

138
/* The error code type gpg_err_code_t.  */
139
140
/* Only use free slots, never change or reorder the existing
141
 * entries.  */
142
typedef enum
143
  {
144
    GPG_ERR_NO_ERROR = 0,
145
    GPG_ERR_GENERAL = 1,
146
    GPG_ERR_UNKNOWN_PACKET = 2,
147
    GPG_ERR_UNKNOWN_VERSION = 3,
148
    GPG_ERR_PUBKEY_ALGO = 4,
149
    GPG_ERR_DIGEST_ALGO = 5,
150
    GPG_ERR_BAD_PUBKEY = 6,
151
    GPG_ERR_BAD_SECKEY = 7,
152
    GPG_ERR_BAD_SIGNATURE = 8,
153
    GPG_ERR_NO_PUBKEY = 9,
154
    GPG_ERR_CHECKSUM = 10,
155
    GPG_ERR_BAD_PASSPHRASE = 11,
156
    GPG_ERR_CIPHER_ALGO = 12,
157
    GPG_ERR_KEYRING_OPEN = 13,
158
    GPG_ERR_INV_PACKET = 14,
159
    GPG_ERR_INV_ARMOR = 15,
160
    GPG_ERR_NO_USER_ID = 16,
161
    GPG_ERR_NO_SECKEY = 17,
162
    GPG_ERR_WRONG_SECKEY = 18,
163
    GPG_ERR_BAD_KEY = 19,
164
    GPG_ERR_COMPR_ALGO = 20,
165
    GPG_ERR_NO_PRIME = 21,
166
    GPG_ERR_NO_ENCODING_METHOD = 22,
167
    GPG_ERR_NO_ENCRYPTION_SCHEME = 23,
168
    GPG_ERR_NO_SIGNATURE_SCHEME = 24,
169
    GPG_ERR_INV_ATTR = 25,
170
    GPG_ERR_NO_VALUE = 26,
171
    GPG_ERR_NOT_FOUND = 27,
172
    GPG_ERR_VALUE_NOT_FOUND = 28,
173
    GPG_ERR_SYNTAX = 29,
174
    GPG_ERR_BAD_MPI = 30,
175
    GPG_ERR_INV_PASSPHRASE = 31,
176
    GPG_ERR_SIG_CLASS = 32,
177
    GPG_ERR_RESOURCE_LIMIT = 33,
178
    GPG_ERR_INV_KEYRING = 34,
179
    GPG_ERR_TRUSTDB = 35,
180
    GPG_ERR_BAD_CERT = 36,
181
    GPG_ERR_INV_USER_ID = 37,
182
    GPG_ERR_UNEXPECTED = 38,
183
    GPG_ERR_TIME_CONFLICT = 39,
184
    GPG_ERR_KEYSERVER = 40,
185
    GPG_ERR_WRONG_PUBKEY_ALGO = 41,
186
    GPG_ERR_TRIBUTE_TO_D_A = 42,
187
    GPG_ERR_WEAK_KEY = 43,
188
    GPG_ERR_INV_KEYLEN = 44,
189
    GPG_ERR_INV_ARG = 45,
190
    GPG_ERR_BAD_URI = 46,
191
    GPG_ERR_INV_URI = 47,
192
    GPG_ERR_NETWORK = 48,
193
    GPG_ERR_UNKNOWN_HOST = 49,
194
    GPG_ERR_SELFTEST_FAILED = 50,
195
    GPG_ERR_NOT_ENCRYPTED = 51,
196
    GPG_ERR_NOT_PROCESSED = 52,
197
    GPG_ERR_UNUSABLE_PUBKEY = 53,
198
    GPG_ERR_UNUSABLE_SECKEY = 54,
199
    GPG_ERR_INV_VALUE = 55,
200
    GPG_ERR_BAD_CERT_CHAIN = 56,
201
    GPG_ERR_MISSING_CERT = 57,
202
    GPG_ERR_NO_DATA = 58,
203
    GPG_ERR_BUG = 59,
204
    GPG_ERR_NOT_SUPPORTED = 60,
205
    GPG_ERR_INV_OP = 61,
206
    GPG_ERR_TIMEOUT = 62,
207
    GPG_ERR_INTERNAL = 63,
208
    GPG_ERR_EOF_GCRYPT = 64,
209
    GPG_ERR_INV_OBJ = 65,
210
    GPG_ERR_TOO_SHORT = 66,
211
    GPG_ERR_TOO_LARGE = 67,
212
    GPG_ERR_NO_OBJ = 68,
213
    GPG_ERR_NOT_IMPLEMENTED = 69,
214
    GPG_ERR_CONFLICT = 70,
215
    GPG_ERR_INV_CIPHER_MODE = 71,
216
    GPG_ERR_INV_FLAG = 72,
217
    GPG_ERR_INV_HANDLE = 73,
218
    GPG_ERR_TRUNCATED = 74,
219
    GPG_ERR_INCOMPLETE_LINE = 75,
220
    GPG_ERR_INV_RESPONSE = 76,
221
    GPG_ERR_NO_AGENT = 77,
222
    GPG_ERR_AGENT = 78,
223
    GPG_ERR_INV_DATA = 79,
224
    GPG_ERR_ASSUAN_SERVER_FAULT = 80,
225
    GPG_ERR_ASSUAN = 81,
226
    GPG_ERR_INV_SESSION_KEY = 82,
227
    GPG_ERR_INV_SEXP = 83,
228
    GPG_ERR_UNSUPPORTED_ALGORITHM = 84,
229
    GPG_ERR_NO_PIN_ENTRY = 85,
230
    GPG_ERR_PIN_ENTRY = 86,
231
    GPG_ERR_BAD_PIN = 87,
232
    GPG_ERR_INV_NAME = 88,
233
    GPG_ERR_BAD_DATA = 89,
234
    GPG_ERR_INV_PARAMETER = 90,
235
    GPG_ERR_WRONG_CARD = 91,
236
    GPG_ERR_NO_DIRMNGR = 92,
237
    GPG_ERR_DIRMNGR = 93,
238
    GPG_ERR_CERT_REVOKED = 94,
239
    GPG_ERR_NO_CRL_KNOWN = 95,
240
    GPG_ERR_CRL_TOO_OLD = 96,
241
    GPG_ERR_LINE_TOO_LONG = 97,
242
    GPG_ERR_NOT_TRUSTED = 98,
243
    GPG_ERR_CANCELED = 99,
244
    GPG_ERR_BAD_CA_CERT = 100,
245
    GPG_ERR_CERT_EXPIRED = 101,
246
    GPG_ERR_CERT_TOO_YOUNG = 102,
247
    GPG_ERR_UNSUPPORTED_CERT = 103,
248
    GPG_ERR_UNKNOWN_SEXP = 104,
249
    GPG_ERR_UNSUPPORTED_PROTECTION = 105,
250
    GPG_ERR_CORRUPTED_PROTECTION = 106,
251
    GPG_ERR_AMBIGUOUS_NAME = 107,
252
    GPG_ERR_CARD = 108,
253
    GPG_ERR_CARD_RESET = 109,
254
    GPG_ERR_CARD_REMOVED = 110,
255
    GPG_ERR_INV_CARD = 111,
256
    GPG_ERR_CARD_NOT_PRESENT = 112,
257
    GPG_ERR_NO_PKCS15_APP = 113,
258
    GPG_ERR_NOT_CONFIRMED = 114,
259
    GPG_ERR_CONFIGURATION = 115,
260
    GPG_ERR_NO_POLICY_MATCH = 116,
261
    GPG_ERR_INV_INDEX = 117,
262
    GPG_ERR_INV_ID = 118,
263
    GPG_ERR_NO_SCDAEMON = 119,
264
    GPG_ERR_SCDAEMON = 120,
265
    GPG_ERR_UNSUPPORTED_PROTOCOL = 121,
266
    GPG_ERR_BAD_PIN_METHOD = 122,
267
    GPG_ERR_CARD_NOT_INITIALIZED = 123,
268
    GPG_ERR_UNSUPPORTED_OPERATION = 124,
269
    GPG_ERR_WRONG_KEY_USAGE = 125,
270
    GPG_ERR_NOTHING_FOUND = 126,
271
    GPG_ERR_WRONG_BLOB_TYPE = 127,
272
    GPG_ERR_MISSING_VALUE = 128,
273
    GPG_ERR_HARDWARE = 129,
274
    GPG_ERR_PIN_BLOCKED = 130,
275
    GPG_ERR_USE_CONDITIONS = 131,
276
    GPG_ERR_PIN_NOT_SYNCED = 132,
277
    GPG_ERR_INV_CRL = 133,
278
    GPG_ERR_BAD_BER = 134,
279
    GPG_ERR_INV_BER = 135,
280
    GPG_ERR_ELEMENT_NOT_FOUND = 136,
281
    GPG_ERR_IDENTIFIER_NOT_FOUND = 137,
282
    GPG_ERR_INV_TAG = 138,
283
    GPG_ERR_INV_LENGTH = 139,
284
    GPG_ERR_INV_KEYINFO = 140,
285
    GPG_ERR_UNEXPECTED_TAG = 141,
286
    GPG_ERR_NOT_DER_ENCODED = 142,
287
    GPG_ERR_NO_CMS_OBJ = 143,
288
    GPG_ERR_INV_CMS_OBJ = 144,
289
    GPG_ERR_UNKNOWN_CMS_OBJ = 145,
290
    GPG_ERR_UNSUPPORTED_CMS_OBJ = 146,
291
    GPG_ERR_UNSUPPORTED_ENCODING = 147,
292
    GPG_ERR_UNSUPPORTED_CMS_VERSION = 148,
293
    GPG_ERR_UNKNOWN_ALGORITHM = 149,
294
    GPG_ERR_INV_ENGINE = 150,
295
    GPG_ERR_PUBKEY_NOT_TRUSTED = 151,
296
    GPG_ERR_DECRYPT_FAILED = 152,
297
    GPG_ERR_KEY_EXPIRED = 153,
298
    GPG_ERR_SIG_EXPIRED = 154,
299
    GPG_ERR_ENCODING_PROBLEM = 155,
300
    GPG_ERR_INV_STATE = 156,
301
    GPG_ERR_DUP_VALUE = 157,
302
    GPG_ERR_MISSING_ACTION = 158,
303
    GPG_ERR_MODULE_NOT_FOUND = 159,
304
    GPG_ERR_INV_OID_STRING = 160,
305
    GPG_ERR_INV_TIME = 161,
306
    GPG_ERR_INV_CRL_OBJ = 162,
307
    GPG_ERR_UNSUPPORTED_CRL_VERSION = 163,
308
    GPG_ERR_INV_CERT_OBJ = 164,
309
    GPG_ERR_UNKNOWN_NAME = 165,
310
    GPG_ERR_LOCALE_PROBLEM = 166,
311
    GPG_ERR_NOT_LOCKED = 167,
312
    GPG_ERR_PROTOCOL_VIOLATION = 168,
313
    GPG_ERR_INV_MAC = 169,
314
    GPG_ERR_INV_REQUEST = 170,
315
    GPG_ERR_UNKNOWN_EXTN = 171,
316
    GPG_ERR_UNKNOWN_CRIT_EXTN = 172,
317
    GPG_ERR_LOCKED = 173,
318
    GPG_ERR_UNKNOWN_OPTION = 174,
319
    GPG_ERR_UNKNOWN_COMMAND = 175,
320
    GPG_ERR_NOT_OPERATIONAL = 176,
321
    GPG_ERR_NO_PASSPHRASE = 177,
322
    GPG_ERR_NO_PIN = 178,
323
    GPG_ERR_NOT_ENABLED = 179,
324
    GPG_ERR_NO_ENGINE = 180,
325
    GPG_ERR_MISSING_KEY = 181,
326
    GPG_ERR_TOO_MANY = 182,
327
    GPG_ERR_LIMIT_REACHED = 183,
328
    GPG_ERR_NOT_INITIALIZED = 184,
329
    GPG_ERR_MISSING_ISSUER_CERT = 185,
330
    GPG_ERR_NO_KEYSERVER = 186,
331
    GPG_ERR_INV_CURVE = 187,
332
    GPG_ERR_UNKNOWN_CURVE = 188,
333
    GPG_ERR_DUP_KEY = 189,
334
    GPG_ERR_AMBIGUOUS = 190,
335
    GPG_ERR_NO_CRYPT_CTX = 191,
336
    GPG_ERR_WRONG_CRYPT_CTX = 192,
337
    GPG_ERR_BAD_CRYPT_CTX = 193,
338
    GPG_ERR_CRYPT_CTX_CONFLICT = 194,
339
    GPG_ERR_BROKEN_PUBKEY = 195,
340
    GPG_ERR_BROKEN_SECKEY = 196,
341
    GPG_ERR_MAC_ALGO = 197,
342
    GPG_ERR_FULLY_CANCELED = 198,
343
    GPG_ERR_UNFINISHED = 199,
344
    GPG_ERR_BUFFER_TOO_SHORT = 200,
345
    GPG_ERR_SEXP_INV_LEN_SPEC = 201,
346
    GPG_ERR_SEXP_STRING_TOO_LONG = 202,
347
    GPG_ERR_SEXP_UNMATCHED_PAREN = 203,
348
    GPG_ERR_SEXP_NOT_CANONICAL = 204,
349
    GPG_ERR_SEXP_BAD_CHARACTER = 205,
350
    GPG_ERR_SEXP_BAD_QUOTATION = 206,
351
    GPG_ERR_SEXP_ZERO_PREFIX = 207,
352
    GPG_ERR_SEXP_NESTED_DH = 208,
353
    GPG_ERR_SEXP_UNMATCHED_DH = 209,
354
    GPG_ERR_SEXP_UNEXPECTED_PUNC = 210,
355
    GPG_ERR_SEXP_BAD_HEX_CHAR = 211,
356
    GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212,
357
    GPG_ERR_SEXP_BAD_OCT_CHAR = 213,
358
    GPG_ERR_SUBKEYS_EXP_OR_REV = 217,
359
    GPG_ERR_DB_CORRUPTED = 218,
360
    GPG_ERR_SERVER_FAILED = 219,
361
    GPG_ERR_NO_NAME = 220,
362
    GPG_ERR_NO_KEY = 221,
363
    GPG_ERR_LEGACY_KEY = 222,
364
    GPG_ERR_REQUEST_TOO_SHORT = 223,
365
    GPG_ERR_REQUEST_TOO_LONG = 224,
366
    GPG_ERR_OBJ_TERM_STATE = 225,
367
    GPG_ERR_NO_CERT_CHAIN = 226,
368
    GPG_ERR_CERT_TOO_LARGE = 227,
369
    GPG_ERR_INV_RECORD = 228,
370
    GPG_ERR_BAD_MAC = 229,
371
    GPG_ERR_UNEXPECTED_MSG = 230,
372
    GPG_ERR_COMPR_FAILED = 231,
373
    GPG_ERR_WOULD_WRAP = 232,
374
    GPG_ERR_FATAL_ALERT = 233,
375
    GPG_ERR_NO_CIPHER = 234,
376
    GPG_ERR_MISSING_CLIENT_CERT = 235,
377
    GPG_ERR_CLOSE_NOTIFY = 236,
378
    GPG_ERR_TICKET_EXPIRED = 237,
379
    GPG_ERR_BAD_TICKET = 238,
380
    GPG_ERR_UNKNOWN_IDENTITY = 239,
381
    GPG_ERR_BAD_HS_CERT = 240,
382
    GPG_ERR_BAD_HS_CERT_REQ = 241,
383
    GPG_ERR_BAD_HS_CERT_VER = 242,
384
    GPG_ERR_BAD_HS_CHANGE_CIPHER = 243,
385
    GPG_ERR_BAD_HS_CLIENT_HELLO = 244,
386
    GPG_ERR_BAD_HS_SERVER_HELLO = 245,
387
    GPG_ERR_BAD_HS_SERVER_HELLO_DONE = 246,
388
    GPG_ERR_BAD_HS_FINISHED = 247,
389
    GPG_ERR_BAD_HS_SERVER_KEX = 248,
390
    GPG_ERR_BAD_HS_CLIENT_KEX = 249,
391
    GPG_ERR_BOGUS_STRING = 250,
392
    GPG_ERR_FORBIDDEN = 251,
393
    GPG_ERR_KEY_DISABLED = 252,
394
    GPG_ERR_KEY_ON_CARD = 253,
395
    GPG_ERR_INV_LOCK_OBJ = 254,
396
    GPG_ERR_TRUE = 255,
397
    GPG_ERR_FALSE = 256,
398
    GPG_ERR_ASS_GENERAL = 257,
399
    GPG_ERR_ASS_ACCEPT_FAILED = 258,
400
    GPG_ERR_ASS_CONNECT_FAILED = 259,
401
    GPG_ERR_ASS_INV_RESPONSE = 260,
402
    GPG_ERR_ASS_INV_VALUE = 261,
403
    GPG_ERR_ASS_INCOMPLETE_LINE = 262,
404
    GPG_ERR_ASS_LINE_TOO_LONG = 263,
405
    GPG_ERR_ASS_NESTED_COMMANDS = 264,
406
    GPG_ERR_ASS_NO_DATA_CB = 265,
407
    GPG_ERR_ASS_NO_INQUIRE_CB = 266,
408
    GPG_ERR_ASS_NOT_A_SERVER = 267,
409
    GPG_ERR_ASS_NOT_A_CLIENT = 268,
410
    GPG_ERR_ASS_SERVER_START = 269,
411
    GPG_ERR_ASS_READ_ERROR = 270,
412
    GPG_ERR_ASS_WRITE_ERROR = 271,
413
    GPG_ERR_ASS_TOO_MUCH_DATA = 273,
414
    GPG_ERR_ASS_UNEXPECTED_CMD = 274,
415
    GPG_ERR_ASS_UNKNOWN_CMD = 275,
416
    GPG_ERR_ASS_SYNTAX = 276,
417
    GPG_ERR_ASS_CANCELED = 277,
418
    GPG_ERR_ASS_NO_INPUT = 278,
419
    GPG_ERR_ASS_NO_OUTPUT = 279,
420
    GPG_ERR_ASS_PARAMETER = 280,
421
    GPG_ERR_ASS_UNKNOWN_INQUIRE = 281,
422
    GPG_ERR_ENGINE_TOO_OLD = 300,
423
    GPG_ERR_WINDOW_TOO_SMALL = 301,
424
    GPG_ERR_WINDOW_TOO_LARGE = 302,
425
    GPG_ERR_MISSING_ENVVAR = 303,
426
    GPG_ERR_USER_ID_EXISTS = 304,
427
    GPG_ERR_NAME_EXISTS = 305,
428
    GPG_ERR_DUP_NAME = 306,
429
    GPG_ERR_TOO_YOUNG = 307,
430
    GPG_ERR_TOO_OLD = 308,
431
    GPG_ERR_UNKNOWN_FLAG = 309,
432
    GPG_ERR_INV_ORDER = 310,
433
    GPG_ERR_ALREADY_FETCHED = 311,
434
    GPG_ERR_TRY_LATER = 312,
435
    GPG_ERR_WRONG_NAME = 313,
436
    GPG_ERR_NO_AUTH = 314,
437
    GPG_ERR_BAD_AUTH = 315,
438
    GPG_ERR_NO_KEYBOXD = 316,
439
    GPG_ERR_KEYBOXD = 317,
440
    GPG_ERR_NO_SERVICE = 318,
441
    GPG_ERR_SERVICE = 319,
442
    GPG_ERR_SYSTEM_BUG = 666,
443
    GPG_ERR_DNS_UNKNOWN = 711,
444
    GPG_ERR_DNS_SECTION = 712,
445
    GPG_ERR_DNS_ADDRESS = 713,
446
    GPG_ERR_DNS_NO_QUERY = 714,
447
    GPG_ERR_DNS_NO_ANSWER = 715,
448
    GPG_ERR_DNS_CLOSED = 716,
449
    GPG_ERR_DNS_VERIFY = 717,
450
    GPG_ERR_DNS_TIMEOUT = 718,
451
    GPG_ERR_LDAP_GENERAL = 721,
452
    GPG_ERR_LDAP_ATTR_GENERAL = 722,
453
    GPG_ERR_LDAP_NAME_GENERAL = 723,
454
    GPG_ERR_LDAP_SECURITY_GENERAL = 724,
455
    GPG_ERR_LDAP_SERVICE_GENERAL = 725,
456
    GPG_ERR_LDAP_UPDATE_GENERAL = 726,
457
    GPG_ERR_LDAP_E_GENERAL = 727,
458
    GPG_ERR_LDAP_X_GENERAL = 728,
459
    GPG_ERR_LDAP_OTHER_GENERAL = 729,
460
    GPG_ERR_LDAP_X_CONNECTING = 750,
461
    GPG_ERR_LDAP_REFERRAL_LIMIT = 751,
462
    GPG_ERR_LDAP_CLIENT_LOOP = 752,
463
    GPG_ERR_LDAP_NO_RESULTS = 754,
464
    GPG_ERR_LDAP_CONTROL_NOT_FOUND = 755,
465
    GPG_ERR_LDAP_NOT_SUPPORTED = 756,
466
    GPG_ERR_LDAP_CONNECT = 757,
467
    GPG_ERR_LDAP_NO_MEMORY = 758,
468
    GPG_ERR_LDAP_PARAM = 759,
469
    GPG_ERR_LDAP_USER_CANCELLED = 760,
470
    GPG_ERR_LDAP_FILTER = 761,
471
    GPG_ERR_LDAP_AUTH_UNKNOWN = 762,
472
    GPG_ERR_LDAP_TIMEOUT = 763,
473
    GPG_ERR_LDAP_DECODING = 764,
474
    GPG_ERR_LDAP_ENCODING = 765,
475
    GPG_ERR_LDAP_LOCAL = 766,
476
    GPG_ERR_LDAP_SERVER_DOWN = 767,
477
    GPG_ERR_LDAP_SUCCESS = 768,
478
    GPG_ERR_LDAP_OPERATIONS = 769,
479
    GPG_ERR_LDAP_PROTOCOL = 770,
480
    GPG_ERR_LDAP_TIMELIMIT = 771,
481
    GPG_ERR_LDAP_SIZELIMIT = 772,
482
    GPG_ERR_LDAP_COMPARE_FALSE = 773,
483
    GPG_ERR_LDAP_COMPARE_TRUE = 774,
484
    GPG_ERR_LDAP_UNSUPPORTED_AUTH = 775,
485
    GPG_ERR_LDAP_STRONG_AUTH_RQRD = 776,
486
    GPG_ERR_LDAP_PARTIAL_RESULTS = 777,
487
    GPG_ERR_LDAP_REFERRAL = 778,
488
    GPG_ERR_LDAP_ADMINLIMIT = 779,
489
    GPG_ERR_LDAP_UNAVAIL_CRIT_EXTN = 780,
490
    GPG_ERR_LDAP_CONFIDENT_RQRD = 781,
491
    GPG_ERR_LDAP_SASL_BIND_INPROG = 782,
492
    GPG_ERR_LDAP_NO_SUCH_ATTRIBUTE = 784,
493
    GPG_ERR_LDAP_UNDEFINED_TYPE = 785,
494
    GPG_ERR_LDAP_BAD_MATCHING = 786,
495
    GPG_ERR_LDAP_CONST_VIOLATION = 787,
496
    GPG_ERR_LDAP_TYPE_VALUE_EXISTS = 788,
497
    GPG_ERR_LDAP_INV_SYNTAX = 789,
498
    GPG_ERR_LDAP_NO_SUCH_OBJ = 800,
499
    GPG_ERR_LDAP_ALIAS_PROBLEM = 801,
500
    GPG_ERR_LDAP_INV_DN_SYNTAX = 802,
501
    GPG_ERR_LDAP_IS_LEAF = 803,
502
    GPG_ERR_LDAP_ALIAS_DEREF = 804,
503
    GPG_ERR_LDAP_X_PROXY_AUTH_FAIL = 815,
504
    GPG_ERR_LDAP_BAD_AUTH = 816,
505
    GPG_ERR_LDAP_INV_CREDENTIALS = 817,
506
    GPG_ERR_LDAP_INSUFFICIENT_ACC = 818,
507
    GPG_ERR_LDAP_BUSY = 819,
508
    GPG_ERR_LDAP_UNAVAILABLE = 820,
509
    GPG_ERR_LDAP_UNWILL_TO_PERFORM = 821,
510
    GPG_ERR_LDAP_LOOP_DETECT = 822,
511
    GPG_ERR_LDAP_NAMING_VIOLATION = 832,
512
    GPG_ERR_LDAP_OBJ_CLS_VIOLATION = 833,
513
    GPG_ERR_LDAP_NOT_ALLOW_NONLEAF = 834,
514
    GPG_ERR_LDAP_NOT_ALLOW_ON_RDN = 835,
515
    GPG_ERR_LDAP_ALREADY_EXISTS = 836,
516
    GPG_ERR_LDAP_NO_OBJ_CLASS_MODS = 837,
517
    GPG_ERR_LDAP_RESULTS_TOO_LARGE = 838,
518
    GPG_ERR_LDAP_AFFECTS_MULT_DSAS = 839,
519
    GPG_ERR_LDAP_VLV = 844,
520
    GPG_ERR_LDAP_OTHER = 848,
521
    GPG_ERR_LDAP_CUP_RESOURCE_LIMIT = 881,
522
    GPG_ERR_LDAP_CUP_SEC_VIOLATION = 882,
523
    GPG_ERR_LDAP_CUP_INV_DATA = 883,
524
    GPG_ERR_LDAP_CUP_UNSUP_SCHEME = 884,
525
    GPG_ERR_LDAP_CUP_RELOAD = 885,
526
    GPG_ERR_LDAP_CANCELLED = 886,
527
    GPG_ERR_LDAP_NO_SUCH_OPERATION = 887,
528
    GPG_ERR_LDAP_TOO_LATE = 888,
529
    GPG_ERR_LDAP_CANNOT_CANCEL = 889,
530
    GPG_ERR_LDAP_ASSERTION_FAILED = 890,
531
    GPG_ERR_LDAP_PROX_AUTH_DENIED = 891,
532
    GPG_ERR_USER_1 = 1024,
533
    GPG_ERR_USER_2 = 1025,
534
    GPG_ERR_USER_3 = 1026,
535
    GPG_ERR_USER_4 = 1027,
536
    GPG_ERR_USER_5 = 1028,
537
    GPG_ERR_USER_6 = 1029,
538
    GPG_ERR_USER_7 = 1030,
539
    GPG_ERR_USER_8 = 1031,
540
    GPG_ERR_USER_9 = 1032,
541
    GPG_ERR_USER_10 = 1033,
542
    GPG_ERR_USER_11 = 1034,
543
    GPG_ERR_USER_12 = 1035,
544
    GPG_ERR_USER_13 = 1036,
545
    GPG_ERR_USER_14 = 1037,
546
    GPG_ERR_USER_15 = 1038,
547
    GPG_ERR_USER_16 = 1039,
548
    GPG_ERR_SQL_OK = 1500,
549
    GPG_ERR_SQL_ERROR = 1501,
550
    GPG_ERR_SQL_INTERNAL = 1502,
551
    GPG_ERR_SQL_PERM = 1503,
552
    GPG_ERR_SQL_ABORT = 1504,
553
    GPG_ERR_SQL_BUSY = 1505,
554
    GPG_ERR_SQL_LOCKED = 1506,
555
    GPG_ERR_SQL_NOMEM = 1507,
556
    GPG_ERR_SQL_READONLY = 1508,
557
    GPG_ERR_SQL_INTERRUPT = 1509,
558
    GPG_ERR_SQL_IOERR = 1510,
559
    GPG_ERR_SQL_CORRUPT = 1511,
560
    GPG_ERR_SQL_NOTFOUND = 1512,
561
    GPG_ERR_SQL_FULL = 1513,
562
    GPG_ERR_SQL_CANTOPEN = 1514,
563
    GPG_ERR_SQL_PROTOCOL = 1515,
564
    GPG_ERR_SQL_EMPTY = 1516,
565
    GPG_ERR_SQL_SCHEMA = 1517,
566
    GPG_ERR_SQL_TOOBIG = 1518,
567
    GPG_ERR_SQL_CONSTRAINT = 1519,
568
    GPG_ERR_SQL_MISMATCH = 1520,
569
    GPG_ERR_SQL_MISUSE = 1521,
570
    GPG_ERR_SQL_NOLFS = 1522,
571
    GPG_ERR_SQL_AUTH = 1523,
572
    GPG_ERR_SQL_FORMAT = 1524,
573
    GPG_ERR_SQL_RANGE = 1525,
574
    GPG_ERR_SQL_NOTADB = 1526,
575
    GPG_ERR_SQL_NOTICE = 1527,
576
    GPG_ERR_SQL_WARNING = 1528,
577
    GPG_ERR_SQL_ROW = 1600,
578
    GPG_ERR_SQL_DONE = 1601,
579
    GPG_ERR_MISSING_ERRNO = 16381,
580
    GPG_ERR_UNKNOWN_ERRNO = 16382,
581
    GPG_ERR_EOF = 16383,
582
583
    /* The following error codes are used to map system errors.  */
584
467k
#define GPG_ERR_SYSTEM_ERROR  (1 << 15)
585
    GPG_ERR_E2BIG = GPG_ERR_SYSTEM_ERROR | 0,
586
    GPG_ERR_EACCES = GPG_ERR_SYSTEM_ERROR | 1,
587
    GPG_ERR_EADDRINUSE = GPG_ERR_SYSTEM_ERROR | 2,
588
    GPG_ERR_EADDRNOTAVAIL = GPG_ERR_SYSTEM_ERROR | 3,
589
    GPG_ERR_EADV = GPG_ERR_SYSTEM_ERROR | 4,
590
    GPG_ERR_EAFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 5,
591
    GPG_ERR_EAGAIN = GPG_ERR_SYSTEM_ERROR | 6,
592
    GPG_ERR_EALREADY = GPG_ERR_SYSTEM_ERROR | 7,
593
    GPG_ERR_EAUTH = GPG_ERR_SYSTEM_ERROR | 8,
594
    GPG_ERR_EBACKGROUND = GPG_ERR_SYSTEM_ERROR | 9,
595
    GPG_ERR_EBADE = GPG_ERR_SYSTEM_ERROR | 10,
596
    GPG_ERR_EBADF = GPG_ERR_SYSTEM_ERROR | 11,
597
    GPG_ERR_EBADFD = GPG_ERR_SYSTEM_ERROR | 12,
598
    GPG_ERR_EBADMSG = GPG_ERR_SYSTEM_ERROR | 13,
599
    GPG_ERR_EBADR = GPG_ERR_SYSTEM_ERROR | 14,
600
    GPG_ERR_EBADRPC = GPG_ERR_SYSTEM_ERROR | 15,
601
    GPG_ERR_EBADRQC = GPG_ERR_SYSTEM_ERROR | 16,
602
    GPG_ERR_EBADSLT = GPG_ERR_SYSTEM_ERROR | 17,
603
    GPG_ERR_EBFONT = GPG_ERR_SYSTEM_ERROR | 18,
604
    GPG_ERR_EBUSY = GPG_ERR_SYSTEM_ERROR | 19,
605
    GPG_ERR_ECANCELED = GPG_ERR_SYSTEM_ERROR | 20,
606
    GPG_ERR_ECHILD = GPG_ERR_SYSTEM_ERROR | 21,
607
    GPG_ERR_ECHRNG = GPG_ERR_SYSTEM_ERROR | 22,
608
    GPG_ERR_ECOMM = GPG_ERR_SYSTEM_ERROR | 23,
609
    GPG_ERR_ECONNABORTED = GPG_ERR_SYSTEM_ERROR | 24,
610
    GPG_ERR_ECONNREFUSED = GPG_ERR_SYSTEM_ERROR | 25,
611
    GPG_ERR_ECONNRESET = GPG_ERR_SYSTEM_ERROR | 26,
612
    GPG_ERR_ED = GPG_ERR_SYSTEM_ERROR | 27,
613
    GPG_ERR_EDEADLK = GPG_ERR_SYSTEM_ERROR | 28,
614
    GPG_ERR_EDEADLOCK = GPG_ERR_SYSTEM_ERROR | 29,
615
    GPG_ERR_EDESTADDRREQ = GPG_ERR_SYSTEM_ERROR | 30,
616
    GPG_ERR_EDIED = GPG_ERR_SYSTEM_ERROR | 31,
617
    GPG_ERR_EDOM = GPG_ERR_SYSTEM_ERROR | 32,
618
    GPG_ERR_EDOTDOT = GPG_ERR_SYSTEM_ERROR | 33,
619
    GPG_ERR_EDQUOT = GPG_ERR_SYSTEM_ERROR | 34,
620
    GPG_ERR_EEXIST = GPG_ERR_SYSTEM_ERROR | 35,
621
    GPG_ERR_EFAULT = GPG_ERR_SYSTEM_ERROR | 36,
622
    GPG_ERR_EFBIG = GPG_ERR_SYSTEM_ERROR | 37,
623
    GPG_ERR_EFTYPE = GPG_ERR_SYSTEM_ERROR | 38,
624
    GPG_ERR_EGRATUITOUS = GPG_ERR_SYSTEM_ERROR | 39,
625
    GPG_ERR_EGREGIOUS = GPG_ERR_SYSTEM_ERROR | 40,
626
    GPG_ERR_EHOSTDOWN = GPG_ERR_SYSTEM_ERROR | 41,
627
    GPG_ERR_EHOSTUNREACH = GPG_ERR_SYSTEM_ERROR | 42,
628
    GPG_ERR_EIDRM = GPG_ERR_SYSTEM_ERROR | 43,
629
    GPG_ERR_EIEIO = GPG_ERR_SYSTEM_ERROR | 44,
630
    GPG_ERR_EILSEQ = GPG_ERR_SYSTEM_ERROR | 45,
631
    GPG_ERR_EINPROGRESS = GPG_ERR_SYSTEM_ERROR | 46,
632
    GPG_ERR_EINTR = GPG_ERR_SYSTEM_ERROR | 47,
633
    GPG_ERR_EINVAL = GPG_ERR_SYSTEM_ERROR | 48,
634
    GPG_ERR_EIO = GPG_ERR_SYSTEM_ERROR | 49,
635
    GPG_ERR_EISCONN = GPG_ERR_SYSTEM_ERROR | 50,
636
    GPG_ERR_EISDIR = GPG_ERR_SYSTEM_ERROR | 51,
637
    GPG_ERR_EISNAM = GPG_ERR_SYSTEM_ERROR | 52,
638
    GPG_ERR_EL2HLT = GPG_ERR_SYSTEM_ERROR | 53,
639
    GPG_ERR_EL2NSYNC = GPG_ERR_SYSTEM_ERROR | 54,
640
    GPG_ERR_EL3HLT = GPG_ERR_SYSTEM_ERROR | 55,
641
    GPG_ERR_EL3RST = GPG_ERR_SYSTEM_ERROR | 56,
642
    GPG_ERR_ELIBACC = GPG_ERR_SYSTEM_ERROR | 57,
643
    GPG_ERR_ELIBBAD = GPG_ERR_SYSTEM_ERROR | 58,
644
    GPG_ERR_ELIBEXEC = GPG_ERR_SYSTEM_ERROR | 59,
645
    GPG_ERR_ELIBMAX = GPG_ERR_SYSTEM_ERROR | 60,
646
    GPG_ERR_ELIBSCN = GPG_ERR_SYSTEM_ERROR | 61,
647
    GPG_ERR_ELNRNG = GPG_ERR_SYSTEM_ERROR | 62,
648
    GPG_ERR_ELOOP = GPG_ERR_SYSTEM_ERROR | 63,
649
    GPG_ERR_EMEDIUMTYPE = GPG_ERR_SYSTEM_ERROR | 64,
650
    GPG_ERR_EMFILE = GPG_ERR_SYSTEM_ERROR | 65,
651
    GPG_ERR_EMLINK = GPG_ERR_SYSTEM_ERROR | 66,
652
    GPG_ERR_EMSGSIZE = GPG_ERR_SYSTEM_ERROR | 67,
653
    GPG_ERR_EMULTIHOP = GPG_ERR_SYSTEM_ERROR | 68,
654
    GPG_ERR_ENAMETOOLONG = GPG_ERR_SYSTEM_ERROR | 69,
655
    GPG_ERR_ENAVAIL = GPG_ERR_SYSTEM_ERROR | 70,
656
    GPG_ERR_ENEEDAUTH = GPG_ERR_SYSTEM_ERROR | 71,
657
    GPG_ERR_ENETDOWN = GPG_ERR_SYSTEM_ERROR | 72,
658
    GPG_ERR_ENETRESET = GPG_ERR_SYSTEM_ERROR | 73,
659
    GPG_ERR_ENETUNREACH = GPG_ERR_SYSTEM_ERROR | 74,
660
    GPG_ERR_ENFILE = GPG_ERR_SYSTEM_ERROR | 75,
661
    GPG_ERR_ENOANO = GPG_ERR_SYSTEM_ERROR | 76,
662
    GPG_ERR_ENOBUFS = GPG_ERR_SYSTEM_ERROR | 77,
663
    GPG_ERR_ENOCSI = GPG_ERR_SYSTEM_ERROR | 78,
664
    GPG_ERR_ENODATA = GPG_ERR_SYSTEM_ERROR | 79,
665
    GPG_ERR_ENODEV = GPG_ERR_SYSTEM_ERROR | 80,
666
    GPG_ERR_ENOENT = GPG_ERR_SYSTEM_ERROR | 81,
667
    GPG_ERR_ENOEXEC = GPG_ERR_SYSTEM_ERROR | 82,
668
    GPG_ERR_ENOLCK = GPG_ERR_SYSTEM_ERROR | 83,
669
    GPG_ERR_ENOLINK = GPG_ERR_SYSTEM_ERROR | 84,
670
    GPG_ERR_ENOMEDIUM = GPG_ERR_SYSTEM_ERROR | 85,
671
    GPG_ERR_ENOMEM = GPG_ERR_SYSTEM_ERROR | 86,
672
    GPG_ERR_ENOMSG = GPG_ERR_SYSTEM_ERROR | 87,
673
    GPG_ERR_ENONET = GPG_ERR_SYSTEM_ERROR | 88,
674
    GPG_ERR_ENOPKG = GPG_ERR_SYSTEM_ERROR | 89,
675
    GPG_ERR_ENOPROTOOPT = GPG_ERR_SYSTEM_ERROR | 90,
676
    GPG_ERR_ENOSPC = GPG_ERR_SYSTEM_ERROR | 91,
677
    GPG_ERR_ENOSR = GPG_ERR_SYSTEM_ERROR | 92,
678
    GPG_ERR_ENOSTR = GPG_ERR_SYSTEM_ERROR | 93,
679
    GPG_ERR_ENOSYS = GPG_ERR_SYSTEM_ERROR | 94,
680
    GPG_ERR_ENOTBLK = GPG_ERR_SYSTEM_ERROR | 95,
681
    GPG_ERR_ENOTCONN = GPG_ERR_SYSTEM_ERROR | 96,
682
    GPG_ERR_ENOTDIR = GPG_ERR_SYSTEM_ERROR | 97,
683
    GPG_ERR_ENOTEMPTY = GPG_ERR_SYSTEM_ERROR | 98,
684
    GPG_ERR_ENOTNAM = GPG_ERR_SYSTEM_ERROR | 99,
685
    GPG_ERR_ENOTSOCK = GPG_ERR_SYSTEM_ERROR | 100,
686
    GPG_ERR_ENOTSUP = GPG_ERR_SYSTEM_ERROR | 101,
687
    GPG_ERR_ENOTTY = GPG_ERR_SYSTEM_ERROR | 102,
688
    GPG_ERR_ENOTUNIQ = GPG_ERR_SYSTEM_ERROR | 103,
689
    GPG_ERR_ENXIO = GPG_ERR_SYSTEM_ERROR | 104,
690
    GPG_ERR_EOPNOTSUPP = GPG_ERR_SYSTEM_ERROR | 105,
691
    GPG_ERR_EOVERFLOW = GPG_ERR_SYSTEM_ERROR | 106,
692
    GPG_ERR_EPERM = GPG_ERR_SYSTEM_ERROR | 107,
693
    GPG_ERR_EPFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 108,
694
    GPG_ERR_EPIPE = GPG_ERR_SYSTEM_ERROR | 109,
695
    GPG_ERR_EPROCLIM = GPG_ERR_SYSTEM_ERROR | 110,
696
    GPG_ERR_EPROCUNAVAIL = GPG_ERR_SYSTEM_ERROR | 111,
697
    GPG_ERR_EPROGMISMATCH = GPG_ERR_SYSTEM_ERROR | 112,
698
    GPG_ERR_EPROGUNAVAIL = GPG_ERR_SYSTEM_ERROR | 113,
699
    GPG_ERR_EPROTO = GPG_ERR_SYSTEM_ERROR | 114,
700
    GPG_ERR_EPROTONOSUPPORT = GPG_ERR_SYSTEM_ERROR | 115,
701
    GPG_ERR_EPROTOTYPE = GPG_ERR_SYSTEM_ERROR | 116,
702
    GPG_ERR_ERANGE = GPG_ERR_SYSTEM_ERROR | 117,
703
    GPG_ERR_EREMCHG = GPG_ERR_SYSTEM_ERROR | 118,
704
    GPG_ERR_EREMOTE = GPG_ERR_SYSTEM_ERROR | 119,
705
    GPG_ERR_EREMOTEIO = GPG_ERR_SYSTEM_ERROR | 120,
706
    GPG_ERR_ERESTART = GPG_ERR_SYSTEM_ERROR | 121,
707
    GPG_ERR_EROFS = GPG_ERR_SYSTEM_ERROR | 122,
708
    GPG_ERR_ERPCMISMATCH = GPG_ERR_SYSTEM_ERROR | 123,
709
    GPG_ERR_ESHUTDOWN = GPG_ERR_SYSTEM_ERROR | 124,
710
    GPG_ERR_ESOCKTNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 125,
711
    GPG_ERR_ESPIPE = GPG_ERR_SYSTEM_ERROR | 126,
712
    GPG_ERR_ESRCH = GPG_ERR_SYSTEM_ERROR | 127,
713
    GPG_ERR_ESRMNT = GPG_ERR_SYSTEM_ERROR | 128,
714
    GPG_ERR_ESTALE = GPG_ERR_SYSTEM_ERROR | 129,
715
    GPG_ERR_ESTRPIPE = GPG_ERR_SYSTEM_ERROR | 130,
716
    GPG_ERR_ETIME = GPG_ERR_SYSTEM_ERROR | 131,
717
    GPG_ERR_ETIMEDOUT = GPG_ERR_SYSTEM_ERROR | 132,
718
    GPG_ERR_ETOOMANYREFS = GPG_ERR_SYSTEM_ERROR | 133,
719
    GPG_ERR_ETXTBSY = GPG_ERR_SYSTEM_ERROR | 134,
720
    GPG_ERR_EUCLEAN = GPG_ERR_SYSTEM_ERROR | 135,
721
    GPG_ERR_EUNATCH = GPG_ERR_SYSTEM_ERROR | 136,
722
    GPG_ERR_EUSERS = GPG_ERR_SYSTEM_ERROR | 137,
723
    GPG_ERR_EWOULDBLOCK = GPG_ERR_SYSTEM_ERROR | 138,
724
    GPG_ERR_EXDEV = GPG_ERR_SYSTEM_ERROR | 139,
725
    GPG_ERR_EXFULL = GPG_ERR_SYSTEM_ERROR | 140,
726
727
    /* This is one more than the largest allowed entry.  */
728
    GPG_ERR_CODE_DIM = 65536
729
  } gpg_err_code_t;
730
731

732
/* The error value type gpg_error_t.  */
733
734
/* We would really like to use bit-fields in a struct, but using
735
 * structs as return values can cause binary compatibility issues, in
736
 * particular if you want to do it efficiently (also see
737
 * -freg-struct-return option to GCC).  */
738
typedef unsigned int gpg_error_t;
739
740
/* We use the lowest 16 bits of gpg_error_t for error codes.  The 16th
741
 * bit indicates system errors.  */
742
336k
#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1)
743
744
/* Bits 17 to 24 are reserved.  */
745
746
/* We use the upper 7 bits of gpg_error_t for error sources.  */
747
0
#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
748
0
#define GPG_ERR_SOURCE_SHIFT  24
749
750
/* The highest bit is reserved.  It shouldn't be used to prevent
751
 * potential negative numbers when transmitting error values as
752
 * text.  */
753
754

755
/*
756
 * GCC feature test.
757
 */
758
#if __GNUC__
759
# define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \
760
                               + __GNUC_MINOR__ * 100 \
761
                               + __GNUC_PATCHLEVEL__)
762
#else
763
# define _GPG_ERR_GCC_VERSION 0
764
#endif
765
766
#undef _GPG_ERR_HAVE_CONSTRUCTOR
767
#if _GPG_ERR_GCC_VERSION > 30100
768
# define _GPG_ERR_CONSTRUCTOR __attribute__ ((__constructor__))
769
# define _GPG_ERR_HAVE_CONSTRUCTOR
770
#else
771
# define _GPG_ERR_CONSTRUCTOR
772
#endif
773
774
#define GPGRT_GCC_VERSION  _GPG_ERR_GCC_VERSION
775
776
#if _GPG_ERR_GCC_VERSION >= 29200
777
# define _GPGRT__RESTRICT __restrict__
778
#else
779
# define _GPGRT__RESTRICT
780
#endif
781
782
/* The noreturn attribute.  */
783
#if _GPG_ERR_GCC_VERSION >= 20500
784
# define GPGRT_ATTR_NORETURN   __attribute__ ((__noreturn__))
785
#else
786
# define GPGRT_ATTR_NORETURN
787
#endif
788
789
/* The printf attributes.  */
790
#if _GPG_ERR_GCC_VERSION >= 40400
791
# define GPGRT_ATTR_PRINTF(f, a) \
792
                    __attribute__ ((format(__gnu_printf__,f,a)))
793
# define GPGRT_ATTR_NR_PRINTF(f, a) \
794
                    __attribute__ ((__noreturn__, format(__gnu_printf__,f,a)))
795
#elif _GPG_ERR_GCC_VERSION >= 20500
796
# define GPGRT_ATTR_PRINTF(f, a) \
797
                    __attribute__ ((format(printf,f,a)))
798
# define GPGRT_ATTR_NR_PRINTF(f, a) \
799
                    __attribute__ ((__noreturn__, format(printf,f,a)))
800
#else
801
# define GPGRT_ATTR_PRINTF(f, a)
802
# define GPGRT_ATTR_NR_PRINTF(f, a)
803
#endif
804
#if _GPG_ERR_GCC_VERSION >= 20800
805
# define GPGRT_ATTR_FORMAT_ARG(a)  __attribute__ ((__format_arg__ (a)))
806
#else
807
# define GPGRT_ATTR_FORMAT_ARG(a)
808
#endif
809
810
/* The sentinel attribute.  */
811
#if _GPG_ERR_GCC_VERSION >= 40000
812
# define GPGRT_ATTR_SENTINEL(a)  __attribute__ ((sentinel(a)))
813
#else
814
# define GPGRT_ATTR_SENTINEL(a)
815
#endif
816
817
/* The used and unused attributes.
818
 * I am not sure since when the unused attribute is really supported.
819
 * In any case it it only needed for gcc versions which print a
820
 * warning.  Thus let us require gcc >= 3.5.  */
821
#if _GPG_ERR_GCC_VERSION >= 40000
822
# define GPGRT_ATTR_USED  __attribute__ ((used))
823
#else
824
# define GPGRT_ATTR_USED
825
#endif
826
#if _GPG_ERR_GCC_VERSION >= 30500
827
# define GPGRT_ATTR_UNUSED  __attribute__ ((unused))
828
#else
829
# define GPGRT_ATTR_UNUSED
830
#endif
831
832
/* The deprecated attribute.  */
833
#if _GPG_ERR_GCC_VERSION >= 30100
834
# define GPGRT_ATTR_DEPRECATED  __attribute__ ((__deprecated__))
835
#else
836
# define GPGRT_ATTR_DEPRECATED
837
#endif
838
839
/* The pure attribute.  */
840
#if _GPG_ERR_GCC_VERSION >= 29600
841
# define GPGRT_ATTR_PURE  __attribute__ ((__pure__))
842
#else
843
# define GPGRT_ATTR_PURE
844
#endif
845
846
/* The malloc attribute.  */
847
#if _GPG_ERR_GCC_VERSION >= 30200
848
# define GPGRT_ATTR_MALLOC  __attribute__ ((__malloc__))
849
#else
850
# define GPGRT_ATTR_MALLOC
851
#endif
852
853
/* A macro defined if a GCC style __FUNCTION__ macro is available.  */
854
#undef GPGRT_HAVE_MACRO_FUNCTION
855
#if _GPG_ERR_GCC_VERSION >= 20500
856
# define GPGRT_HAVE_MACRO_FUNCTION 1
857
#endif
858
859
/* A macro defined if the pragma GCC push_options is available.  */
860
#undef GPGRT_HAVE_PRAGMA_GCC_PUSH
861
#if _GPG_ERR_GCC_VERSION >= 40400
862
# define GPGRT_HAVE_PRAGMA_GCC_PUSH 1
863
#endif
864
865
/* Detect LeakSanitizer (LSan) support for GCC and Clang based on
866
 * whether AddressSanitizer (ASAN) is enabled via -fsanitize=address).
867
 * Note that -fsanitize=leak just affect the linker options which
868
 * cannot be detected here.  In that case you have to define the
869
 * GPGRT_HAVE_LEAK_SANITIZER macro manually.  */
870
#ifdef __GNUC__
871
# ifdef __SANITIZE_ADDRESS__
872
#  define GPGRT_HAVE_LEAK_SANITIZER
873
# elif defined(__has_feature)
874
#  if __has_feature(address_sanitizer)
875
#   define GPGRT_HAVE_LEAK_SANITIZER
876
#  endif
877
# endif
878
#endif
879
880
881
/* The new name for the inline macro.  */
882
#define GPGRT_INLINE GPG_ERR_INLINE
883
884
#ifdef GPGRT_HAVE_LEAK_SANITIZER
885
# include <sanitizer/lsan_interface.h>
886
#endif
887
888
/* Mark heap objects as non-leaked memory. */
889
static GPGRT_INLINE void
890
gpgrt_annotate_leaked_object (const void *p)
891
0
{
892
#ifdef GPGRT_HAVE_LEAK_SANITIZER
893
  __lsan_ignore_object(p);
894
#else
895
0
  (void)p;
896
0
#endif
897
0
}
Unexecuted instantiation: visibility.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: sysutils.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: stringutils.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: syscall-clamp.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: logging.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: b64dec.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: b64enc.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: argparse.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: posix-lock.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: posix-thread.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: init.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: version.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: estream.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: estream-printf.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: strsource.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: strerror.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: code-to-errno.c:gpgrt_annotate_leaked_object
Unexecuted instantiation: code-from-errno.c:gpgrt_annotate_leaked_object
898
899

900
/*
901
 * Initialization function.
902
 */
903
904
/* Initialize the library.  This function should be run early.  */
905
gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR;
906
907
/* If this is defined, the library is already initialized by the
908
   constructor and does not need to be initialized explicitely.  */
909
#undef GPG_ERR_INITIALIZED
910
#ifdef _GPG_ERR_HAVE_CONSTRUCTOR
911
# define GPG_ERR_INITIALIZED  1
912
# define gpgrt_init() do { gpg_err_init (); } while (0)
913
#else
914
# define gpgrt_init() do { ; } while (0)
915
#endif
916
917
/* See the source on how to use the deinit function; it is usually not
918
   required.  */
919
void gpg_err_deinit (int mode);
920
921
/* Register blocking system I/O clamping functions.  */
922
void gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void));
923
924
/* Get current I/O clamping functions.  */
925
void gpgrt_get_syscall_clamp (void (**r_pre)(void), void (**r_post)(void));
926
927
/* Register a custom malloc/realloc/free function.  */
928
void gpgrt_set_alloc_func  (void *(*f)(void *a, size_t n));
929
930
/* Register an emergency cleanup handler.  */
931
void gpgrt_add_emergency_cleanup (void (*f)(void));
932
933
/* Wrapper around abort to make sure emergency cleanups are run.  */
934
void gpgrt_abort (void) GPGRT_ATTR_NORETURN;
935
936
937

938
/*
939
 * Constructor and accessor functions.
940
 */
941
942
/* Construct an error value from an error code and source.  Within a
943
 * subsystem, use gpg_error.  */
944
static GPG_ERR_INLINE gpg_error_t
945
gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
946
0
{
947
0
  return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
948
0
    : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
949
0
       | (code & GPG_ERR_CODE_MASK));
950
0
}
Unexecuted instantiation: sysutils.c:gpg_err_make
Unexecuted instantiation: stringutils.c:gpg_err_make
Unexecuted instantiation: syscall-clamp.c:gpg_err_make
Unexecuted instantiation: logging.c:gpg_err_make
Unexecuted instantiation: b64dec.c:gpg_err_make
Unexecuted instantiation: b64enc.c:gpg_err_make
Unexecuted instantiation: argparse.c:gpg_err_make
Unexecuted instantiation: posix-lock.c:gpg_err_make
Unexecuted instantiation: posix-thread.c:gpg_err_make
Unexecuted instantiation: init.c:gpg_err_make
Unexecuted instantiation: version.c:gpg_err_make
Unexecuted instantiation: estream.c:gpg_err_make
Unexecuted instantiation: estream-printf.c:gpg_err_make
Unexecuted instantiation: strsource.c:gpg_err_make
Unexecuted instantiation: strerror.c:gpg_err_make
Unexecuted instantiation: code-to-errno.c:gpg_err_make
Unexecuted instantiation: code-from-errno.c:gpg_err_make
951
952
953
/* The user should define GPG_ERR_SOURCE_DEFAULT before including this
954
 * file to specify a default source for gpg_error.  */
955
#ifndef GPG_ERR_SOURCE_DEFAULT
956
0
#define GPG_ERR_SOURCE_DEFAULT  GPG_ERR_SOURCE_UNKNOWN
957
#endif
958
959
static GPG_ERR_INLINE gpg_error_t
960
gpg_error (gpg_err_code_t code)
961
0
{
962
0
  return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
963
0
}
Unexecuted instantiation: sysutils.c:gpg_error
Unexecuted instantiation: stringutils.c:gpg_error
Unexecuted instantiation: syscall-clamp.c:gpg_error
Unexecuted instantiation: logging.c:gpg_error
Unexecuted instantiation: b64dec.c:gpg_error
Unexecuted instantiation: b64enc.c:gpg_error
Unexecuted instantiation: argparse.c:gpg_error
Unexecuted instantiation: posix-lock.c:gpg_error
Unexecuted instantiation: posix-thread.c:gpg_error
Unexecuted instantiation: init.c:gpg_error
Unexecuted instantiation: version.c:gpg_error
Unexecuted instantiation: estream.c:gpg_error
Unexecuted instantiation: estream-printf.c:gpg_error
Unexecuted instantiation: strsource.c:gpg_error
Unexecuted instantiation: strerror.c:gpg_error
Unexecuted instantiation: code-to-errno.c:gpg_error
Unexecuted instantiation: code-from-errno.c:gpg_error
964
965
966
/* Retrieve the error code from an error value.  */
967
static GPG_ERR_INLINE gpg_err_code_t
968
gpg_err_code (gpg_error_t err)
969
336k
{
970
336k
  return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
971
336k
}
Unexecuted instantiation: visibility.c:gpg_err_code
Unexecuted instantiation: sysutils.c:gpg_err_code
Unexecuted instantiation: stringutils.c:gpg_err_code
Unexecuted instantiation: syscall-clamp.c:gpg_err_code
Unexecuted instantiation: logging.c:gpg_err_code
Unexecuted instantiation: b64dec.c:gpg_err_code
Unexecuted instantiation: b64enc.c:gpg_err_code
Unexecuted instantiation: argparse.c:gpg_err_code
Unexecuted instantiation: posix-lock.c:gpg_err_code
Unexecuted instantiation: posix-thread.c:gpg_err_code
Unexecuted instantiation: init.c:gpg_err_code
Unexecuted instantiation: version.c:gpg_err_code
Unexecuted instantiation: estream.c:gpg_err_code
Unexecuted instantiation: estream-printf.c:gpg_err_code
Unexecuted instantiation: strsource.c:gpg_err_code
strerror.c:gpg_err_code
Line
Count
Source
969
336k
{
970
336k
  return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
971
336k
}
Unexecuted instantiation: code-to-errno.c:gpg_err_code
Unexecuted instantiation: code-from-errno.c:gpg_err_code
972
973
974
/* Retrieve the error source from an error value.  */
975
static GPG_ERR_INLINE gpg_err_source_t
976
gpg_err_source (gpg_error_t err)
977
0
{
978
0
  return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
979
0
           & GPG_ERR_SOURCE_MASK);
980
0
}
Unexecuted instantiation: visibility.c:gpg_err_source
Unexecuted instantiation: sysutils.c:gpg_err_source
Unexecuted instantiation: stringutils.c:gpg_err_source
Unexecuted instantiation: syscall-clamp.c:gpg_err_source
Unexecuted instantiation: logging.c:gpg_err_source
Unexecuted instantiation: b64dec.c:gpg_err_source
Unexecuted instantiation: b64enc.c:gpg_err_source
Unexecuted instantiation: argparse.c:gpg_err_source
Unexecuted instantiation: posix-lock.c:gpg_err_source
Unexecuted instantiation: posix-thread.c:gpg_err_source
Unexecuted instantiation: init.c:gpg_err_source
Unexecuted instantiation: version.c:gpg_err_source
Unexecuted instantiation: estream.c:gpg_err_source
Unexecuted instantiation: estream-printf.c:gpg_err_source
Unexecuted instantiation: strsource.c:gpg_err_source
Unexecuted instantiation: strerror.c:gpg_err_source
Unexecuted instantiation: code-to-errno.c:gpg_err_source
Unexecuted instantiation: code-from-errno.c:gpg_err_source
981
982

983
/* String functions.  */
984
985
/* Return a pointer to a string containing a description of the error
986
 * code in the error value ERR.  This function is not thread-safe.  */
987
const char *gpg_strerror (gpg_error_t err);
988
989
/* Return the error string for ERR in the user-supplied buffer BUF of
990
 * size BUFLEN.  This function is, in contrast to gpg_strerror,
991
 * thread-safe if a thread-safe strerror_r() function is provided by
992
 * the system.  If the function succeeds, 0 is returned and BUF
993
 * contains the string describing the error.  If the buffer was not
994
 * large enough, ERANGE is returned and BUF contains as much of the
995
 * beginning of the error string as fits into the buffer.  */
996
int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
997
998
/* Return a pointer to a string containing a description of the error
999
 * source in the error value ERR.  */
1000
const char *gpg_strsource (gpg_error_t err);
1001
1002

1003
/*
1004
 * Mapping of system errors (errno).
1005
 */
1006
1007
/* Retrieve the error code for the system error ERR.  This returns
1008
 * GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
1009
 * this). */
1010
gpg_err_code_t gpg_err_code_from_errno (int err);
1011
1012
/* Retrieve the system error for the error code CODE.  This returns 0
1013
 * if CODE is not a system error code.  */
1014
int gpg_err_code_to_errno (gpg_err_code_t code);
1015
1016
/* Retrieve the error code directly from the ERRNO variable.  This
1017
 * returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
1018
 * (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
1019
gpg_err_code_t gpg_err_code_from_syserror (void);
1020
1021
/* Mapper for SQLite primary error codes.  */
1022
static GPG_ERR_INLINE gpg_error_t
1023
gpg_err_code_from_sqlite (int sqlres)
1024
0
{
1025
0
  return sqlres? GPG_ERR_SQL_OK + (sqlres & 0xff) : 0;
1026
0
}
Unexecuted instantiation: visibility.c:gpg_err_code_from_sqlite
Unexecuted instantiation: sysutils.c:gpg_err_code_from_sqlite
Unexecuted instantiation: stringutils.c:gpg_err_code_from_sqlite
Unexecuted instantiation: syscall-clamp.c:gpg_err_code_from_sqlite
Unexecuted instantiation: logging.c:gpg_err_code_from_sqlite
Unexecuted instantiation: b64dec.c:gpg_err_code_from_sqlite
Unexecuted instantiation: b64enc.c:gpg_err_code_from_sqlite
Unexecuted instantiation: argparse.c:gpg_err_code_from_sqlite
Unexecuted instantiation: posix-lock.c:gpg_err_code_from_sqlite
Unexecuted instantiation: posix-thread.c:gpg_err_code_from_sqlite
Unexecuted instantiation: init.c:gpg_err_code_from_sqlite
Unexecuted instantiation: version.c:gpg_err_code_from_sqlite
Unexecuted instantiation: estream.c:gpg_err_code_from_sqlite
Unexecuted instantiation: estream-printf.c:gpg_err_code_from_sqlite
Unexecuted instantiation: strsource.c:gpg_err_code_from_sqlite
Unexecuted instantiation: strerror.c:gpg_err_code_from_sqlite
Unexecuted instantiation: code-to-errno.c:gpg_err_code_from_sqlite
Unexecuted instantiation: code-from-errno.c:gpg_err_code_from_sqlite
1027
1028
1029
/* Set the ERRNO variable.  This function is the preferred way to set
1030
 * ERRNO due to peculiarities on WindowsCE.  */
1031
void gpg_err_set_errno (int err);
1032
1033
/* Return or check the version.  Both functions are identical.  */
1034
const char *gpgrt_check_version (const char *req_version);
1035
const char *gpg_error_check_version (const char *req_version);
1036
1037
/* System specific type definitions.  */
1038
#include <sys/types.h>
1039
typedef pid_t gpgrt_process_t;
1040
1041
typedef ssize_t gpgrt_ssize_t;
1042
1043
typedef long gpgrt_off_t;
1044
1045
1046
1047

1048
/* Self-documenting convenience functions.  */
1049
1050
static GPG_ERR_INLINE gpg_error_t
1051
gpg_err_make_from_errno (gpg_err_source_t source, int err)
1052
0
{
1053
0
  return gpg_err_make (source, gpg_err_code_from_errno (err));
1054
0
}
Unexecuted instantiation: visibility.c:gpg_err_make_from_errno
Unexecuted instantiation: sysutils.c:gpg_err_make_from_errno
Unexecuted instantiation: stringutils.c:gpg_err_make_from_errno
Unexecuted instantiation: syscall-clamp.c:gpg_err_make_from_errno
Unexecuted instantiation: logging.c:gpg_err_make_from_errno
Unexecuted instantiation: b64dec.c:gpg_err_make_from_errno
Unexecuted instantiation: b64enc.c:gpg_err_make_from_errno
Unexecuted instantiation: argparse.c:gpg_err_make_from_errno
Unexecuted instantiation: posix-lock.c:gpg_err_make_from_errno
Unexecuted instantiation: posix-thread.c:gpg_err_make_from_errno
Unexecuted instantiation: init.c:gpg_err_make_from_errno
Unexecuted instantiation: version.c:gpg_err_make_from_errno
Unexecuted instantiation: estream.c:gpg_err_make_from_errno
Unexecuted instantiation: estream-printf.c:gpg_err_make_from_errno
Unexecuted instantiation: strsource.c:gpg_err_make_from_errno
Unexecuted instantiation: strerror.c:gpg_err_make_from_errno
Unexecuted instantiation: code-to-errno.c:gpg_err_make_from_errno
Unexecuted instantiation: code-from-errno.c:gpg_err_make_from_errno
1055
1056
1057
static GPG_ERR_INLINE gpg_error_t
1058
gpg_error_from_errno (int err)
1059
0
{
1060
0
  return gpg_error (gpg_err_code_from_errno (err));
1061
0
}
Unexecuted instantiation: visibility.c:gpg_error_from_errno
Unexecuted instantiation: sysutils.c:gpg_error_from_errno
Unexecuted instantiation: stringutils.c:gpg_error_from_errno
Unexecuted instantiation: syscall-clamp.c:gpg_error_from_errno
Unexecuted instantiation: logging.c:gpg_error_from_errno
Unexecuted instantiation: b64dec.c:gpg_error_from_errno
Unexecuted instantiation: b64enc.c:gpg_error_from_errno
Unexecuted instantiation: argparse.c:gpg_error_from_errno
Unexecuted instantiation: posix-lock.c:gpg_error_from_errno
Unexecuted instantiation: posix-thread.c:gpg_error_from_errno
Unexecuted instantiation: init.c:gpg_error_from_errno
Unexecuted instantiation: version.c:gpg_error_from_errno
Unexecuted instantiation: estream.c:gpg_error_from_errno
Unexecuted instantiation: estream-printf.c:gpg_error_from_errno
Unexecuted instantiation: strsource.c:gpg_error_from_errno
Unexecuted instantiation: strerror.c:gpg_error_from_errno
Unexecuted instantiation: code-to-errno.c:gpg_error_from_errno
Unexecuted instantiation: code-from-errno.c:gpg_error_from_errno
1062
1063
static GPG_ERR_INLINE gpg_error_t
1064
gpg_error_from_syserror (void)
1065
0
{
1066
0
  return gpg_error (gpg_err_code_from_syserror ());
1067
0
}
Unexecuted instantiation: visibility.c:gpg_error_from_syserror
Unexecuted instantiation: sysutils.c:gpg_error_from_syserror
Unexecuted instantiation: stringutils.c:gpg_error_from_syserror
Unexecuted instantiation: syscall-clamp.c:gpg_error_from_syserror
Unexecuted instantiation: logging.c:gpg_error_from_syserror
Unexecuted instantiation: b64dec.c:gpg_error_from_syserror
Unexecuted instantiation: b64enc.c:gpg_error_from_syserror
Unexecuted instantiation: argparse.c:gpg_error_from_syserror
Unexecuted instantiation: posix-lock.c:gpg_error_from_syserror
Unexecuted instantiation: posix-thread.c:gpg_error_from_syserror
Unexecuted instantiation: init.c:gpg_error_from_syserror
Unexecuted instantiation: version.c:gpg_error_from_syserror
Unexecuted instantiation: estream.c:gpg_error_from_syserror
Unexecuted instantiation: estream-printf.c:gpg_error_from_syserror
Unexecuted instantiation: strsource.c:gpg_error_from_syserror
Unexecuted instantiation: strerror.c:gpg_error_from_syserror
Unexecuted instantiation: code-to-errno.c:gpg_error_from_syserror
Unexecuted instantiation: code-from-errno.c:gpg_error_from_syserror
1068
1069
1070

1071
/*
1072
 * Malloc and friends
1073
 */
1074
1075
void *gpgrt_realloc (void *a, size_t n);
1076
void *gpgrt_reallocarray (void *a, size_t oldnmemb, size_t nmemb, size_t size);
1077
void *gpgrt_malloc (size_t n);
1078
void *gpgrt_calloc (size_t n, size_t m);
1079
char *gpgrt_strdup (const char *string);
1080
char *gpgrt_strconcat (const char *s1, ...) GPGRT_ATTR_SENTINEL(0);
1081
void gpgrt_free (void *a);
1082
1083
1084
/*
1085
 * System specific function wrappers.
1086
 */
1087
1088
/* A getenv replacement which mallocs the returned string.  */
1089
char *gpgrt_getenv (const char *name);
1090
1091
/* A setenv and a unsetenv replacement.*/
1092
gpg_err_code_t gpgrt_setenv (const char *name,
1093
                             const char *value, int overwrite);
1094
#define gpgrt_unsetenv(n) gpgrt_setenv ((n), NULL, 1)
1095
1096
/* A wrapper around mkdir using a string for the mode.  */
1097
gpg_err_code_t gpgrt_mkdir (const char *name, const char *modestr);
1098
1099
/* A simple wrapper around chdir.  */
1100
gpg_err_code_t gpgrt_chdir (const char *name);
1101
1102
/* Return the current WD as a malloced string.  */
1103
char *gpgrt_getcwd (void);
1104
1105
/* A wrapper around access to handle UTF-8 on Windows.  */
1106
gpg_err_code_t gpgrt_access (const char *fname, int mode);
1107
1108
1109
1110

1111
/*
1112
 * Lock functions.
1113
 */
1114
1115
1116
typedef struct
1117
{
1118
  long _vers;
1119
  union {
1120
    volatile char _priv[40];
1121
    long _x_align;
1122
    long *_xp_align;
1123
  } u;
1124
} gpgrt_lock_t;
1125
1126
3.54k
#define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \
1127
3.54k
                                    0,0,0,0,0,0,0,0, \
1128
3.54k
                                    0,0,0,0,0,0,0,0, \
1129
3.54k
                                    0,0,0,0,0,0,0,0, \
1130
3.54k
                                    0,0,0,0,0,0,0,0}}}
1131
1132
1133
#define GPGRT_LOCK_DEFINE(name) \
1134
  static gpgrt_lock_t name  = GPGRT_LOCK_INITIALIZER
1135
1136
/* NB: If GPGRT_LOCK_DEFINE is not used, zero out the lock variable
1137
   before passing it to gpgrt_lock_init.  */
1138
gpg_err_code_t gpgrt_lock_init (gpgrt_lock_t *lockhd);
1139
gpg_err_code_t gpgrt_lock_lock (gpgrt_lock_t *lockhd);
1140
gpg_err_code_t gpgrt_lock_trylock (gpgrt_lock_t *lockhd);
1141
gpg_err_code_t gpgrt_lock_unlock (gpgrt_lock_t *lockhd);
1142
gpg_err_code_t gpgrt_lock_destroy (gpgrt_lock_t *lockhd);
1143
1144
1145

1146
/*
1147
 * Thread functions.
1148
 */
1149
1150
gpg_err_code_t gpgrt_yield (void);
1151
1152
1153
1154

1155
/*
1156
 * Estream
1157
 */
1158
1159
/* The definition of this struct is entirely private.  You must not
1160
   use it for anything.  It is only here so some functions can be
1161
   implemented as macros.  */
1162
struct _gpgrt_stream_internal;
1163
struct _gpgrt__stream
1164
{
1165
  /* The layout of this struct must never change.  It may be grown,
1166
     but only if all functions which access the new members are
1167
     versioned.  */
1168
1169
  /* Various flags.  */
1170
  struct {
1171
    unsigned int magic: 16;
1172
    unsigned int writing: 1;
1173
    unsigned int reserved: 15;
1174
  } flags;
1175
1176
  /* A pointer to the stream buffer.  */
1177
  unsigned char *buffer;
1178
1179
  /* The size of the buffer in bytes.  */
1180
  size_t buffer_size;
1181
1182
  /* The length of the usable data in the buffer, only valid when in
1183
     read mode (see flags).  */
1184
  size_t data_len;
1185
1186
  /* The current position of the offset pointer, valid in read and
1187
     write mode.  */
1188
  size_t data_offset;
1189
1190
  size_t data_flushed;
1191
  unsigned char *unread_buffer;
1192
  size_t unread_buffer_size;
1193
1194
  /* The number of unread bytes.  */
1195
  size_t unread_data_len;
1196
1197
  /* A pointer to our internal data for this stream.  */
1198
  struct _gpgrt_stream_internal *intern;
1199
};
1200
1201
/* The opaque type for an estream.  */
1202
typedef struct _gpgrt__stream *gpgrt_stream_t;
1203
#ifdef GPGRT_ENABLE_ES_MACROS
1204
typedef struct _gpgrt__stream *estream_t;
1205
#endif
1206
1207
typedef ssize_t (*gpgrt_cookie_read_function_t) (void *cookie,
1208
                                                 void *buffer, size_t size);
1209
typedef ssize_t (*gpgrt_cookie_write_function_t) (void *cookie,
1210
                                                  const void *buffer,
1211
                                                  size_t size);
1212
typedef int (*gpgrt_cookie_seek_function_t) (void *cookie,
1213
                                             gpgrt_off_t *pos, int whence);
1214
typedef int (*gpgrt_cookie_close_function_t) (void *cookie);
1215
1216
struct _gpgrt_cookie_io_functions
1217
{
1218
  gpgrt_cookie_read_function_t func_read;
1219
  gpgrt_cookie_write_function_t func_write;
1220
  gpgrt_cookie_seek_function_t func_seek;
1221
  gpgrt_cookie_close_function_t func_close;
1222
};
1223
typedef struct _gpgrt_cookie_io_functions gpgrt_cookie_io_functions_t;
1224
#ifdef GPGRT_ENABLE_ES_MACROS
1225
typedef struct _gpgrt_cookie_io_functions  es_cookie_io_functions_t;
1226
#define es_cookie_read_function_t  gpgrt_cookie_read_function_t
1227
#define es_cookie_write_function_t gpgrt_cookie_read_function_t
1228
#define es_cookie_seek_function_t  gpgrt_cookie_read_function_t
1229
#define es_cookie_close_function_t gpgrt_cookie_read_function_t
1230
#endif
1231
1232
enum gpgrt_syshd_types
1233
  {
1234
    GPGRT_SYSHD_NONE = 0,  /* No system handle available.                   */
1235
    GPGRT_SYSHD_FD = 1,    /* A file descriptor as returned by open().      */
1236
    GPGRT_SYSHD_SOCK = 2,  /* A socket as returned by socket().             */
1237
    GPGRT_SYSHD_RVID = 3,  /* A rendezvous id (see libassuan's gpgcedev.c).  */
1238
    GPGRT_SYSHD_HANDLE = 4 /* A HANDLE object (Windows).                    */
1239
  };
1240
1241
struct _gpgrt_syshd
1242
{
1243
  enum gpgrt_syshd_types type;
1244
  union {
1245
    int fd;
1246
    int sock;
1247
    int rvid;
1248
    void *handle;
1249
  } u;
1250
};
1251
typedef struct _gpgrt_syshd gpgrt_syshd_t;
1252
#ifdef GPGRT_ENABLE_ES_MACROS
1253
typedef struct _gpgrt_syshd es_syshd_t;
1254
0
#define ES_SYSHD_NONE   GPGRT_SYSHD_NONE
1255
3.54k
#define ES_SYSHD_FD     GPGRT_SYSHD_FD
1256
0
#define ES_SYSHD_SOCK   GPGRT_SYSHD_SOCK
1257
#define ES_SYSHD_RVID   GPGRT_SYSHD_RVID
1258
#define ES_SYSHD_HANDLE GPGRT_SYSHD_HANDLE
1259
#endif
1260
1261
/* The object used with gpgrt_poll.  */
1262
struct _gpgrt_poll_s
1263
{
1264
  gpgrt_stream_t stream;
1265
  unsigned int want_read:1;
1266
  unsigned int want_write:1;
1267
  unsigned int want_oob:1;
1268
  unsigned int want_rdhup:1;
1269
  unsigned int _reserv1:4;
1270
  unsigned int got_read:1;
1271
  unsigned int got_write:1;
1272
  unsigned int got_oob:1;
1273
  unsigned int got_rdhup:1;
1274
  unsigned int _reserv2:4;
1275
  unsigned int got_err:1;
1276
  unsigned int got_hup:1;
1277
  unsigned int got_nval:1;
1278
  unsigned int _reserv3:4;
1279
  unsigned int ignore:1;
1280
  unsigned int user:8;       /* For application use.  */
1281
};
1282
typedef struct _gpgrt_poll_s gpgrt_poll_t;
1283
#ifdef GPGRT_ENABLE_ES_MACROS
1284
typedef struct _gpgrt_poll_s es_poll_t;
1285
#endif
1286
1287
/* The type of the string filter function as used by fprintf_sf et al.  */
1288
typedef char *(*gpgrt_string_filter_t) (const char *s, int n, void *opaque);
1289
1290
1291
1292
gpgrt_stream_t gpgrt_fopen (const char *_GPGRT__RESTRICT path,
1293
                            const char *_GPGRT__RESTRICT mode);
1294
gpgrt_stream_t gpgrt_mopen (void *_GPGRT__RESTRICT data,
1295
                            size_t data_n, size_t data_len,
1296
                            unsigned int grow,
1297
                            void *(*func_realloc) (void *mem, size_t size),
1298
                            void (*func_free) (void *mem),
1299
                            const char *_GPGRT__RESTRICT mode);
1300
gpgrt_stream_t gpgrt_fopenmem (size_t memlimit,
1301
                               const char *_GPGRT__RESTRICT mode);
1302
gpgrt_stream_t gpgrt_fopenmem_init (size_t memlimit,
1303
                                    const char *_GPGRT__RESTRICT mode,
1304
                                    const void *data, size_t datalen);
1305
gpgrt_stream_t gpgrt_fdopen    (int filedes, const char *mode);
1306
gpgrt_stream_t gpgrt_fdopen_nc (int filedes, const char *mode);
1307
gpgrt_stream_t gpgrt_sysopen    (gpgrt_syshd_t *syshd, const char *mode);
1308
gpgrt_stream_t gpgrt_sysopen_nc (gpgrt_syshd_t *syshd, const char *mode);
1309
gpgrt_stream_t gpgrt_fpopen    (FILE *fp, const char *mode);
1310
gpgrt_stream_t gpgrt_fpopen_nc (FILE *fp, const char *mode);
1311
gpgrt_stream_t gpgrt_freopen (const char *_GPGRT__RESTRICT path,
1312
                              const char *_GPGRT__RESTRICT mode,
1313
                              gpgrt_stream_t _GPGRT__RESTRICT stream);
1314
gpgrt_stream_t gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie,
1315
                                  const char *_GPGRT__RESTRICT mode,
1316
                                  gpgrt_cookie_io_functions_t functions);
1317
int gpgrt_fclose (gpgrt_stream_t stream);
1318
int gpgrt_fcancel (gpgrt_stream_t stream);
1319
int gpgrt_fclose_snatch (gpgrt_stream_t stream,
1320
                         void **r_buffer, size_t *r_buflen);
1321
int gpgrt_onclose (gpgrt_stream_t stream, int mode,
1322
                   void (*fnc) (gpgrt_stream_t, void*), void *fnc_value);
1323
int gpgrt_fileno (gpgrt_stream_t stream);
1324
int gpgrt_fileno_unlocked (gpgrt_stream_t stream);
1325
int gpgrt_syshd (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
1326
int gpgrt_syshd_unlocked (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
1327
1328
void _gpgrt_set_std_fd (int no, int fd);
1329
gpgrt_stream_t _gpgrt_get_std_stream (int fd);
1330
1331
#define gpgrt_stdin  _gpgrt_get_std_stream (0)
1332
#define gpgrt_stdout _gpgrt_get_std_stream (1)
1333
#define gpgrt_stderr _gpgrt_get_std_stream (2)
1334
1335
1336
void gpgrt_flockfile (gpgrt_stream_t stream);
1337
int  gpgrt_ftrylockfile (gpgrt_stream_t stream);
1338
void gpgrt_funlockfile (gpgrt_stream_t stream);
1339
1340
int gpgrt_feof (gpgrt_stream_t stream);
1341
int gpgrt_feof_unlocked (gpgrt_stream_t stream);
1342
int gpgrt_ferror (gpgrt_stream_t stream);
1343
int gpgrt_ferror_unlocked (gpgrt_stream_t stream);
1344
void gpgrt_clearerr (gpgrt_stream_t stream);
1345
void gpgrt_clearerr_unlocked (gpgrt_stream_t stream);
1346
1347
int _gpgrt_pending (gpgrt_stream_t stream);          /* (private) */
1348
int _gpgrt_pending_unlocked (gpgrt_stream_t stream); /* (private) */
1349
1350
#define gpgrt_pending(stream) _gpgrt_pending (stream)
1351
1352
#define gpgrt_pending_unlocked(stream)        \
1353
  (((!(stream)->flags.writing)          \
1354
    && (((stream)->data_offset < (stream)->data_len)    \
1355
        || ((stream)->unread_data_len)))                        \
1356
   ? 1 : _gpgrt_pending_unlocked ((stream)))
1357
1358
int gpgrt_fflush (gpgrt_stream_t stream);
1359
int gpgrt_fseek (gpgrt_stream_t stream, long int offset, int whence);
1360
int gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence);
1361
int gpgrt_ftruncate (gpgrt_stream_t stream, gpgrt_off_t length);
1362
long int gpgrt_ftell (gpgrt_stream_t stream);
1363
gpgrt_off_t gpgrt_ftello (gpgrt_stream_t stream);
1364
void gpgrt_rewind (gpgrt_stream_t stream);
1365
1366
int gpgrt_fgetc (gpgrt_stream_t stream);
1367
int gpgrt_fputc (int c, gpgrt_stream_t stream);
1368
1369
int _gpgrt_getc_underflow (gpgrt_stream_t stream);       /* (private) */
1370
int _gpgrt_putc_overflow (int c, gpgrt_stream_t stream); /* (private) */
1371
1372
#define gpgrt_getc_unlocked(stream)       \
1373
  (((!(stream)->flags.writing)          \
1374
    && ((stream)->data_offset < (stream)->data_len)   \
1375
    && (! (stream)->unread_data_len))       \
1376
  ? ((int) (stream)->buffer[((stream)->data_offset)++])   \
1377
  : _gpgrt_getc_underflow ((stream)))
1378
1379
#define gpgrt_putc_unlocked(c, stream)        \
1380
  (((stream)->flags.writing         \
1381
    && ((stream)->data_offset < (stream)->buffer_size)    \
1382
    && (c != '\n'))           \
1383
  ? ((int) ((stream)->buffer[((stream)->data_offset)++] = (c))) \
1384
  : _gpgrt_putc_overflow ((c), (stream)))
1385
1386
#define gpgrt_getc(stream)    gpgrt_fgetc (stream)
1387
#define gpgrt_putc(c, stream) gpgrt_fputc (c, stream)
1388
1389
int gpgrt_ungetc (int c, gpgrt_stream_t stream);
1390
1391
int gpgrt_read (gpgrt_stream_t _GPGRT__RESTRICT stream,
1392
                void *_GPGRT__RESTRICT buffer, size_t bytes_to_read,
1393
                size_t *_GPGRT__RESTRICT bytes_read);
1394
int gpgrt_write (gpgrt_stream_t _GPGRT__RESTRICT stream,
1395
                 const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write,
1396
                 size_t *_GPGRT__RESTRICT bytes_written);
1397
int gpgrt_write_sanitized (gpgrt_stream_t _GPGRT__RESTRICT stream,
1398
                           const void *_GPGRT__RESTRICT buffer, size_t length,
1399
                           const char *delimiters,
1400
                           size_t *_GPGRT__RESTRICT bytes_written);
1401
int gpgrt_write_hexstring (gpgrt_stream_t _GPGRT__RESTRICT stream,
1402
                           const void *_GPGRT__RESTRICT buffer, size_t length,
1403
                           int reserved,
1404
                           size_t *_GPGRT__RESTRICT bytes_written);
1405
1406
size_t gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems,
1407
                    gpgrt_stream_t _GPGRT__RESTRICT stream);
1408
size_t gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr, size_t size,
1409
                     size_t nitems, gpgrt_stream_t _GPGRT__RESTRICT stream);
1410
1411
char *gpgrt_fgets (char *_GPGRT__RESTRICT s, int n,
1412
                   gpgrt_stream_t _GPGRT__RESTRICT stream);
1413
int gpgrt_fputs (const char *_GPGRT__RESTRICT s,
1414
                 gpgrt_stream_t _GPGRT__RESTRICT stream);
1415
int gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s,
1416
                          gpgrt_stream_t _GPGRT__RESTRICT stream);
1417
1418
ssize_t gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr,
1419
                       size_t *_GPGRT__RESTRICT n,
1420
                       gpgrt_stream_t stream);
1421
ssize_t gpgrt_read_line (gpgrt_stream_t stream,
1422
                         char **addr_of_buffer, size_t *length_of_buffer,
1423
                         size_t *max_length);
1424
1425
int gpgrt_fprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1426
                   const char *_GPGRT__RESTRICT format, ...)
1427
                   GPGRT_ATTR_PRINTF(2,3);
1428
int gpgrt_fprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
1429
                            const char *_GPGRT__RESTRICT format, ...)
1430
                            GPGRT_ATTR_PRINTF(2,3);
1431
1432
int gpgrt_fprintf_sf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1433
                      gpgrt_string_filter_t sf, void *sfvalue,
1434
                      const char *_GPGRT__RESTRICT format,
1435
                      ...) GPGRT_ATTR_PRINTF(4,5);
1436
int gpgrt_fprintf_sf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
1437
                               gpgrt_string_filter_t sf, void *sfvalue,
1438
                               const char *_GPGRT__RESTRICT format,
1439
                               ...) GPGRT_ATTR_PRINTF(4,5);
1440
1441
int gpgrt_printf (const char *_GPGRT__RESTRICT format, ...)
1442
                  GPGRT_ATTR_PRINTF(1,2);
1443
int gpgrt_printf_unlocked (const char *_GPGRT__RESTRICT format, ...)
1444
                           GPGRT_ATTR_PRINTF(1,2);
1445
1446
int gpgrt_vfprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1447
                    const char *_GPGRT__RESTRICT format, va_list ap)
1448
                    GPGRT_ATTR_PRINTF(2,0);
1449
int gpgrt_vfprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
1450
                             const char *_GPGRT__RESTRICT format, va_list ap)
1451
                             GPGRT_ATTR_PRINTF(2,0);
1452
1453
int gpgrt_setvbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1454
                   char *_GPGRT__RESTRICT buf, int mode, size_t size);
1455
void gpgrt_setbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1456
                   char *_GPGRT__RESTRICT buf);
1457
1458
void gpgrt_set_binary (gpgrt_stream_t stream);
1459
int  gpgrt_set_nonblock (gpgrt_stream_t stream, int onoff);
1460
int  gpgrt_get_nonblock (gpgrt_stream_t stream);
1461
1462
int gpgrt_poll (gpgrt_poll_t *fdlist, unsigned int nfds, int timeout);
1463
1464
gpgrt_stream_t gpgrt_tmpfile (void);
1465
1466
void gpgrt_opaque_set (gpgrt_stream_t _GPGRT__RESTRICT stream,
1467
                       void *_GPGRT__RESTRICT opaque);
1468
void *gpgrt_opaque_get (gpgrt_stream_t stream);
1469
1470
void gpgrt_fname_set (gpgrt_stream_t stream, const char *fname);
1471
const char *gpgrt_fname_get (gpgrt_stream_t stream);
1472
1473
int gpgrt_asprintf (char **r_buf, const char * _GPGRT__RESTRICT format, ...)
1474
                    GPGRT_ATTR_PRINTF(2,3);
1475
int gpgrt_vasprintf (char **r_buf, const char * _GPGRT__RESTRICT format,
1476
                     va_list ap)
1477
                     GPGRT_ATTR_PRINTF(2,0);
1478
char *gpgrt_bsprintf (const char * _GPGRT__RESTRICT format, ...)
1479
                      GPGRT_ATTR_PRINTF(1,2);
1480
char *gpgrt_vbsprintf (const char * _GPGRT__RESTRICT format, va_list ap)
1481
                       GPGRT_ATTR_PRINTF(1,0);
1482
int gpgrt_snprintf (char *buf, size_t bufsize,
1483
                    const char * _GPGRT__RESTRICT format, ...)
1484
                    GPGRT_ATTR_PRINTF(3,4);
1485
int gpgrt_vsnprintf (char *buf,size_t bufsize,
1486
                     const char * _GPGRT__RESTRICT format, va_list arg_ptr)
1487
                     GPGRT_ATTR_PRINTF(3,0);
1488
1489
1490
#ifdef GPGRT_ENABLE_ES_MACROS
1491
# define es_fopen             gpgrt_fopen
1492
# define es_mopen             gpgrt_mopen
1493
# define es_fopenmem          gpgrt_fopenmem
1494
# define es_fopenmem_init     gpgrt_fopenmem_init
1495
# define es_fdopen            gpgrt_fdopen
1496
# define es_fdopen_nc         gpgrt_fdopen_nc
1497
# define es_sysopen           gpgrt_sysopen
1498
# define es_sysopen_nc        gpgrt_sysopen_nc
1499
# define es_fpopen            gpgrt_fpopen
1500
# define es_fpopen_nc         gpgrt_fpopen_nc
1501
# define es_freopen           gpgrt_freopen
1502
# define es_fopencookie       gpgrt_fopencookie
1503
# define es_fclose            gpgrt_fclose
1504
# define es_fclose_snatch     gpgrt_fclose_snatch
1505
# define es_onclose           gpgrt_onclose
1506
# define es_fileno            gpgrt_fileno
1507
# define es_fileno_unlocked   gpgrt_fileno_unlocked
1508
# define es_syshd             gpgrt_syshd
1509
# define es_syshd_unlocked    gpgrt_syshd_unlocked
1510
# define es_stdin             _gpgrt_get_std_stream (0)
1511
# define es_stdout            _gpgrt_get_std_stream (1)
1512
# define es_stderr            _gpgrt_get_std_stream (2)
1513
# define es_flockfile         gpgrt_flockfile
1514
# define es_ftrylockfile      gpgrt_ftrylockfile
1515
# define es_funlockfile       gpgrt_funlockfile
1516
# define es_feof              gpgrt_feof
1517
# define es_feof_unlocked     gpgrt_feof_unlocked
1518
# define es_ferror            gpgrt_ferror
1519
# define es_ferror_unlocked   gpgrt_ferror_unlocked
1520
# define es_clearerr          gpgrt_clearerr
1521
# define es_clearerr_unlocked gpgrt_clearerr_unlocked
1522
# define es_pending           gpgrt_pending
1523
# define es_pending_unlocked  gpgrt_pending_unlocked
1524
# define es_fflush            gpgrt_fflush
1525
# define es_fseek             gpgrt_fseek
1526
# define es_fseeko            gpgrt_fseeko
1527
# define es_ftruncate         gpgrt_ftruncate
1528
# define es_ftell             gpgrt_ftell
1529
# define es_ftello            gpgrt_ftello
1530
# define es_rewind            gpgrt_rewind
1531
# define es_fgetc             gpgrt_fgetc
1532
# define es_fputc             gpgrt_fputc
1533
# define es_getc_unlocked     gpgrt_getc_unlocked
1534
# define es_putc_unlocked     gpgrt_putc_unlocked
1535
# define es_getc              gpgrt_getc
1536
# define es_putc              gpgrt_putc
1537
# define es_ungetc            gpgrt_ungetc
1538
# define es_read              gpgrt_read
1539
# define es_write             gpgrt_write
1540
# define es_write_sanitized   gpgrt_write_sanitized
1541
# define es_write_hexstring   gpgrt_write_hexstring
1542
# define es_fread             gpgrt_fread
1543
# define es_fwrite            gpgrt_fwrite
1544
# define es_fgets             gpgrt_fgets
1545
# define es_fputs             gpgrt_fputs
1546
# define es_fputs_unlocked    gpgrt_fputs_unlocked
1547
# define es_getline           gpgrt_getline
1548
# define es_read_line         gpgrt_read_line
1549
# define es_free              gpgrt_free
1550
# define es_fprintf           gpgrt_fprintf
1551
# define es_fprintf_unlocked  gpgrt_fprintf_unlocked
1552
# define es_printf            gpgrt_printf
1553
# define es_printf_unlocked   gpgrt_printf_unlocked
1554
# define es_vfprintf          gpgrt_vfprintf
1555
# define es_vfprintf_unlocked gpgrt_vfprintf_unlocked
1556
# define es_setvbuf           gpgrt_setvbuf
1557
# define es_setbuf            gpgrt_setbuf
1558
# define es_set_binary        gpgrt_set_binary
1559
# define es_set_nonblock      gpgrt_set_nonblock
1560
# define es_get_nonblock      gpgrt_get_nonblock
1561
# define es_poll              gpgrt_poll
1562
# define es_tmpfile           gpgrt_tmpfile
1563
# define es_opaque_set        gpgrt_opaque_set
1564
# define es_opaque_get        gpgrt_opaque_get
1565
# define es_fname_set         gpgrt_fname_set
1566
# define es_fname_get         gpgrt_fname_get
1567
# define es_asprintf          gpgrt_asprintf
1568
# define es_vasprintf         gpgrt_vasprintf
1569
# define es_bsprintf          gpgrt_bsprintf
1570
# define es_vbsprintf         gpgrt_vbsprintf
1571
#endif /*GPGRT_ENABLE_ES_MACROS*/
1572
1573
1574

1575
/*
1576
 * Base64 encode and decode functions.
1577
 */
1578
1579
struct _gpgrt_b64state;
1580
typedef struct _gpgrt_b64state *gpgrt_b64state_t;
1581
1582
gpgrt_b64state_t gpgrt_b64enc_start (gpgrt_stream_t stream, const char *title);
1583
gpg_err_code_t   gpgrt_b64enc_write (gpgrt_b64state_t state,
1584
                                     const void *buffer, size_t nbytes);
1585
gpg_err_code_t   gpgrt_b64enc_finish (gpgrt_b64state_t state);
1586
1587
gpgrt_b64state_t gpgrt_b64dec_start (const char *title);
1588
gpg_error_t      gpgrt_b64dec_proc (gpgrt_b64state_t state,
1589
                                    void *buffer, size_t length,
1590
                                    size_t *r_nbytes);
1591
gpg_error_t      gpgrt_b64dec_finish (gpgrt_b64state_t state);
1592
1593
1594

1595
/*
1596
 * Logging functions
1597
 */
1598
1599
/* Flag values for gpgrt_log_set_prefix. */
1600
0
#define GPGRT_LOG_WITH_PREFIX  1
1601
0
#define GPGRT_LOG_WITH_TIME    2
1602
0
#define GPGRT_LOG_WITH_PID     4
1603
0
#define GPGRT_LOG_RUN_DETACHED 256
1604
#define GPGRT_LOG_NO_REGISTRY  512
1605
1606
/* Log levels as used by gpgrt_log.  */
1607
enum gpgrt_log_levels
1608
  {
1609
    GPGRT_LOGLVL_BEGIN,
1610
    GPGRT_LOGLVL_CONT,
1611
    GPGRT_LOGLVL_INFO,
1612
    GPGRT_LOGLVL_WARN,
1613
    GPGRT_LOGLVL_ERROR,
1614
    GPGRT_LOGLVL_FATAL,
1615
    GPGRT_LOGLVL_BUG,
1616
    GPGRT_LOGLVL_DEBUG
1617
  };
1618
1619
1620
/* The next 4 functions are not thread-safe - call them early.  */
1621
void gpgrt_log_set_sink (const char *name, gpgrt_stream_t stream, int fd);
1622
void gpgrt_log_set_socket_dir_cb (const char *(*fnc)(void));
1623
void gpgrt_log_set_pid_suffix_cb (int (*cb)(unsigned long *r_value));
1624
void gpgrt_log_set_prefix (const char *text, unsigned int flags);
1625
1626
int  gpgrt_get_errorcount (int clear);
1627
void gpgrt_inc_errorcount (void);
1628
const char *gpgrt_log_get_prefix (unsigned int *flags);
1629
int  gpgrt_log_test_fd (int fd);
1630
int  gpgrt_log_get_fd (void);
1631
gpgrt_stream_t gpgrt_log_get_stream (void);
1632
1633
void gpgrt_log (int level, const char *fmt, ...) GPGRT_ATTR_PRINTF(2,3);
1634
void gpgrt_logv (int level, const char *fmt, va_list arg_ptr);
1635
void gpgrt_logv_prefix (int level, const char *prefix,
1636
                              const char *fmt, va_list arg_ptr);
1637
void gpgrt_log_string (int level, const char *string);
1638
void gpgrt_log_bug (const char *fmt, ...)    GPGRT_ATTR_NR_PRINTF(1,2);
1639
void gpgrt_log_fatal (const char *fmt, ...)  GPGRT_ATTR_NR_PRINTF(1,2);
1640
void gpgrt_log_error (const char *fmt, ...)  GPGRT_ATTR_PRINTF(1,2);
1641
void gpgrt_log_info (const char *fmt, ...)   GPGRT_ATTR_PRINTF(1,2);
1642
void gpgrt_log_debug (const char *fmt, ...)  GPGRT_ATTR_PRINTF(1,2);
1643
void gpgrt_log_debug_string (const char *string,
1644
                             const char *fmt, ...) GPGRT_ATTR_PRINTF(2,3);
1645
void gpgrt_log_printf (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
1646
void gpgrt_log_printhex (const void *buffer, size_t length,
1647
                         const char *fmt, ...) GPGRT_ATTR_PRINTF(3,4);
1648
void gpgrt_log_clock (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
1649
void gpgrt_log_flush (void);
1650
void _gpgrt_log_assert (const char *expr, const char *file, int line,
1651
                        const char *func) GPGRT_ATTR_NORETURN;
1652
1653
#ifdef GPGRT_HAVE_MACRO_FUNCTION
1654
# define gpgrt_assert(expr)                                     \
1655
  ((expr)                                                       \
1656
   ? (void) 0                                                   \
1657
   : _gpgrt_log_assert (#expr, __FILE__, __LINE__, __FUNCTION__))
1658
#else /*!GPGRT_HAVE_MACRO_FUNCTION*/
1659
# define gpgrt_assert(expr)                                     \
1660
  ((expr)                                                       \
1661
   ? (void) 0                                                   \
1662
   : _gpgrt_log_assert (#expr, __FILE__, __LINE__, NULL))
1663
#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
1664
1665
#ifdef GPGRT_ENABLE_LOG_MACROS
1666
# define log_get_errorcount      gpgrt_get_errorcount
1667
# define log_inc_errorcount      gpgrt_inc_errorcount
1668
# define log_set_file(a)         gpgrt_log_set_sink ((a), NULL, -1)
1669
# define log_set_fd(a)           gpgrt_log_set_sink (NULL, NULL, (a))
1670
# define log_set_stream(a)       gpgrt_log_set_sink (NULL, (a), -1)
1671
# define log_set_socket_dir_cb   gpgrt_log_set_socket_dir_cb
1672
# define log_set_pid_suffix_cb   gpgrt_log_set_pid_suffix_cb
1673
# define log_set_prefix          gpgrt_log_set_prefix
1674
# define log_get_prefix          gpgrt_log_get_prefix
1675
# define log_test_fd             gpgrt_log_test_fd
1676
# define log_get_fd              gpgrt_log_get_fd
1677
# define log_get_stream          gpgrt_log_get_stream
1678
# define log_log                 gpgrt_log
1679
# define log_logv                gpgrt_logv
1680
# define log_logv_prefix         gpgrt_logv_prefix
1681
# define log_string              gpgrt_log_string
1682
# define log_bug                 gpgrt_log_bug
1683
# define log_fatal               gpgrt_log_fatal
1684
# define log_error               gpgrt_log_error
1685
# define log_info                gpgrt_log_info
1686
# define log_debug               gpgrt_log_debug
1687
# define log_debug_string        gpgrt_log_debug_string
1688
# define log_printf              gpgrt_log_printf
1689
# define log_printhex            gpgrt_log_printhex
1690
# define log_clock               gpgrt_log_clock
1691
# define log_flush               gpgrt_log_flush
1692
# ifdef GPGRT_HAVE_MACRO_FUNCTION
1693
#  define log_assert(expr)                                      \
1694
  ((expr)                                                       \
1695
   ? (void) 0                                                   \
1696
   : _gpgrt_log_assert (#expr, __FILE__, __LINE__, __FUNCTION__))
1697
# else /*!GPGRT_HAVE_MACRO_FUNCTION*/
1698
#  define log_assert(expr)                                      \
1699
  ((expr)                                                       \
1700
   ? (void) 0                                                   \
1701
   : _gpgrt_log_assert (#expr, __FILE__, __LINE__, NULL))
1702
# endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
1703
1704
#endif /*GPGRT_ENABLE_LOG_MACROS*/
1705
1706

1707
/*
1708
 * Spawn functions  (Not yet available)
1709
 */
1710
/* Internal flag to ihnerit file descriptor/handle */
1711
#define GPGRT_SPAWN_INHERIT_FILE  1
1712
1713
#define GPGRT_SPAWN_NONBLOCK   16 /* Set the streams to non-blocking.      */
1714
#define GPGRT_SPAWN_RUN_ASFW   64 /* Use AllowSetForegroundWindow on W32.  */
1715
#define GPGRT_SPAWN_DETACHED  128 /* Start the process in the background.  */
1716
#define GPGRT_SPAWN_KEEP_STDIN   256
1717
#define GPGRT_SPAWN_KEEP_STDOUT  512
1718
#define GPGRT_SPAWN_KEEP_STDERR 1024
1719
1720
#if 0
1721
/* Function and convenience macros to create pipes.  */
1722
gpg_err_code_t gpgrt_make_pipe (int filedes[2], gpgrt_stream_t *r_fp,
1723
                                int direction, int nonblock);
1724
#define gpgrt_create_pipe(a)              gpgrt_make_pipe ((a),NULL,  0,  0);
1725
#define gpgrt_create_inbound_pipe(a,b,c)  gpgrt_make_pipe ((a), (b), -1,(c));
1726
#define gpgrt_create_outbound_pipe(a,b,c) gpgrt_make_pipe ((a), (b),  1,(c));
1727
1728
1729
/* Fork and exec PGMNAME.  */
1730
gpg_err_code_t gpgrt_spawn_process (const char *pgmname, const char *argv[],
1731
                                    int *execpt, unsigned int flags,
1732
                                    gpgrt_stream_t *r_infp,
1733
                                    gpgrt_stream_t *r_outfp,
1734
                                    gpgrt_stream_t *r_errfp,
1735
                                    gpgrt_process_t *r_process_id);
1736
1737
/* Fork and exec PGNNAME and connect the process to the given FDs.  */
1738
gpg_err_code_t gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
1739
                                       int infd, int outfd, int errfd,
1740
                                       int (*spawn_cb) (void *),
1741
                                       void *spawn_cb_arg,
1742
                                       gpgrt_process_t *r_process_id);
1743
1744
/* Fork and exec PGMNAME as a detached process.  */
1745
gpg_err_code_t gpgrt_spawn_process_detached (const char *pgmname,
1746
                                             const char *argv[],
1747
                                             const char *envp[]);
1748
1749
/* Wait for a single process.  */
1750
gpg_err_code_t gpgrt_wait_process (const char *pgmname,
1751
                                   gpgrt_process_t process_id,
1752
                                   int hang, int *r_exitcode);
1753
1754
/* Wait for a multiple processes.  */
1755
gpg_err_code_t gpgrt_wait_processes (const char **pgmnames,
1756
                                     gpgrt_process_t *process_ids,
1757
                                     size_t count, int hang, int *r_exitcodes);
1758
1759
/* Kill the process identified by PROCESS_ID.  */
1760
void gpgrt_kill_process (gpgrt_process_t process_id);
1761
1762
/* Release process resources identified by PROCESS_ID.  */
1763
void gpgrt_release_process (gpgrt_process_t process_id);
1764
1765
/* Close all file resources (descriptors), except KEEP_FDS. */
1766
void gpgrt_close_all_fds (int from, int *keep_fds);
1767
#endif /*0*/
1768

1769
/*
1770
 * Option parsing.
1771
 */
1772
1773
struct _gpgrt_argparse_internal_s;
1774
typedef struct
1775
{
1776
  int  *argc;       /* Pointer to ARGC (value subject to change). */
1777
  char ***argv;       /* Pointer to ARGV (value subject to change). */
1778
  unsigned int flags; /* Global flags.  May be set prior to calling the
1779
                         parser.  The parser may change the value.  */
1780
  int err;            /* Print error description for last option.
1781
                         Either 0,  ARGPARSE_PRINT_WARNING or
1782
                         ARGPARSE_PRINT_ERROR.  */
1783
  unsigned int lineno;/* The current line number.  */
1784
  int r_opt;        /* Returns option code. */
1785
  int r_type;       /* Returns type of option value.  */
1786
  union {
1787
    int   ret_int;
1788
    long  ret_long;
1789
    unsigned long ret_ulong;
1790
    char *ret_str;
1791
  } r;          /* Return values */
1792
1793
  struct _gpgrt_argparse_internal_s *internal;
1794
} gpgrt_argparse_t;
1795
1796
1797
typedef struct
1798
{
1799
  int          short_opt;
1800
  const char  *long_opt;
1801
  unsigned int flags;
1802
  const char  *description; /* Optional description. */
1803
} gpgrt_opt_t;
1804
1805
1806
#ifdef GPGRT_ENABLE_ARGPARSE_MACROS
1807
1808
/* Global flags for (gpgrt_argparse_t).flags.  */
1809
0
#define ARGPARSE_FLAG_KEEP        1  /* Do not remove options form argv.     */
1810
0
#define ARGPARSE_FLAG_ALL         2  /* Do not stop at last option but return
1811
                                        remaining args with R_OPT set to -1. */
1812
0
#define ARGPARSE_FLAG_MIXED       4  /* Assume options and args are mixed.   */
1813
0
#define ARGPARSE_FLAG_NOSTOP      8  /* Do not stop processing at "--".      */
1814
0
#define ARGPARSE_FLAG_ARG0       16  /* Do not skip the first arg.           */
1815
0
#define ARGPARSE_FLAG_ONEDASH    32  /* Allow long options with one dash.    */
1816
0
#define ARGPARSE_FLAG_NOVERSION  64  /* No output for "--version".           */
1817
0
#define ARGPARSE_FLAG_RESET     128  /* Request to reset the internal state. */
1818
0
#define ARGPARSE_FLAG_STOP_SEEN 256  /* Set to true if a "--" has been seen. */
1819
0
#define ARGPARSE_FLAG_NOLINENO  512  /* Do not zero the lineno field.        */
1820
0
#define ARGPARSE_FLAG_SYS      1024  /* Use system config file.              */
1821
0
#define ARGPARSE_FLAG_USER     2048  /* Use user config file.                */
1822
0
#define ARGPARSE_FLAG_VERBOSE  4096  /* Print additional argparser info.     */
1823
0
#define ARGPARSE_FLAG_USERVERS 8192  /* Try version-ed user config files.    */
1824
0
#define ARGPARSE_FLAG_WITHATTR 16384 /* Return attribute bits.  (Make sure   */
1825
                                     /* to act upon ARGPARSE_OPT_IGNORE.)    */
1826
1827
/* Constants for (gpgrt_argparse_t).err.  */
1828
0
#define ARGPARSE_PRINT_WARNING  1    /* Print a diagnostic.                  */
1829
#define ARGPARSE_PRINT_ERROR    2    /* Print a diagnostic and call exit.    */
1830
1831
/* Special return values of gpgrt_argparse.  */
1832
0
#define ARGPARSE_IS_ARG            (-1)
1833
0
#define ARGPARSE_INVALID_OPTION    (-2)
1834
0
#define ARGPARSE_MISSING_ARG       (-3)
1835
0
#define ARGPARSE_KEYWORD_TOO_LONG  (-4)
1836
0
#define ARGPARSE_READ_ERROR        (-5)
1837
0
#define ARGPARSE_UNEXPECTED_ARG    (-6)
1838
0
#define ARGPARSE_INVALID_COMMAND   (-7)
1839
0
#define ARGPARSE_AMBIGUOUS_OPTION  (-8)
1840
0
#define ARGPARSE_AMBIGUOUS_COMMAND (-9)
1841
0
#define ARGPARSE_INVALID_ALIAS     (-10)
1842
0
#define ARGPARSE_OUT_OF_CORE       (-11)
1843
0
#define ARGPARSE_INVALID_ARG       (-12)
1844
0
#define ARGPARSE_PERMISSION_ERROR  (-13)
1845
0
#define ARGPARSE_NO_CONFFILE       (-14)
1846
0
#define ARGPARSE_CONFFILE          (-15)
1847
0
#define ARGPARSE_INVALID_META      (-16)
1848
0
#define ARGPARSE_UNKNOWN_META      (-17)
1849
0
#define ARGPARSE_UNEXPECTED_META   (-18)
1850
1851
/* Flags for the option descriptor (gpgrt_opt_t)->flags.  Note that a
1852
 * TYPE constant may be or-ed with the OPT constants but when used as
1853
 * return value in r_type these OPT constants are normally not
1854
 * included.  However with ARGPARSE_FLAG_WITHATTR used and an option
1855
 * would normally not be returned, it is returned but
1856
 * ARGPARSE_OPT_IGNORE is then set; further ARPARSE_ATTR_* are set.
1857
 */
1858
0
#define ARGPARSE_TYPE_MASK   0x0007  /* Mask for the type bits.           */
1859
0
#define ARGPARSE_TYPE_NONE        0  /* Does not take an argument.        */
1860
0
#define ARGPARSE_TYPE_INT         1  /* Takes an int argument.            */
1861
0
#define ARGPARSE_TYPE_STRING      2  /* Takes a string argument.          */
1862
0
#define ARGPARSE_TYPE_LONG        3  /* Takes a long argument.            */
1863
0
#define ARGPARSE_TYPE_ULONG       4  /* Takes an unsigned long argument.  */
1864
0
#define ARGPARSE_OPT_OPTIONAL (1<<3) /* Argument is optional.             */
1865
0
#define ARGPARSE_OPT_PREFIX   (1<<4) /* Allow 0x etc. prefixed values.    */
1866
0
#define ARGPARSE_OPT_IGNORE   (1<<6) /* Ignore command or option.         */
1867
0
#define ARGPARSE_OPT_COMMAND  (1<<7) /* The argument is a command.        */
1868
0
#define ARGPARSE_OPT_CONFFILE (1<<8) /* The value is a conffile.          */
1869
0
#define ARGPARSE_OPT_HEADER   (1<<9) /* The value is printed as a header. */
1870
0
#define ARGPARSE_OPT_VERBATIM (1<<10)/* The value is printed verbatim.    */
1871
0
#define ARGPARSE_ATTR_FORCE   (1<<14)/* Attribute force is set.           */
1872
0
#define ARGPARSE_ATTR_IGNORE  (1<<15)/* Attribute ignore is set.          */
1873
1874
/* A set of macros to make option definitions easier to read.  */
1875
#define ARGPARSE_x(s,l,t,f,d) \
1876
     { (s), (l), ARGPARSE_TYPE_ ## t | (f), (d) }
1877
1878
#define ARGPARSE_s(s,l,t,d) \
1879
     { (s), (l), ARGPARSE_TYPE_ ## t, (d) }
1880
#define ARGPARSE_s_n(s,l,d) \
1881
     { (s), (l), ARGPARSE_TYPE_NONE, (d) }
1882
#define ARGPARSE_s_i(s,l,d) \
1883
     { (s), (l), ARGPARSE_TYPE_INT, (d) }
1884
#define ARGPARSE_s_s(s,l,d) \
1885
     { (s), (l), ARGPARSE_TYPE_STRING, (d) }
1886
#define ARGPARSE_s_l(s,l,d) \
1887
     { (s), (l), ARGPARSE_TYPE_LONG, (d) }
1888
#define ARGPARSE_s_u(s,l,d) \
1889
     { (s), (l), ARGPARSE_TYPE_ULONG, (d) }
1890
1891
#define ARGPARSE_o(s,l,t,d) \
1892
     { (s), (l), (ARGPARSE_TYPE_ ## t  | ARGPARSE_OPT_OPTIONAL), (d) }
1893
#define ARGPARSE_o_n(s,l,d) \
1894
     { (s), (l), (ARGPARSE_TYPE_NONE   | ARGPARSE_OPT_OPTIONAL), (d) }
1895
#define ARGPARSE_o_i(s,l,d) \
1896
     { (s), (l), (ARGPARSE_TYPE_INT    | ARGPARSE_OPT_OPTIONAL), (d) }
1897
#define ARGPARSE_o_s(s,l,d) \
1898
     { (s), (l), (ARGPARSE_TYPE_STRING | ARGPARSE_OPT_OPTIONAL), (d) }
1899
#define ARGPARSE_o_l(s,l,d) \
1900
     { (s), (l), (ARGPARSE_TYPE_LONG   | ARGPARSE_OPT_OPTIONAL), (d) }
1901
#define ARGPARSE_o_u(s,l,d) \
1902
     { (s), (l), (ARGPARSE_TYPE_ULONG  | ARGPARSE_OPT_OPTIONAL), (d) }
1903
1904
#define ARGPARSE_p(s,l,t,d) \
1905
     { (s), (l), (ARGPARSE_TYPE_ ## t  | ARGPARSE_OPT_PREFIX), (d) }
1906
#define ARGPARSE_p_n(s,l,d) \
1907
     { (s), (l), (ARGPARSE_TYPE_NONE   | ARGPARSE_OPT_PREFIX), (d) }
1908
#define ARGPARSE_p_i(s,l,d) \
1909
     { (s), (l), (ARGPARSE_TYPE_INT    | ARGPARSE_OPT_PREFIX), (d) }
1910
#define ARGPARSE_p_s(s,l,d) \
1911
     { (s), (l), (ARGPARSE_TYPE_STRING | ARGPARSE_OPT_PREFIX), (d) }
1912
#define ARGPARSE_p_l(s,l,d) \
1913
     { (s), (l), (ARGPARSE_TYPE_LONG   | ARGPARSE_OPT_PREFIX), (d) }
1914
#define ARGPARSE_p_u(s,l,d) \
1915
     { (s), (l), (ARGPARSE_TYPE_ULONG  | ARGPARSE_OPT_PREFIX), (d) }
1916
1917
#define ARGPARSE_op(s,l,t,d) \
1918
     { (s), (l), (ARGPARSE_TYPE_ ## t \
1919
                  | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
1920
#define ARGPARSE_op_n(s,l,d) \
1921
     { (s), (l), (ARGPARSE_TYPE_NONE \
1922
                  | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
1923
#define ARGPARSE_op_i(s,l,d) \
1924
     { (s), (l), (ARGPARSE_TYPE_INT \
1925
                  | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
1926
#define ARGPARSE_op_s(s,l,d) \
1927
     { (s), (l), (ARGPARSE_TYPE_STRING \
1928
                  | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
1929
#define ARGPARSE_op_l(s,l,d) \
1930
     { (s), (l), (ARGPARSE_TYPE_LONG \
1931
                  | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
1932
#define ARGPARSE_op_u(s,l,d) \
1933
     { (s), (l), (ARGPARSE_TYPE_ULONG \
1934
                  | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
1935
1936
#define ARGPARSE_c(s,l,d) \
1937
     { (s), (l), (ARGPARSE_TYPE_NONE | ARGPARSE_OPT_COMMAND), (d) }
1938
1939
#define ARGPARSE_conffile(s,l,d) \
1940
  { (s), (l), (ARGPARSE_TYPE_STRING|ARGPARSE_OPT_CONFFILE), (d) }
1941
1942
#define ARGPARSE_noconffile(s,l,d) \
1943
  { (s), (l), (ARGPARSE_TYPE_NONE|ARGPARSE_OPT_CONFFILE), (d) }
1944
1945
/* This macro is for stub or obsolete options.  */
1946
#define ARGPARSE_ignore(s,l)                    \
1947
  { (s), (l), (ARGPARSE_OPT_IGNORE), "@" }
1948
1949
/* This is a legacy version of ARGPARSE_verbatim which really does
1950
 * verbatim printing.  */
1951
#define ARGPARSE_group(s,d) \
1952
  { (s), NULL, 0, (d) }
1953
1954
/* Verbatim print the string D in the help output.  It does not make
1955
 * use of the "@" hack as ARGPARSE_group does.  */
1956
#define ARGPARSE_verbatim(d) \
1957
  { 1, NULL, (ARGPARSE_OPT_VERBATIM), (d) }
1958
1959
/* Same as ARGPARSE_verbatim but also print a colon and a LF.  N can
1960
 * be used give a symbolic name to the header.  Nothing is printed if
1961
 * D is the empty string.  */
1962
#define ARGPARSE_header(n,d) \
1963
  { 1, (n), (ARGPARSE_OPT_HEADER), (d) }
1964
1965
/* Mark the end of the list (mandatory).  */
1966
#define ARGPARSE_end() \
1967
  { 0, NULL, 0, NULL }
1968
1969
#endif /* GPGRT_ENABLE_ARGPARSE_MACROS */
1970
1971
/* Values used for gpgrt_set_confdir.  */
1972
0
#define GPGRT_CONFDIR_USER 1   /* The user's configuration dir.    */
1973
0
#define GPGRT_CONFDIR_SYS  2   /* The systems's configuration dir. */
1974
1975
/* Take care: gpgrt_argparse keeps state in ARG and requires that
1976
 * either ARGPARSE_FLAG_RESET is used after OPTS has been changed or
1977
 * gpgrt_argparse (NULL, ARG, NULL) is called first.  */
1978
int gpgrt_argparse (gpgrt_stream_t fp,
1979
                    gpgrt_argparse_t *arg, gpgrt_opt_t *opts);
1980
int gpgrt_argparser (gpgrt_argparse_t *arg, gpgrt_opt_t *opts,
1981
                     const char *confname);
1982
void gpgrt_usage (int level);
1983
const char *gpgrt_strusage (int level);
1984
void gpgrt_set_strusage (const char *(*f)(int));
1985
void gpgrt_set_usage_outfnc (int (*f)(int, const char *));
1986
void gpgrt_set_fixed_string_mapper (const char *(*f)(const char*));
1987
void gpgrt_set_confdir (int what, const char *name);
1988
1989

1990
/*
1991
 * Various helper functions
1992
 */
1993
1994
/* Compare arbitrary version strings.  For the standard m.n.o version
1995
 * numbering scheme a LEVEL of 3 is suitable; see the manual.  */
1996
int gpgrt_cmp_version (const char *a, const char *b, int level);
1997
1998
/* Construct a filename from the NULL terminated list of parts.  Tilde
1999
 * expansion is done for the first argument.  The caller must release
2000
 * the result using gpgrt_free; on error ERRNO is set and NULL
2001
 * returned.  The second function returns an absolute filename.  */
2002
char *gpgrt_fnameconcat (const char *first, ...) GPGRT_ATTR_SENTINEL(0);
2003
char *gpgrt_absfnameconcat (const char *first, ...) GPGRT_ATTR_SENTINEL(0);
2004
2005
2006
#ifdef __cplusplus
2007
}
2008
#endif
2009
#endif  /* GPGRT_H */
2010
#endif  /* GPG_ERROR_H */
2011
/*
2012
Local Variables:
2013
buffer-read-only: t
2014
End:
2015
*/