Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:20:41

0001 /* gpg-error.h or gpgrt.h - Common code for GnuPG and others.    -*- c -*-
0002  * Copyright (C) 2001-2024 g10 Code GmbH
0003  *
0004  * This file is part of libgpg-error (aka libgpgrt).
0005  *
0006  * libgpg-error is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public License
0008  * as published by the Free Software Foundation; either version 2.1 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * libgpg-error is distributed in the hope that it will be useful, but
0012  * WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this program; if not, see <https://www.gnu.org/licenses/>.
0018  * SPDX-License-Identifier: LGPL-2.1-or-later
0019  *
0020  * Do not edit.  Generated from gpg-error.h.in for:
0021                  x86_64-unknown-linux-gnu (x86_64-pc-linux-gnu)
0022  */
0023 
0024 /* The GnuPG project consists of many components.  Error codes are
0025  * exchanged between all components.  The common error codes and their
0026  * user-presentable descriptions are kept into a shared library to
0027  * allow adding new error codes and components without recompiling any
0028  * of the other components.  In addition to error codes this library
0029  * also features several other groups of functions which are common to
0030  * all GnuPG components.  They may be used by independet project as
0031  * well.  The interfaces will not change in a backward incompatible way.
0032  *
0033  * An error code together with an error source build up an error
0034  * value.  As the error value is been passed from one component to
0035  * another, it preserves the information about the source and nature
0036  * of the error.
0037  *
0038  * A component of the GnuPG project can define the following macros to
0039  * tune the behaviour of the library:
0040  *
0041  * GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
0042  * gpg_err_source_t to make that source the default for gpg_error().
0043  * Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default.
0044  *
0045  * GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the
0046  * internal gettext API to standard names.  This has only an effect on
0047  * Windows platforms.
0048  *
0049  * GPGRT_ENABLE_ES_MACROS: Define to provide "es_" macros for the
0050  * estream functions.
0051  *
0052  * GPGRT_ENABLE_LOG_MACROS: Define to provide short versions of the
0053  * log functions.
0054  *
0055  * GPGRT_ENABLE_ARGPARSE_MACROS: Needs to be defined to provide the
0056  * mandatory macros of the argparse interface.
0057  */
0058 
0059 #ifndef GPG_ERROR_H
0060 #define GPG_ERROR_H 1
0061 #ifndef GPGRT_H
0062 #define GPGRT_H 1
0063 
0064 #include <stddef.h>
0065 #include <stdio.h>
0066 #include <stdarg.h>
0067 
0068 /* The version string of this header. */
0069 #define GPG_ERROR_VERSION "1.55"
0070 #define GPGRT_VERSION     "1.55"
0071 
0072 /* The version number of this header. */
0073 #define GPG_ERROR_VERSION_NUMBER 0x013700
0074 #define GPGRT_VERSION_NUMBER     0x013700
0075 
0076 
0077 #ifdef __GNUC__
0078 # define GPG_ERR_INLINE __inline__
0079 #elif defined(_MSC_VER) && _MSC_VER >= 1300
0080 # define GPG_ERR_INLINE __inline
0081 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
0082 # define GPG_ERR_INLINE inline
0083 #else
0084 # ifndef GPG_ERR_INLINE
0085 #  define GPG_ERR_INLINE
0086 # endif
0087 #endif
0088 
0089 #ifdef __cplusplus
0090 extern "C" {
0091 #if 0 /* just to make Emacs auto-indent happy */
0092 }
0093 #endif
0094 #endif /* __cplusplus */
0095 
0096 
0097 
0098 /* The error source type gpg_err_source_t.
0099  *
0100  * Where as the Poo out of a welle small
0101  * Taketh his firste springing and his sours.
0102  *                  --Chaucer.
0103  */
0104 
0105 /* Only use free slots, never change or reorder the existing
0106  * entries.  */
0107 typedef enum
0108   {
0109     GPG_ERR_SOURCE_UNKNOWN = 0,
0110     GPG_ERR_SOURCE_GCRYPT = 1,
0111     GPG_ERR_SOURCE_GPG = 2,
0112     GPG_ERR_SOURCE_GPGSM = 3,
0113     GPG_ERR_SOURCE_GPGAGENT = 4,
0114     GPG_ERR_SOURCE_PINENTRY = 5,
0115     GPG_ERR_SOURCE_SCD = 6,
0116     GPG_ERR_SOURCE_GPGME = 7,
0117     GPG_ERR_SOURCE_KEYBOX = 8,
0118     GPG_ERR_SOURCE_KSBA = 9,
0119     GPG_ERR_SOURCE_DIRMNGR = 10,
0120     GPG_ERR_SOURCE_GSTI = 11,
0121     GPG_ERR_SOURCE_GPA = 12,
0122     GPG_ERR_SOURCE_KLEO = 13,
0123     GPG_ERR_SOURCE_G13 = 14,
0124     GPG_ERR_SOURCE_ASSUAN = 15,
0125     GPG_ERR_SOURCE_TPM2D = 16,
0126     GPG_ERR_SOURCE_TLS = 17,
0127     GPG_ERR_SOURCE_TKD = 18,
0128     GPG_ERR_SOURCE_ANY = 31,
0129     GPG_ERR_SOURCE_USER_1 = 32,
0130     GPG_ERR_SOURCE_USER_2 = 33,
0131     GPG_ERR_SOURCE_USER_3 = 34,
0132     GPG_ERR_SOURCE_USER_4 = 35,
0133 
0134     /* This is one more than the largest allowed entry.  */
0135     GPG_ERR_SOURCE_DIM = 128
0136   } gpg_err_source_t;
0137 
0138 
0139 /* The error code type gpg_err_code_t.  */
0140 
0141 /* Only use free slots, never change or reorder the existing
0142  * entries.  */
0143 typedef enum
0144   {
0145     GPG_ERR_NO_ERROR = 0,
0146     GPG_ERR_GENERAL = 1,
0147     GPG_ERR_UNKNOWN_PACKET = 2,
0148     GPG_ERR_UNKNOWN_VERSION = 3,
0149     GPG_ERR_PUBKEY_ALGO = 4,
0150     GPG_ERR_DIGEST_ALGO = 5,
0151     GPG_ERR_BAD_PUBKEY = 6,
0152     GPG_ERR_BAD_SECKEY = 7,
0153     GPG_ERR_BAD_SIGNATURE = 8,
0154     GPG_ERR_NO_PUBKEY = 9,
0155     GPG_ERR_CHECKSUM = 10,
0156     GPG_ERR_BAD_PASSPHRASE = 11,
0157     GPG_ERR_CIPHER_ALGO = 12,
0158     GPG_ERR_KEYRING_OPEN = 13,
0159     GPG_ERR_INV_PACKET = 14,
0160     GPG_ERR_INV_ARMOR = 15,
0161     GPG_ERR_NO_USER_ID = 16,
0162     GPG_ERR_NO_SECKEY = 17,
0163     GPG_ERR_WRONG_SECKEY = 18,
0164     GPG_ERR_BAD_KEY = 19,
0165     GPG_ERR_COMPR_ALGO = 20,
0166     GPG_ERR_NO_PRIME = 21,
0167     GPG_ERR_NO_ENCODING_METHOD = 22,
0168     GPG_ERR_NO_ENCRYPTION_SCHEME = 23,
0169     GPG_ERR_NO_SIGNATURE_SCHEME = 24,
0170     GPG_ERR_INV_ATTR = 25,
0171     GPG_ERR_NO_VALUE = 26,
0172     GPG_ERR_NOT_FOUND = 27,
0173     GPG_ERR_VALUE_NOT_FOUND = 28,
0174     GPG_ERR_SYNTAX = 29,
0175     GPG_ERR_BAD_MPI = 30,
0176     GPG_ERR_INV_PASSPHRASE = 31,
0177     GPG_ERR_SIG_CLASS = 32,
0178     GPG_ERR_RESOURCE_LIMIT = 33,
0179     GPG_ERR_INV_KEYRING = 34,
0180     GPG_ERR_TRUSTDB = 35,
0181     GPG_ERR_BAD_CERT = 36,
0182     GPG_ERR_INV_USER_ID = 37,
0183     GPG_ERR_UNEXPECTED = 38,
0184     GPG_ERR_TIME_CONFLICT = 39,
0185     GPG_ERR_KEYSERVER = 40,
0186     GPG_ERR_WRONG_PUBKEY_ALGO = 41,
0187     GPG_ERR_TRIBUTE_TO_D_A = 42,
0188     GPG_ERR_WEAK_KEY = 43,
0189     GPG_ERR_INV_KEYLEN = 44,
0190     GPG_ERR_INV_ARG = 45,
0191     GPG_ERR_BAD_URI = 46,
0192     GPG_ERR_INV_URI = 47,
0193     GPG_ERR_NETWORK = 48,
0194     GPG_ERR_UNKNOWN_HOST = 49,
0195     GPG_ERR_SELFTEST_FAILED = 50,
0196     GPG_ERR_NOT_ENCRYPTED = 51,
0197     GPG_ERR_NOT_PROCESSED = 52,
0198     GPG_ERR_UNUSABLE_PUBKEY = 53,
0199     GPG_ERR_UNUSABLE_SECKEY = 54,
0200     GPG_ERR_INV_VALUE = 55,
0201     GPG_ERR_BAD_CERT_CHAIN = 56,
0202     GPG_ERR_MISSING_CERT = 57,
0203     GPG_ERR_NO_DATA = 58,
0204     GPG_ERR_BUG = 59,
0205     GPG_ERR_NOT_SUPPORTED = 60,
0206     GPG_ERR_INV_OP = 61,
0207     GPG_ERR_TIMEOUT = 62,
0208     GPG_ERR_INTERNAL = 63,
0209     GPG_ERR_EOF_GCRYPT = 64,
0210     GPG_ERR_INV_OBJ = 65,
0211     GPG_ERR_TOO_SHORT = 66,
0212     GPG_ERR_TOO_LARGE = 67,
0213     GPG_ERR_NO_OBJ = 68,
0214     GPG_ERR_NOT_IMPLEMENTED = 69,
0215     GPG_ERR_CONFLICT = 70,
0216     GPG_ERR_INV_CIPHER_MODE = 71,
0217     GPG_ERR_INV_FLAG = 72,
0218     GPG_ERR_INV_HANDLE = 73,
0219     GPG_ERR_TRUNCATED = 74,
0220     GPG_ERR_INCOMPLETE_LINE = 75,
0221     GPG_ERR_INV_RESPONSE = 76,
0222     GPG_ERR_NO_AGENT = 77,
0223     GPG_ERR_AGENT = 78,
0224     GPG_ERR_INV_DATA = 79,
0225     GPG_ERR_ASSUAN_SERVER_FAULT = 80,
0226     GPG_ERR_ASSUAN = 81,
0227     GPG_ERR_INV_SESSION_KEY = 82,
0228     GPG_ERR_INV_SEXP = 83,
0229     GPG_ERR_UNSUPPORTED_ALGORITHM = 84,
0230     GPG_ERR_NO_PIN_ENTRY = 85,
0231     GPG_ERR_PIN_ENTRY = 86,
0232     GPG_ERR_BAD_PIN = 87,
0233     GPG_ERR_INV_NAME = 88,
0234     GPG_ERR_BAD_DATA = 89,
0235     GPG_ERR_INV_PARAMETER = 90,
0236     GPG_ERR_WRONG_CARD = 91,
0237     GPG_ERR_NO_DIRMNGR = 92,
0238     GPG_ERR_DIRMNGR = 93,
0239     GPG_ERR_CERT_REVOKED = 94,
0240     GPG_ERR_NO_CRL_KNOWN = 95,
0241     GPG_ERR_CRL_TOO_OLD = 96,
0242     GPG_ERR_LINE_TOO_LONG = 97,
0243     GPG_ERR_NOT_TRUSTED = 98,
0244     GPG_ERR_CANCELED = 99,
0245     GPG_ERR_BAD_CA_CERT = 100,
0246     GPG_ERR_CERT_EXPIRED = 101,
0247     GPG_ERR_CERT_TOO_YOUNG = 102,
0248     GPG_ERR_UNSUPPORTED_CERT = 103,
0249     GPG_ERR_UNKNOWN_SEXP = 104,
0250     GPG_ERR_UNSUPPORTED_PROTECTION = 105,
0251     GPG_ERR_CORRUPTED_PROTECTION = 106,
0252     GPG_ERR_AMBIGUOUS_NAME = 107,
0253     GPG_ERR_CARD = 108,
0254     GPG_ERR_CARD_RESET = 109,
0255     GPG_ERR_CARD_REMOVED = 110,
0256     GPG_ERR_INV_CARD = 111,
0257     GPG_ERR_CARD_NOT_PRESENT = 112,
0258     GPG_ERR_NO_PKCS15_APP = 113,
0259     GPG_ERR_NOT_CONFIRMED = 114,
0260     GPG_ERR_CONFIGURATION = 115,
0261     GPG_ERR_NO_POLICY_MATCH = 116,
0262     GPG_ERR_INV_INDEX = 117,
0263     GPG_ERR_INV_ID = 118,
0264     GPG_ERR_NO_SCDAEMON = 119,
0265     GPG_ERR_SCDAEMON = 120,
0266     GPG_ERR_UNSUPPORTED_PROTOCOL = 121,
0267     GPG_ERR_BAD_PIN_METHOD = 122,
0268     GPG_ERR_CARD_NOT_INITIALIZED = 123,
0269     GPG_ERR_UNSUPPORTED_OPERATION = 124,
0270     GPG_ERR_WRONG_KEY_USAGE = 125,
0271     GPG_ERR_NOTHING_FOUND = 126,
0272     GPG_ERR_WRONG_BLOB_TYPE = 127,
0273     GPG_ERR_MISSING_VALUE = 128,
0274     GPG_ERR_HARDWARE = 129,
0275     GPG_ERR_PIN_BLOCKED = 130,
0276     GPG_ERR_USE_CONDITIONS = 131,
0277     GPG_ERR_PIN_NOT_SYNCED = 132,
0278     GPG_ERR_INV_CRL = 133,
0279     GPG_ERR_BAD_BER = 134,
0280     GPG_ERR_INV_BER = 135,
0281     GPG_ERR_ELEMENT_NOT_FOUND = 136,
0282     GPG_ERR_IDENTIFIER_NOT_FOUND = 137,
0283     GPG_ERR_INV_TAG = 138,
0284     GPG_ERR_INV_LENGTH = 139,
0285     GPG_ERR_INV_KEYINFO = 140,
0286     GPG_ERR_UNEXPECTED_TAG = 141,
0287     GPG_ERR_NOT_DER_ENCODED = 142,
0288     GPG_ERR_NO_CMS_OBJ = 143,
0289     GPG_ERR_INV_CMS_OBJ = 144,
0290     GPG_ERR_UNKNOWN_CMS_OBJ = 145,
0291     GPG_ERR_UNSUPPORTED_CMS_OBJ = 146,
0292     GPG_ERR_UNSUPPORTED_ENCODING = 147,
0293     GPG_ERR_UNSUPPORTED_CMS_VERSION = 148,
0294     GPG_ERR_UNKNOWN_ALGORITHM = 149,
0295     GPG_ERR_INV_ENGINE = 150,
0296     GPG_ERR_PUBKEY_NOT_TRUSTED = 151,
0297     GPG_ERR_DECRYPT_FAILED = 152,
0298     GPG_ERR_KEY_EXPIRED = 153,
0299     GPG_ERR_SIG_EXPIRED = 154,
0300     GPG_ERR_ENCODING_PROBLEM = 155,
0301     GPG_ERR_INV_STATE = 156,
0302     GPG_ERR_DUP_VALUE = 157,
0303     GPG_ERR_MISSING_ACTION = 158,
0304     GPG_ERR_MODULE_NOT_FOUND = 159,
0305     GPG_ERR_INV_OID_STRING = 160,
0306     GPG_ERR_INV_TIME = 161,
0307     GPG_ERR_INV_CRL_OBJ = 162,
0308     GPG_ERR_UNSUPPORTED_CRL_VERSION = 163,
0309     GPG_ERR_INV_CERT_OBJ = 164,
0310     GPG_ERR_UNKNOWN_NAME = 165,
0311     GPG_ERR_LOCALE_PROBLEM = 166,
0312     GPG_ERR_NOT_LOCKED = 167,
0313     GPG_ERR_PROTOCOL_VIOLATION = 168,
0314     GPG_ERR_INV_MAC = 169,
0315     GPG_ERR_INV_REQUEST = 170,
0316     GPG_ERR_UNKNOWN_EXTN = 171,
0317     GPG_ERR_UNKNOWN_CRIT_EXTN = 172,
0318     GPG_ERR_LOCKED = 173,
0319     GPG_ERR_UNKNOWN_OPTION = 174,
0320     GPG_ERR_UNKNOWN_COMMAND = 175,
0321     GPG_ERR_NOT_OPERATIONAL = 176,
0322     GPG_ERR_NO_PASSPHRASE = 177,
0323     GPG_ERR_NO_PIN = 178,
0324     GPG_ERR_NOT_ENABLED = 179,
0325     GPG_ERR_NO_ENGINE = 180,
0326     GPG_ERR_MISSING_KEY = 181,
0327     GPG_ERR_TOO_MANY = 182,
0328     GPG_ERR_LIMIT_REACHED = 183,
0329     GPG_ERR_NOT_INITIALIZED = 184,
0330     GPG_ERR_MISSING_ISSUER_CERT = 185,
0331     GPG_ERR_NO_KEYSERVER = 186,
0332     GPG_ERR_INV_CURVE = 187,
0333     GPG_ERR_UNKNOWN_CURVE = 188,
0334     GPG_ERR_DUP_KEY = 189,
0335     GPG_ERR_AMBIGUOUS = 190,
0336     GPG_ERR_NO_CRYPT_CTX = 191,
0337     GPG_ERR_WRONG_CRYPT_CTX = 192,
0338     GPG_ERR_BAD_CRYPT_CTX = 193,
0339     GPG_ERR_CRYPT_CTX_CONFLICT = 194,
0340     GPG_ERR_BROKEN_PUBKEY = 195,
0341     GPG_ERR_BROKEN_SECKEY = 196,
0342     GPG_ERR_MAC_ALGO = 197,
0343     GPG_ERR_FULLY_CANCELED = 198,
0344     GPG_ERR_UNFINISHED = 199,
0345     GPG_ERR_BUFFER_TOO_SHORT = 200,
0346     GPG_ERR_SEXP_INV_LEN_SPEC = 201,
0347     GPG_ERR_SEXP_STRING_TOO_LONG = 202,
0348     GPG_ERR_SEXP_UNMATCHED_PAREN = 203,
0349     GPG_ERR_SEXP_NOT_CANONICAL = 204,
0350     GPG_ERR_SEXP_BAD_CHARACTER = 205,
0351     GPG_ERR_SEXP_BAD_QUOTATION = 206,
0352     GPG_ERR_SEXP_ZERO_PREFIX = 207,
0353     GPG_ERR_SEXP_NESTED_DH = 208,
0354     GPG_ERR_SEXP_UNMATCHED_DH = 209,
0355     GPG_ERR_SEXP_UNEXPECTED_PUNC = 210,
0356     GPG_ERR_SEXP_BAD_HEX_CHAR = 211,
0357     GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212,
0358     GPG_ERR_SEXP_BAD_OCT_CHAR = 213,
0359     GPG_ERR_SUBKEYS_EXP_OR_REV = 217,
0360     GPG_ERR_DB_CORRUPTED = 218,
0361     GPG_ERR_SERVER_FAILED = 219,
0362     GPG_ERR_NO_NAME = 220,
0363     GPG_ERR_NO_KEY = 221,
0364     GPG_ERR_LEGACY_KEY = 222,
0365     GPG_ERR_REQUEST_TOO_SHORT = 223,
0366     GPG_ERR_REQUEST_TOO_LONG = 224,
0367     GPG_ERR_OBJ_TERM_STATE = 225,
0368     GPG_ERR_NO_CERT_CHAIN = 226,
0369     GPG_ERR_CERT_TOO_LARGE = 227,
0370     GPG_ERR_INV_RECORD = 228,
0371     GPG_ERR_BAD_MAC = 229,
0372     GPG_ERR_UNEXPECTED_MSG = 230,
0373     GPG_ERR_COMPR_FAILED = 231,
0374     GPG_ERR_WOULD_WRAP = 232,
0375     GPG_ERR_FATAL_ALERT = 233,
0376     GPG_ERR_NO_CIPHER = 234,
0377     GPG_ERR_MISSING_CLIENT_CERT = 235,
0378     GPG_ERR_CLOSE_NOTIFY = 236,
0379     GPG_ERR_TICKET_EXPIRED = 237,
0380     GPG_ERR_BAD_TICKET = 238,
0381     GPG_ERR_UNKNOWN_IDENTITY = 239,
0382     GPG_ERR_BAD_HS_CERT = 240,
0383     GPG_ERR_BAD_HS_CERT_REQ = 241,
0384     GPG_ERR_BAD_HS_CERT_VER = 242,
0385     GPG_ERR_BAD_HS_CHANGE_CIPHER = 243,
0386     GPG_ERR_BAD_HS_CLIENT_HELLO = 244,
0387     GPG_ERR_BAD_HS_SERVER_HELLO = 245,
0388     GPG_ERR_BAD_HS_SERVER_HELLO_DONE = 246,
0389     GPG_ERR_BAD_HS_FINISHED = 247,
0390     GPG_ERR_BAD_HS_SERVER_KEX = 248,
0391     GPG_ERR_BAD_HS_CLIENT_KEX = 249,
0392     GPG_ERR_BOGUS_STRING = 250,
0393     GPG_ERR_FORBIDDEN = 251,
0394     GPG_ERR_KEY_DISABLED = 252,
0395     GPG_ERR_KEY_ON_CARD = 253,
0396     GPG_ERR_INV_LOCK_OBJ = 254,
0397     GPG_ERR_TRUE = 255,
0398     GPG_ERR_FALSE = 256,
0399     GPG_ERR_ASS_GENERAL = 257,
0400     GPG_ERR_ASS_ACCEPT_FAILED = 258,
0401     GPG_ERR_ASS_CONNECT_FAILED = 259,
0402     GPG_ERR_ASS_INV_RESPONSE = 260,
0403     GPG_ERR_ASS_INV_VALUE = 261,
0404     GPG_ERR_ASS_INCOMPLETE_LINE = 262,
0405     GPG_ERR_ASS_LINE_TOO_LONG = 263,
0406     GPG_ERR_ASS_NESTED_COMMANDS = 264,
0407     GPG_ERR_ASS_NO_DATA_CB = 265,
0408     GPG_ERR_ASS_NO_INQUIRE_CB = 266,
0409     GPG_ERR_ASS_NOT_A_SERVER = 267,
0410     GPG_ERR_ASS_NOT_A_CLIENT = 268,
0411     GPG_ERR_ASS_SERVER_START = 269,
0412     GPG_ERR_ASS_READ_ERROR = 270,
0413     GPG_ERR_ASS_WRITE_ERROR = 271,
0414     GPG_ERR_ASS_TOO_MUCH_DATA = 273,
0415     GPG_ERR_ASS_UNEXPECTED_CMD = 274,
0416     GPG_ERR_ASS_UNKNOWN_CMD = 275,
0417     GPG_ERR_ASS_SYNTAX = 276,
0418     GPG_ERR_ASS_CANCELED = 277,
0419     GPG_ERR_ASS_NO_INPUT = 278,
0420     GPG_ERR_ASS_NO_OUTPUT = 279,
0421     GPG_ERR_ASS_PARAMETER = 280,
0422     GPG_ERR_ASS_UNKNOWN_INQUIRE = 281,
0423     GPG_ERR_ENGINE_TOO_OLD = 300,
0424     GPG_ERR_WINDOW_TOO_SMALL = 301,
0425     GPG_ERR_WINDOW_TOO_LARGE = 302,
0426     GPG_ERR_MISSING_ENVVAR = 303,
0427     GPG_ERR_USER_ID_EXISTS = 304,
0428     GPG_ERR_NAME_EXISTS = 305,
0429     GPG_ERR_DUP_NAME = 306,
0430     GPG_ERR_TOO_YOUNG = 307,
0431     GPG_ERR_TOO_OLD = 308,
0432     GPG_ERR_UNKNOWN_FLAG = 309,
0433     GPG_ERR_INV_ORDER = 310,
0434     GPG_ERR_ALREADY_FETCHED = 311,
0435     GPG_ERR_TRY_LATER = 312,
0436     GPG_ERR_WRONG_NAME = 313,
0437     GPG_ERR_NO_AUTH = 314,
0438     GPG_ERR_BAD_AUTH = 315,
0439     GPG_ERR_NO_KEYBOXD = 316,
0440     GPG_ERR_KEYBOXD = 317,
0441     GPG_ERR_NO_SERVICE = 318,
0442     GPG_ERR_SERVICE = 319,
0443     GPG_ERR_BAD_PUK = 320,
0444     GPG_ERR_NO_RESET_CODE = 321,
0445     GPG_ERR_BAD_RESET_CODE = 322,
0446     GPG_ERR_SYSTEM_BUG = 666,
0447     GPG_ERR_DNS_UNKNOWN = 711,
0448     GPG_ERR_DNS_SECTION = 712,
0449     GPG_ERR_DNS_ADDRESS = 713,
0450     GPG_ERR_DNS_NO_QUERY = 714,
0451     GPG_ERR_DNS_NO_ANSWER = 715,
0452     GPG_ERR_DNS_CLOSED = 716,
0453     GPG_ERR_DNS_VERIFY = 717,
0454     GPG_ERR_DNS_TIMEOUT = 718,
0455     GPG_ERR_LDAP_GENERAL = 721,
0456     GPG_ERR_LDAP_ATTR_GENERAL = 722,
0457     GPG_ERR_LDAP_NAME_GENERAL = 723,
0458     GPG_ERR_LDAP_SECURITY_GENERAL = 724,
0459     GPG_ERR_LDAP_SERVICE_GENERAL = 725,
0460     GPG_ERR_LDAP_UPDATE_GENERAL = 726,
0461     GPG_ERR_LDAP_E_GENERAL = 727,
0462     GPG_ERR_LDAP_X_GENERAL = 728,
0463     GPG_ERR_LDAP_OTHER_GENERAL = 729,
0464     GPG_ERR_LDAP_X_CONNECTING = 750,
0465     GPG_ERR_LDAP_REFERRAL_LIMIT = 751,
0466     GPG_ERR_LDAP_CLIENT_LOOP = 752,
0467     GPG_ERR_LDAP_NO_RESULTS = 754,
0468     GPG_ERR_LDAP_CONTROL_NOT_FOUND = 755,
0469     GPG_ERR_LDAP_NOT_SUPPORTED = 756,
0470     GPG_ERR_LDAP_CONNECT = 757,
0471     GPG_ERR_LDAP_NO_MEMORY = 758,
0472     GPG_ERR_LDAP_PARAM = 759,
0473     GPG_ERR_LDAP_USER_CANCELLED = 760,
0474     GPG_ERR_LDAP_FILTER = 761,
0475     GPG_ERR_LDAP_AUTH_UNKNOWN = 762,
0476     GPG_ERR_LDAP_TIMEOUT = 763,
0477     GPG_ERR_LDAP_DECODING = 764,
0478     GPG_ERR_LDAP_ENCODING = 765,
0479     GPG_ERR_LDAP_LOCAL = 766,
0480     GPG_ERR_LDAP_SERVER_DOWN = 767,
0481     GPG_ERR_LDAP_SUCCESS = 768,
0482     GPG_ERR_LDAP_OPERATIONS = 769,
0483     GPG_ERR_LDAP_PROTOCOL = 770,
0484     GPG_ERR_LDAP_TIMELIMIT = 771,
0485     GPG_ERR_LDAP_SIZELIMIT = 772,
0486     GPG_ERR_LDAP_COMPARE_FALSE = 773,
0487     GPG_ERR_LDAP_COMPARE_TRUE = 774,
0488     GPG_ERR_LDAP_UNSUPPORTED_AUTH = 775,
0489     GPG_ERR_LDAP_STRONG_AUTH_RQRD = 776,
0490     GPG_ERR_LDAP_PARTIAL_RESULTS = 777,
0491     GPG_ERR_LDAP_REFERRAL = 778,
0492     GPG_ERR_LDAP_ADMINLIMIT = 779,
0493     GPG_ERR_LDAP_UNAVAIL_CRIT_EXTN = 780,
0494     GPG_ERR_LDAP_CONFIDENT_RQRD = 781,
0495     GPG_ERR_LDAP_SASL_BIND_INPROG = 782,
0496     GPG_ERR_LDAP_NO_SUCH_ATTRIBUTE = 784,
0497     GPG_ERR_LDAP_UNDEFINED_TYPE = 785,
0498     GPG_ERR_LDAP_BAD_MATCHING = 786,
0499     GPG_ERR_LDAP_CONST_VIOLATION = 787,
0500     GPG_ERR_LDAP_TYPE_VALUE_EXISTS = 788,
0501     GPG_ERR_LDAP_INV_SYNTAX = 789,
0502     GPG_ERR_LDAP_NO_SUCH_OBJ = 800,
0503     GPG_ERR_LDAP_ALIAS_PROBLEM = 801,
0504     GPG_ERR_LDAP_INV_DN_SYNTAX = 802,
0505     GPG_ERR_LDAP_IS_LEAF = 803,
0506     GPG_ERR_LDAP_ALIAS_DEREF = 804,
0507     GPG_ERR_LDAP_X_PROXY_AUTH_FAIL = 815,
0508     GPG_ERR_LDAP_BAD_AUTH = 816,
0509     GPG_ERR_LDAP_INV_CREDENTIALS = 817,
0510     GPG_ERR_LDAP_INSUFFICIENT_ACC = 818,
0511     GPG_ERR_LDAP_BUSY = 819,
0512     GPG_ERR_LDAP_UNAVAILABLE = 820,
0513     GPG_ERR_LDAP_UNWILL_TO_PERFORM = 821,
0514     GPG_ERR_LDAP_LOOP_DETECT = 822,
0515     GPG_ERR_LDAP_NAMING_VIOLATION = 832,
0516     GPG_ERR_LDAP_OBJ_CLS_VIOLATION = 833,
0517     GPG_ERR_LDAP_NOT_ALLOW_NONLEAF = 834,
0518     GPG_ERR_LDAP_NOT_ALLOW_ON_RDN = 835,
0519     GPG_ERR_LDAP_ALREADY_EXISTS = 836,
0520     GPG_ERR_LDAP_NO_OBJ_CLASS_MODS = 837,
0521     GPG_ERR_LDAP_RESULTS_TOO_LARGE = 838,
0522     GPG_ERR_LDAP_AFFECTS_MULT_DSAS = 839,
0523     GPG_ERR_LDAP_VLV = 844,
0524     GPG_ERR_LDAP_OTHER = 848,
0525     GPG_ERR_LDAP_CUP_RESOURCE_LIMIT = 881,
0526     GPG_ERR_LDAP_CUP_SEC_VIOLATION = 882,
0527     GPG_ERR_LDAP_CUP_INV_DATA = 883,
0528     GPG_ERR_LDAP_CUP_UNSUP_SCHEME = 884,
0529     GPG_ERR_LDAP_CUP_RELOAD = 885,
0530     GPG_ERR_LDAP_CANCELLED = 886,
0531     GPG_ERR_LDAP_NO_SUCH_OPERATION = 887,
0532     GPG_ERR_LDAP_TOO_LATE = 888,
0533     GPG_ERR_LDAP_CANNOT_CANCEL = 889,
0534     GPG_ERR_LDAP_ASSERTION_FAILED = 890,
0535     GPG_ERR_LDAP_PROX_AUTH_DENIED = 891,
0536     GPG_ERR_USER_1 = 1024,
0537     GPG_ERR_USER_2 = 1025,
0538     GPG_ERR_USER_3 = 1026,
0539     GPG_ERR_USER_4 = 1027,
0540     GPG_ERR_USER_5 = 1028,
0541     GPG_ERR_USER_6 = 1029,
0542     GPG_ERR_USER_7 = 1030,
0543     GPG_ERR_USER_8 = 1031,
0544     GPG_ERR_USER_9 = 1032,
0545     GPG_ERR_USER_10 = 1033,
0546     GPG_ERR_USER_11 = 1034,
0547     GPG_ERR_USER_12 = 1035,
0548     GPG_ERR_USER_13 = 1036,
0549     GPG_ERR_USER_14 = 1037,
0550     GPG_ERR_USER_15 = 1038,
0551     GPG_ERR_USER_16 = 1039,
0552     GPG_ERR_SQL_OK = 1500,
0553     GPG_ERR_SQL_ERROR = 1501,
0554     GPG_ERR_SQL_INTERNAL = 1502,
0555     GPG_ERR_SQL_PERM = 1503,
0556     GPG_ERR_SQL_ABORT = 1504,
0557     GPG_ERR_SQL_BUSY = 1505,
0558     GPG_ERR_SQL_LOCKED = 1506,
0559     GPG_ERR_SQL_NOMEM = 1507,
0560     GPG_ERR_SQL_READONLY = 1508,
0561     GPG_ERR_SQL_INTERRUPT = 1509,
0562     GPG_ERR_SQL_IOERR = 1510,
0563     GPG_ERR_SQL_CORRUPT = 1511,
0564     GPG_ERR_SQL_NOTFOUND = 1512,
0565     GPG_ERR_SQL_FULL = 1513,
0566     GPG_ERR_SQL_CANTOPEN = 1514,
0567     GPG_ERR_SQL_PROTOCOL = 1515,
0568     GPG_ERR_SQL_EMPTY = 1516,
0569     GPG_ERR_SQL_SCHEMA = 1517,
0570     GPG_ERR_SQL_TOOBIG = 1518,
0571     GPG_ERR_SQL_CONSTRAINT = 1519,
0572     GPG_ERR_SQL_MISMATCH = 1520,
0573     GPG_ERR_SQL_MISUSE = 1521,
0574     GPG_ERR_SQL_NOLFS = 1522,
0575     GPG_ERR_SQL_AUTH = 1523,
0576     GPG_ERR_SQL_FORMAT = 1524,
0577     GPG_ERR_SQL_RANGE = 1525,
0578     GPG_ERR_SQL_NOTADB = 1526,
0579     GPG_ERR_SQL_NOTICE = 1527,
0580     GPG_ERR_SQL_WARNING = 1528,
0581     GPG_ERR_SQL_ROW = 1600,
0582     GPG_ERR_SQL_DONE = 1601,
0583     GPG_ERR_MISSING_ERRNO = 16381,
0584     GPG_ERR_UNKNOWN_ERRNO = 16382,
0585     GPG_ERR_EOF = 16383,
0586 
0587     /* The following error codes are used to map system errors.  */
0588 #define GPG_ERR_SYSTEM_ERROR    (1 << 15)
0589     GPG_ERR_E2BIG = GPG_ERR_SYSTEM_ERROR | 0,
0590     GPG_ERR_EACCES = GPG_ERR_SYSTEM_ERROR | 1,
0591     GPG_ERR_EADDRINUSE = GPG_ERR_SYSTEM_ERROR | 2,
0592     GPG_ERR_EADDRNOTAVAIL = GPG_ERR_SYSTEM_ERROR | 3,
0593     GPG_ERR_EADV = GPG_ERR_SYSTEM_ERROR | 4,
0594     GPG_ERR_EAFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 5,
0595     GPG_ERR_EAGAIN = GPG_ERR_SYSTEM_ERROR | 6,
0596     GPG_ERR_EALREADY = GPG_ERR_SYSTEM_ERROR | 7,
0597     GPG_ERR_EAUTH = GPG_ERR_SYSTEM_ERROR | 8,
0598     GPG_ERR_EBACKGROUND = GPG_ERR_SYSTEM_ERROR | 9,
0599     GPG_ERR_EBADE = GPG_ERR_SYSTEM_ERROR | 10,
0600     GPG_ERR_EBADF = GPG_ERR_SYSTEM_ERROR | 11,
0601     GPG_ERR_EBADFD = GPG_ERR_SYSTEM_ERROR | 12,
0602     GPG_ERR_EBADMSG = GPG_ERR_SYSTEM_ERROR | 13,
0603     GPG_ERR_EBADR = GPG_ERR_SYSTEM_ERROR | 14,
0604     GPG_ERR_EBADRPC = GPG_ERR_SYSTEM_ERROR | 15,
0605     GPG_ERR_EBADRQC = GPG_ERR_SYSTEM_ERROR | 16,
0606     GPG_ERR_EBADSLT = GPG_ERR_SYSTEM_ERROR | 17,
0607     GPG_ERR_EBFONT = GPG_ERR_SYSTEM_ERROR | 18,
0608     GPG_ERR_EBUSY = GPG_ERR_SYSTEM_ERROR | 19,
0609     GPG_ERR_ECANCELED = GPG_ERR_SYSTEM_ERROR | 20,
0610     GPG_ERR_ECHILD = GPG_ERR_SYSTEM_ERROR | 21,
0611     GPG_ERR_ECHRNG = GPG_ERR_SYSTEM_ERROR | 22,
0612     GPG_ERR_ECOMM = GPG_ERR_SYSTEM_ERROR | 23,
0613     GPG_ERR_ECONNABORTED = GPG_ERR_SYSTEM_ERROR | 24,
0614     GPG_ERR_ECONNREFUSED = GPG_ERR_SYSTEM_ERROR | 25,
0615     GPG_ERR_ECONNRESET = GPG_ERR_SYSTEM_ERROR | 26,
0616     GPG_ERR_ED = GPG_ERR_SYSTEM_ERROR | 27,
0617     GPG_ERR_EDEADLK = GPG_ERR_SYSTEM_ERROR | 28,
0618     GPG_ERR_EDEADLOCK = GPG_ERR_SYSTEM_ERROR | 29,
0619     GPG_ERR_EDESTADDRREQ = GPG_ERR_SYSTEM_ERROR | 30,
0620     GPG_ERR_EDIED = GPG_ERR_SYSTEM_ERROR | 31,
0621     GPG_ERR_EDOM = GPG_ERR_SYSTEM_ERROR | 32,
0622     GPG_ERR_EDOTDOT = GPG_ERR_SYSTEM_ERROR | 33,
0623     GPG_ERR_EDQUOT = GPG_ERR_SYSTEM_ERROR | 34,
0624     GPG_ERR_EEXIST = GPG_ERR_SYSTEM_ERROR | 35,
0625     GPG_ERR_EFAULT = GPG_ERR_SYSTEM_ERROR | 36,
0626     GPG_ERR_EFBIG = GPG_ERR_SYSTEM_ERROR | 37,
0627     GPG_ERR_EFTYPE = GPG_ERR_SYSTEM_ERROR | 38,
0628     GPG_ERR_EGRATUITOUS = GPG_ERR_SYSTEM_ERROR | 39,
0629     GPG_ERR_EGREGIOUS = GPG_ERR_SYSTEM_ERROR | 40,
0630     GPG_ERR_EHOSTDOWN = GPG_ERR_SYSTEM_ERROR | 41,
0631     GPG_ERR_EHOSTUNREACH = GPG_ERR_SYSTEM_ERROR | 42,
0632     GPG_ERR_EIDRM = GPG_ERR_SYSTEM_ERROR | 43,
0633     GPG_ERR_EIEIO = GPG_ERR_SYSTEM_ERROR | 44,
0634     GPG_ERR_EILSEQ = GPG_ERR_SYSTEM_ERROR | 45,
0635     GPG_ERR_EINPROGRESS = GPG_ERR_SYSTEM_ERROR | 46,
0636     GPG_ERR_EINTR = GPG_ERR_SYSTEM_ERROR | 47,
0637     GPG_ERR_EINVAL = GPG_ERR_SYSTEM_ERROR | 48,
0638     GPG_ERR_EIO = GPG_ERR_SYSTEM_ERROR | 49,
0639     GPG_ERR_EISCONN = GPG_ERR_SYSTEM_ERROR | 50,
0640     GPG_ERR_EISDIR = GPG_ERR_SYSTEM_ERROR | 51,
0641     GPG_ERR_EISNAM = GPG_ERR_SYSTEM_ERROR | 52,
0642     GPG_ERR_EL2HLT = GPG_ERR_SYSTEM_ERROR | 53,
0643     GPG_ERR_EL2NSYNC = GPG_ERR_SYSTEM_ERROR | 54,
0644     GPG_ERR_EL3HLT = GPG_ERR_SYSTEM_ERROR | 55,
0645     GPG_ERR_EL3RST = GPG_ERR_SYSTEM_ERROR | 56,
0646     GPG_ERR_ELIBACC = GPG_ERR_SYSTEM_ERROR | 57,
0647     GPG_ERR_ELIBBAD = GPG_ERR_SYSTEM_ERROR | 58,
0648     GPG_ERR_ELIBEXEC = GPG_ERR_SYSTEM_ERROR | 59,
0649     GPG_ERR_ELIBMAX = GPG_ERR_SYSTEM_ERROR | 60,
0650     GPG_ERR_ELIBSCN = GPG_ERR_SYSTEM_ERROR | 61,
0651     GPG_ERR_ELNRNG = GPG_ERR_SYSTEM_ERROR | 62,
0652     GPG_ERR_ELOOP = GPG_ERR_SYSTEM_ERROR | 63,
0653     GPG_ERR_EMEDIUMTYPE = GPG_ERR_SYSTEM_ERROR | 64,
0654     GPG_ERR_EMFILE = GPG_ERR_SYSTEM_ERROR | 65,
0655     GPG_ERR_EMLINK = GPG_ERR_SYSTEM_ERROR | 66,
0656     GPG_ERR_EMSGSIZE = GPG_ERR_SYSTEM_ERROR | 67,
0657     GPG_ERR_EMULTIHOP = GPG_ERR_SYSTEM_ERROR | 68,
0658     GPG_ERR_ENAMETOOLONG = GPG_ERR_SYSTEM_ERROR | 69,
0659     GPG_ERR_ENAVAIL = GPG_ERR_SYSTEM_ERROR | 70,
0660     GPG_ERR_ENEEDAUTH = GPG_ERR_SYSTEM_ERROR | 71,
0661     GPG_ERR_ENETDOWN = GPG_ERR_SYSTEM_ERROR | 72,
0662     GPG_ERR_ENETRESET = GPG_ERR_SYSTEM_ERROR | 73,
0663     GPG_ERR_ENETUNREACH = GPG_ERR_SYSTEM_ERROR | 74,
0664     GPG_ERR_ENFILE = GPG_ERR_SYSTEM_ERROR | 75,
0665     GPG_ERR_ENOANO = GPG_ERR_SYSTEM_ERROR | 76,
0666     GPG_ERR_ENOBUFS = GPG_ERR_SYSTEM_ERROR | 77,
0667     GPG_ERR_ENOCSI = GPG_ERR_SYSTEM_ERROR | 78,
0668     GPG_ERR_ENODATA = GPG_ERR_SYSTEM_ERROR | 79,
0669     GPG_ERR_ENODEV = GPG_ERR_SYSTEM_ERROR | 80,
0670     GPG_ERR_ENOENT = GPG_ERR_SYSTEM_ERROR | 81,
0671     GPG_ERR_ENOEXEC = GPG_ERR_SYSTEM_ERROR | 82,
0672     GPG_ERR_ENOLCK = GPG_ERR_SYSTEM_ERROR | 83,
0673     GPG_ERR_ENOLINK = GPG_ERR_SYSTEM_ERROR | 84,
0674     GPG_ERR_ENOMEDIUM = GPG_ERR_SYSTEM_ERROR | 85,
0675     GPG_ERR_ENOMEM = GPG_ERR_SYSTEM_ERROR | 86,
0676     GPG_ERR_ENOMSG = GPG_ERR_SYSTEM_ERROR | 87,
0677     GPG_ERR_ENONET = GPG_ERR_SYSTEM_ERROR | 88,
0678     GPG_ERR_ENOPKG = GPG_ERR_SYSTEM_ERROR | 89,
0679     GPG_ERR_ENOPROTOOPT = GPG_ERR_SYSTEM_ERROR | 90,
0680     GPG_ERR_ENOSPC = GPG_ERR_SYSTEM_ERROR | 91,
0681     GPG_ERR_ENOSR = GPG_ERR_SYSTEM_ERROR | 92,
0682     GPG_ERR_ENOSTR = GPG_ERR_SYSTEM_ERROR | 93,
0683     GPG_ERR_ENOSYS = GPG_ERR_SYSTEM_ERROR | 94,
0684     GPG_ERR_ENOTBLK = GPG_ERR_SYSTEM_ERROR | 95,
0685     GPG_ERR_ENOTCONN = GPG_ERR_SYSTEM_ERROR | 96,
0686     GPG_ERR_ENOTDIR = GPG_ERR_SYSTEM_ERROR | 97,
0687     GPG_ERR_ENOTEMPTY = GPG_ERR_SYSTEM_ERROR | 98,
0688     GPG_ERR_ENOTNAM = GPG_ERR_SYSTEM_ERROR | 99,
0689     GPG_ERR_ENOTSOCK = GPG_ERR_SYSTEM_ERROR | 100,
0690     GPG_ERR_ENOTSUP = GPG_ERR_SYSTEM_ERROR | 101,
0691     GPG_ERR_ENOTTY = GPG_ERR_SYSTEM_ERROR | 102,
0692     GPG_ERR_ENOTUNIQ = GPG_ERR_SYSTEM_ERROR | 103,
0693     GPG_ERR_ENXIO = GPG_ERR_SYSTEM_ERROR | 104,
0694     GPG_ERR_EOPNOTSUPP = GPG_ERR_SYSTEM_ERROR | 105,
0695     GPG_ERR_EOVERFLOW = GPG_ERR_SYSTEM_ERROR | 106,
0696     GPG_ERR_EPERM = GPG_ERR_SYSTEM_ERROR | 107,
0697     GPG_ERR_EPFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 108,
0698     GPG_ERR_EPIPE = GPG_ERR_SYSTEM_ERROR | 109,
0699     GPG_ERR_EPROCLIM = GPG_ERR_SYSTEM_ERROR | 110,
0700     GPG_ERR_EPROCUNAVAIL = GPG_ERR_SYSTEM_ERROR | 111,
0701     GPG_ERR_EPROGMISMATCH = GPG_ERR_SYSTEM_ERROR | 112,
0702     GPG_ERR_EPROGUNAVAIL = GPG_ERR_SYSTEM_ERROR | 113,
0703     GPG_ERR_EPROTO = GPG_ERR_SYSTEM_ERROR | 114,
0704     GPG_ERR_EPROTONOSUPPORT = GPG_ERR_SYSTEM_ERROR | 115,
0705     GPG_ERR_EPROTOTYPE = GPG_ERR_SYSTEM_ERROR | 116,
0706     GPG_ERR_ERANGE = GPG_ERR_SYSTEM_ERROR | 117,
0707     GPG_ERR_EREMCHG = GPG_ERR_SYSTEM_ERROR | 118,
0708     GPG_ERR_EREMOTE = GPG_ERR_SYSTEM_ERROR | 119,
0709     GPG_ERR_EREMOTEIO = GPG_ERR_SYSTEM_ERROR | 120,
0710     GPG_ERR_ERESTART = GPG_ERR_SYSTEM_ERROR | 121,
0711     GPG_ERR_EROFS = GPG_ERR_SYSTEM_ERROR | 122,
0712     GPG_ERR_ERPCMISMATCH = GPG_ERR_SYSTEM_ERROR | 123,
0713     GPG_ERR_ESHUTDOWN = GPG_ERR_SYSTEM_ERROR | 124,
0714     GPG_ERR_ESOCKTNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 125,
0715     GPG_ERR_ESPIPE = GPG_ERR_SYSTEM_ERROR | 126,
0716     GPG_ERR_ESRCH = GPG_ERR_SYSTEM_ERROR | 127,
0717     GPG_ERR_ESRMNT = GPG_ERR_SYSTEM_ERROR | 128,
0718     GPG_ERR_ESTALE = GPG_ERR_SYSTEM_ERROR | 129,
0719     GPG_ERR_ESTRPIPE = GPG_ERR_SYSTEM_ERROR | 130,
0720     GPG_ERR_ETIME = GPG_ERR_SYSTEM_ERROR | 131,
0721     GPG_ERR_ETIMEDOUT = GPG_ERR_SYSTEM_ERROR | 132,
0722     GPG_ERR_ETOOMANYREFS = GPG_ERR_SYSTEM_ERROR | 133,
0723     GPG_ERR_ETXTBSY = GPG_ERR_SYSTEM_ERROR | 134,
0724     GPG_ERR_EUCLEAN = GPG_ERR_SYSTEM_ERROR | 135,
0725     GPG_ERR_EUNATCH = GPG_ERR_SYSTEM_ERROR | 136,
0726     GPG_ERR_EUSERS = GPG_ERR_SYSTEM_ERROR | 137,
0727     GPG_ERR_EWOULDBLOCK = GPG_ERR_SYSTEM_ERROR | 138,
0728     GPG_ERR_EXDEV = GPG_ERR_SYSTEM_ERROR | 139,
0729     GPG_ERR_EXFULL = GPG_ERR_SYSTEM_ERROR | 140,
0730 
0731     /* This is one more than the largest allowed entry.  */
0732     GPG_ERR_CODE_DIM = 65536
0733   } gpg_err_code_t;
0734 
0735 
0736 /* The error value type gpg_error_t.  */
0737 
0738 /* We would really like to use bit-fields in a struct, but using
0739  * structs as return values can cause binary compatibility issues, in
0740  * particular if you want to do it efficiently (also see
0741  * -freg-struct-return option to GCC).  */
0742 typedef unsigned int gpg_error_t;
0743 
0744 /* We use the lowest 16 bits of gpg_error_t for error codes.  The 16th
0745  * bit indicates system errors.  */
0746 #define GPG_ERR_CODE_MASK   (GPG_ERR_CODE_DIM - 1)
0747 
0748 /* Bits 17 to 24 are reserved.  */
0749 
0750 /* We use the upper 7 bits of gpg_error_t for error sources.  */
0751 #define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
0752 #define GPG_ERR_SOURCE_SHIFT    24
0753 
0754 /* The highest bit is reserved.  It shouldn't be used to prevent
0755  * potential negative numbers when transmitting error values as
0756  * text.  */
0757 
0758 
0759 /*
0760  * GCC feature test.
0761  */
0762 #if __GNUC__
0763 # define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \
0764                                + __GNUC_MINOR__ * 100 \
0765                                + __GNUC_PATCHLEVEL__)
0766 #else
0767 # define _GPG_ERR_GCC_VERSION 0
0768 #endif
0769 
0770 #undef _GPG_ERR_HAVE_CONSTRUCTOR
0771 #if _GPG_ERR_GCC_VERSION > 30100
0772 # define _GPG_ERR_CONSTRUCTOR   __attribute__ ((__constructor__))
0773 # define _GPG_ERR_HAVE_CONSTRUCTOR
0774 #else
0775 # define _GPG_ERR_CONSTRUCTOR
0776 #endif
0777 
0778 #define GPGRT_GCC_VERSION  _GPG_ERR_GCC_VERSION
0779 
0780 #if _GPG_ERR_GCC_VERSION >= 29200
0781 # define _GPGRT__RESTRICT __restrict__
0782 #else
0783 # define _GPGRT__RESTRICT
0784 #endif
0785 
0786 /* The noreturn attribute.  */
0787 #if _GPG_ERR_GCC_VERSION >= 20500
0788 # define GPGRT_ATTR_NORETURN   __attribute__ ((__noreturn__))
0789 #else
0790 # define GPGRT_ATTR_NORETURN
0791 #endif
0792 
0793 /* The printf attributes.  */
0794 #if _GPG_ERR_GCC_VERSION >= 40400
0795 # define GPGRT_ATTR_PRINTF(f, a) \
0796                     __attribute__ ((format(__gnu_printf__,f,a)))
0797 # define GPGRT_ATTR_NR_PRINTF(f, a) \
0798                     __attribute__ ((__noreturn__, format(__gnu_printf__,f,a)))
0799 #elif _GPG_ERR_GCC_VERSION >= 20500
0800 # define GPGRT_ATTR_PRINTF(f, a) \
0801                     __attribute__ ((format(printf,f,a)))
0802 # define GPGRT_ATTR_NR_PRINTF(f, a) \
0803                     __attribute__ ((__noreturn__, format(printf,f,a)))
0804 #else
0805 # define GPGRT_ATTR_PRINTF(f, a)
0806 # define GPGRT_ATTR_NR_PRINTF(f, a)
0807 #endif
0808 #if _GPG_ERR_GCC_VERSION >= 20800
0809 # define GPGRT_ATTR_FORMAT_ARG(a)  __attribute__ ((__format_arg__ (a)))
0810 #else
0811 # define GPGRT_ATTR_FORMAT_ARG(a)
0812 #endif
0813 
0814 /* The sentinel attribute.  */
0815 #if _GPG_ERR_GCC_VERSION >= 40000
0816 # define GPGRT_ATTR_SENTINEL(a)  __attribute__ ((sentinel(a)))
0817 #else
0818 # define GPGRT_ATTR_SENTINEL(a)
0819 #endif
0820 
0821 /* The used and unused attributes.
0822  * I am not sure since when the unused attribute is really supported.
0823  * In any case it it only needed for gcc versions which print a
0824  * warning.  Thus let us require gcc >= 3.5.  */
0825 #if _GPG_ERR_GCC_VERSION >= 40000
0826 # define GPGRT_ATTR_USED  __attribute__ ((used))
0827 #else
0828 # define GPGRT_ATTR_USED
0829 #endif
0830 #if _GPG_ERR_GCC_VERSION >= 30500
0831 # define GPGRT_ATTR_UNUSED  __attribute__ ((unused))
0832 #else
0833 # define GPGRT_ATTR_UNUSED
0834 #endif
0835 
0836 /* The deprecated attribute.  */
0837 #if _GPG_ERR_GCC_VERSION >= 30100
0838 # define GPGRT_ATTR_DEPRECATED  __attribute__ ((__deprecated__))
0839 #else
0840 # define GPGRT_ATTR_DEPRECATED
0841 #endif
0842 
0843 /* The pure attribute.  */
0844 #if _GPG_ERR_GCC_VERSION >= 29600
0845 # define GPGRT_ATTR_PURE  __attribute__ ((__pure__))
0846 #else
0847 # define GPGRT_ATTR_PURE
0848 #endif
0849 
0850 /* The malloc attribute.  */
0851 #if _GPG_ERR_GCC_VERSION >= 30200
0852 # define GPGRT_ATTR_MALLOC  __attribute__ ((__malloc__))
0853 #else
0854 # define GPGRT_ATTR_MALLOC
0855 #endif
0856 
0857 #if _GPG_ERR_GCC_VERSION >= 80000
0858 # define GPGRT_ATTR_NONSTRING __attribute__((__nonstring__))
0859 #else
0860 # define GPGRT_ATTR_NONSTRING
0861 #endif
0862 
0863 /* A macro defined if a GCC style __FUNCTION__ macro is available.  */
0864 #undef GPGRT_HAVE_MACRO_FUNCTION
0865 #if _GPG_ERR_GCC_VERSION >= 20500
0866 # define GPGRT_HAVE_MACRO_FUNCTION 1
0867 #endif
0868 
0869 /* A macro defined if the pragma GCC push_options is available.  */
0870 #undef GPGRT_HAVE_PRAGMA_GCC_PUSH
0871 #if _GPG_ERR_GCC_VERSION >= 40400
0872 # define GPGRT_HAVE_PRAGMA_GCC_PUSH 1
0873 #endif
0874 
0875 /* Detect LeakSanitizer (LSan) support for GCC and Clang based on
0876  * whether AddressSanitizer (ASAN) is enabled via -fsanitize=address).
0877  * Note that -fsanitize=leak just affect the linker options which
0878  * cannot be detected here.  In that case you have to define the
0879  * GPGRT_HAVE_LEAK_SANITIZER macro manually.  */
0880 #ifdef __GNUC__
0881 # ifdef __SANITIZE_ADDRESS__
0882 #  define GPGRT_HAVE_LEAK_SANITIZER
0883 # elif defined(__has_feature)
0884 #  if __has_feature(address_sanitizer)
0885 #   define GPGRT_HAVE_LEAK_SANITIZER
0886 #  endif
0887 # endif
0888 #endif
0889 
0890 
0891 /* The new name for the inline macro.  */
0892 #define GPGRT_INLINE GPG_ERR_INLINE
0893 
0894 #ifdef GPGRT_HAVE_LEAK_SANITIZER
0895 # include <sanitizer/lsan_interface.h>
0896 #endif
0897 
0898 /* Mark heap objects as non-leaked memory. */
0899 static GPGRT_INLINE void
0900 gpgrt_annotate_leaked_object (const void *p)
0901 {
0902 #ifdef GPGRT_HAVE_LEAK_SANITIZER
0903   __lsan_ignore_object(p);
0904 #else
0905   (void)p;
0906 #endif
0907 }
0908 
0909 
0910 /*
0911  * Initialization function.
0912  */
0913 
0914 /* Initialize the library.  This function should be run early.  */
0915 gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR;
0916 
0917 /* If this is defined, the library is already initialized by the
0918    constructor and does not need to be initialized explicitely.  */
0919 #undef GPG_ERR_INITIALIZED
0920 #ifdef _GPG_ERR_HAVE_CONSTRUCTOR
0921 # define GPG_ERR_INITIALIZED    1
0922 # define gpgrt_init() do { gpg_err_init (); } while (0)
0923 #else
0924 # define gpgrt_init() do { ; } while (0)
0925 #endif
0926 
0927 /* See the source on how to use the deinit function; it is usually not
0928    required.  */
0929 void gpg_err_deinit (int mode);
0930 
0931 /* Register blocking system I/O clamping functions.  */
0932 void gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void));
0933 
0934 /* Get current I/O clamping functions.  */
0935 void gpgrt_get_syscall_clamp (void (**r_pre)(void), void (**r_post)(void));
0936 
0937 /* Register a custom malloc/realloc/free function.  */
0938 void gpgrt_set_alloc_func  (void *(*f)(void *a, size_t n));
0939 
0940 /* Register an emergency cleanup handler.  */
0941 void gpgrt_add_emergency_cleanup (void (*f)(void));
0942 
0943 /* Wrapper around abort to make sure emergency cleanups are run.  */
0944 void gpgrt_abort (void) GPGRT_ATTR_NORETURN;
0945 
0946 
0947 
0948 /*
0949  * Constructor and accessor functions.
0950  */
0951 
0952 /* Construct an error value from an error code and source.  Within a
0953  * subsystem, use gpg_error.  */
0954 static GPG_ERR_INLINE gpg_error_t
0955 gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
0956 {
0957   return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
0958     : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
0959        | (code & GPG_ERR_CODE_MASK));
0960 }
0961 
0962 
0963 /* The user should define GPG_ERR_SOURCE_DEFAULT before including this
0964  * file to specify a default source for gpg_error.  */
0965 #ifndef GPG_ERR_SOURCE_DEFAULT
0966 #define GPG_ERR_SOURCE_DEFAULT  GPG_ERR_SOURCE_UNKNOWN
0967 #endif
0968 
0969 static GPG_ERR_INLINE gpg_error_t
0970 gpg_error (gpg_err_code_t code)
0971 {
0972   return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
0973 }
0974 
0975 
0976 /* Retrieve the error code from an error value.  */
0977 static GPG_ERR_INLINE gpg_err_code_t
0978 gpg_err_code (gpg_error_t err)
0979 {
0980   return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
0981 }
0982 
0983 
0984 /* Retrieve the error source from an error value.  */
0985 static GPG_ERR_INLINE gpg_err_source_t
0986 gpg_err_source (gpg_error_t err)
0987 {
0988   return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
0989                  & GPG_ERR_SOURCE_MASK);
0990 }
0991 
0992 
0993 /* String functions.  */
0994 
0995 /* Return a pointer to a string containing a description of the error
0996  * code in the error value ERR.  This function is not thread-safe.  */
0997 const char *gpg_strerror (gpg_error_t err);
0998 
0999 /* Return the error string for ERR in the user-supplied buffer BUF of
1000  * size BUFLEN.  This function is, in contrast to gpg_strerror,
1001  * thread-safe if a thread-safe strerror_r() function is provided by
1002  * the system.  If the function succeeds, 0 is returned and BUF
1003  * contains the string describing the error.  If the buffer was not
1004  * large enough, ERANGE is returned and BUF contains as much of the
1005  * beginning of the error string as fits into the buffer.  */
1006 int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
1007 
1008 /* Return a pointer to a string containing a description of the error
1009  * source in the error value ERR.  */
1010 const char *gpg_strsource (gpg_error_t err);
1011 
1012 
1013 /*
1014  * Mapping of system errors (errno).
1015  */
1016 
1017 /* Retrieve the error code for the system error ERR.  This returns
1018  * GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
1019  * this). */
1020 gpg_err_code_t gpg_err_code_from_errno (int err);
1021 
1022 /* Retrieve the system error for the error code CODE.  This returns 0
1023  * if CODE is not a system error code.  */
1024 int gpg_err_code_to_errno (gpg_err_code_t code);
1025 
1026 /* Retrieve the error code directly from the ERRNO variable.  This
1027  * returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
1028  * (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
1029 gpg_err_code_t gpg_err_code_from_syserror (void);
1030 
1031 /* Mapper for SQLite primary error codes.  */
1032 static GPG_ERR_INLINE gpg_error_t
1033 gpg_err_code_from_sqlite (int sqlres)
1034 {
1035   return sqlres? GPG_ERR_SQL_OK + (sqlres & 0xff) : 0;
1036 }
1037 
1038 
1039 /* Set the ERRNO variable.  This function is the preferred way to set
1040  * ERRNO due to peculiarities on WindowsCE.  */
1041 void gpg_err_set_errno (int err);
1042 
1043 /* Return or check the version.  Both functions are identical.  */
1044 const char *gpgrt_check_version (const char *req_version);
1045 const char *gpg_error_check_version (const char *req_version);
1046 
1047 /* System specific type definitions.  */
1048 #include <sys/types.h>
1049 typedef ssize_t gpgrt_ssize_t;
1050 
1051 typedef long gpgrt_off_t;
1052 
1053 
1054 
1055 
1056 /* Self-documenting convenience functions.  */
1057 
1058 static GPG_ERR_INLINE gpg_error_t
1059 gpg_err_make_from_errno (gpg_err_source_t source, int err)
1060 {
1061   return gpg_err_make (source, gpg_err_code_from_errno (err));
1062 }
1063 
1064 
1065 static GPG_ERR_INLINE gpg_error_t
1066 gpg_error_from_errno (int err)
1067 {
1068   return gpg_error (gpg_err_code_from_errno (err));
1069 }
1070 
1071 static GPG_ERR_INLINE gpg_error_t
1072 gpg_error_from_syserror (void)
1073 {
1074   return gpg_error (gpg_err_code_from_syserror ());
1075 }
1076 
1077 
1078 
1079 /*
1080  * Malloc and friends
1081  */
1082 
1083 void *gpgrt_realloc (void *a, size_t n);
1084 void *gpgrt_reallocarray (void *a, size_t oldnmemb, size_t nmemb, size_t size);
1085 void *gpgrt_malloc (size_t n);
1086 void *gpgrt_calloc (size_t n, size_t m);
1087 char *gpgrt_strdup (const char *string);
1088 char *gpgrt_strconcat (const char *s1, ...) GPGRT_ATTR_SENTINEL(0);
1089 void gpgrt_free (void *a);
1090 void gpgrt_wipememory (void *ptr, size_t len);
1091 
1092 
1093 /*
1094  * System specific function wrappers.
1095  */
1096 
1097 /* A getenv replacement which mallocs the returned string.  */
1098 char *gpgrt_getenv (const char *name);
1099 
1100 /* A setenv and a unsetenv replacement.*/
1101 gpg_err_code_t gpgrt_setenv (const char *name,
1102                              const char *value, int overwrite);
1103 #define gpgrt_unsetenv(n) gpgrt_setenv ((n), NULL, 1)
1104 
1105 /* A wrapper around mkdir using a string for the mode.  */
1106 gpg_err_code_t gpgrt_mkdir (const char *name, const char *modestr);
1107 
1108 /* A simple wrapper around chdir.  */
1109 gpg_err_code_t gpgrt_chdir (const char *name);
1110 
1111 /* Return the current WD as a malloced string.  */
1112 char *gpgrt_getcwd (void);
1113 
1114 /* A wrapper around access to handle UTF-8 on Windows.  */
1115 gpg_err_code_t gpgrt_access (const char *fname, int mode);
1116 
1117 
1118 
1119 
1120 /*
1121  * Lock functions.
1122  */
1123 
1124 
1125 typedef struct
1126 {
1127   long _vers;
1128   union {
1129     volatile char _priv[40];
1130     long _x_align;
1131     long *_xp_align;
1132   } u;
1133 } gpgrt_lock_t;
1134 
1135 #define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \
1136                                     0,0,0,0,0,0,0,0, \
1137                                     0,0,0,0,0,0,0,0, \
1138                                     0,0,0,0,0,0,0,0, \
1139                                     0,0,0,0,0,0,0,0}}}
1140 
1141 
1142 #define GPGRT_LOCK_DEFINE(name) \
1143   static gpgrt_lock_t name  = GPGRT_LOCK_INITIALIZER
1144 
1145 /* NB: If GPGRT_LOCK_DEFINE is not used, zero out the lock variable
1146    before passing it to gpgrt_lock_init.  */
1147 gpg_err_code_t gpgrt_lock_init (gpgrt_lock_t *lockhd);
1148 gpg_err_code_t gpgrt_lock_lock (gpgrt_lock_t *lockhd);
1149 gpg_err_code_t gpgrt_lock_trylock (gpgrt_lock_t *lockhd);
1150 gpg_err_code_t gpgrt_lock_unlock (gpgrt_lock_t *lockhd);
1151 gpg_err_code_t gpgrt_lock_destroy (gpgrt_lock_t *lockhd);
1152 
1153 
1154 
1155 /*
1156  * Thread functions.
1157  */
1158 
1159 gpg_err_code_t gpgrt_yield (void);
1160 
1161 
1162 
1163 
1164 /*
1165  * Estream
1166  */
1167 
1168 /* The definition of this struct is entirely private.  You must not
1169    use it for anything.  It is only here so some functions can be
1170    implemented as macros.  */
1171 struct _gpgrt_stream_internal;
1172 struct _gpgrt__stream
1173 {
1174   /* The layout of this struct must never change.  It may be grown,
1175      but only if all functions which access the new members are
1176      versioned.  */
1177 
1178   /* Various flags.  */
1179   struct {
1180     unsigned int magic: 16;
1181     unsigned int writing: 1;
1182     unsigned int reserved: 15;
1183   } flags;
1184 
1185   /* A pointer to the stream buffer.  */
1186   unsigned char *buffer;
1187 
1188   /* The size of the buffer in bytes.  */
1189   size_t buffer_size;
1190 
1191   /* The length of the usable data in the buffer, only valid when in
1192      read mode (see flags).  */
1193   size_t data_len;
1194 
1195   /* The current position of the offset pointer, valid in read and
1196      write mode.  */
1197   size_t data_offset;
1198 
1199   size_t data_flushed;
1200   unsigned char *unread_buffer;
1201   size_t unread_buffer_size;
1202 
1203   /* The number of unread bytes.  */
1204   size_t unread_data_len;
1205 
1206   /* A pointer to our internal data for this stream.  */
1207   struct _gpgrt_stream_internal *intern;
1208 };
1209 
1210 /* The opaque type for an estream.  */
1211 typedef struct _gpgrt__stream *gpgrt_stream_t;
1212 #ifdef GPGRT_ENABLE_ES_MACROS
1213 typedef struct _gpgrt__stream *estream_t;
1214 #endif
1215 
1216 typedef ssize_t (*gpgrt_cookie_read_function_t) (void *cookie,
1217                                                  void *buffer, size_t size);
1218 typedef ssize_t (*gpgrt_cookie_write_function_t) (void *cookie,
1219                                                   const void *buffer,
1220                                                   size_t size);
1221 typedef int (*gpgrt_cookie_seek_function_t) (void *cookie,
1222                                              gpgrt_off_t *pos, int whence);
1223 typedef int (*gpgrt_cookie_close_function_t) (void *cookie);
1224 
1225 struct _gpgrt_cookie_io_functions
1226 {
1227   gpgrt_cookie_read_function_t func_read;
1228   gpgrt_cookie_write_function_t func_write;
1229   gpgrt_cookie_seek_function_t func_seek;
1230   gpgrt_cookie_close_function_t func_close;
1231 };
1232 typedef struct _gpgrt_cookie_io_functions gpgrt_cookie_io_functions_t;
1233 #ifdef GPGRT_ENABLE_ES_MACROS
1234 typedef struct _gpgrt_cookie_io_functions  es_cookie_io_functions_t;
1235 #define es_cookie_read_function_t  gpgrt_cookie_read_function_t
1236 #define es_cookie_write_function_t gpgrt_cookie_read_function_t
1237 #define es_cookie_seek_function_t  gpgrt_cookie_read_function_t
1238 #define es_cookie_close_function_t gpgrt_cookie_read_function_t
1239 #endif
1240 
1241 enum gpgrt_syshd_types
1242   {
1243     GPGRT_SYSHD_NONE = 0,  /* No system handle available.                   */
1244     GPGRT_SYSHD_FD = 1,    /* A file descriptor as returned by open().      */
1245     GPGRT_SYSHD_SOCK = 2,  /* A socket as returned by socket().             */
1246     GPGRT_SYSHD_RVID = 3,  /* A rendezvous id (see libassuan's gpgcedev.c).  */
1247     GPGRT_SYSHD_HANDLE = 4 /* A HANDLE object (Windows).                    */
1248   };
1249 
1250 struct _gpgrt_syshd
1251 {
1252   enum gpgrt_syshd_types type;
1253   union {
1254     int fd;
1255     int sock;
1256     int rvid;
1257     void *handle;
1258   } u;
1259 };
1260 typedef struct _gpgrt_syshd gpgrt_syshd_t;
1261 #ifdef GPGRT_ENABLE_ES_MACROS
1262 typedef struct _gpgrt_syshd es_syshd_t;
1263 #define ES_SYSHD_NONE   GPGRT_SYSHD_NONE
1264 #define ES_SYSHD_FD     GPGRT_SYSHD_FD
1265 #define ES_SYSHD_SOCK   GPGRT_SYSHD_SOCK
1266 #define ES_SYSHD_RVID   GPGRT_SYSHD_RVID
1267 #define ES_SYSHD_HANDLE GPGRT_SYSHD_HANDLE
1268 #endif
1269 
1270 /* The object used with gpgrt_poll.  */
1271 struct _gpgrt_poll_s
1272 {
1273   gpgrt_stream_t stream;
1274   unsigned int want_read:1;
1275   unsigned int want_write:1;
1276   unsigned int want_oob:1;
1277   unsigned int want_rdhup:1;
1278   unsigned int _reserv1:4;
1279   unsigned int got_read:1;
1280   unsigned int got_write:1;
1281   unsigned int got_oob:1;
1282   unsigned int got_rdhup:1;
1283   unsigned int _reserv2:4;
1284   unsigned int got_err:1;
1285   unsigned int got_hup:1;
1286   unsigned int got_nval:1;
1287   unsigned int _reserv3:4;
1288   unsigned int ignore:1;
1289   unsigned int user:8;       /* For application use.  */
1290 };
1291 typedef struct _gpgrt_poll_s gpgrt_poll_t;
1292 #ifdef GPGRT_ENABLE_ES_MACROS
1293 typedef struct _gpgrt_poll_s es_poll_t;
1294 #endif
1295 
1296 /* The type of the string filter function as used by fprintf_sf et al.  */
1297 typedef char *(*gpgrt_string_filter_t) (const char *s, int n, void *opaque);
1298 
1299 
1300 
1301 gpgrt_stream_t gpgrt_fopen (const char *_GPGRT__RESTRICT path,
1302                             const char *_GPGRT__RESTRICT mode);
1303 gpgrt_stream_t gpgrt_mopen (void *_GPGRT__RESTRICT data,
1304                             size_t data_n, size_t data_len,
1305                             unsigned int grow,
1306                             void *(*func_realloc) (void *mem, size_t size),
1307                             void (*func_free) (void *mem),
1308                             const char *_GPGRT__RESTRICT mode);
1309 gpgrt_stream_t gpgrt_fopenmem (size_t memlimit,
1310                                const char *_GPGRT__RESTRICT mode);
1311 gpgrt_stream_t gpgrt_fopenmem_init (size_t memlimit,
1312                                     const char *_GPGRT__RESTRICT mode,
1313                                     const void *data, size_t datalen);
1314 gpgrt_stream_t gpgrt_fdopen    (int filedes, const char *mode);
1315 gpgrt_stream_t gpgrt_fdopen_nc (int filedes, const char *mode);
1316 gpgrt_stream_t gpgrt_sysopen    (gpgrt_syshd_t *syshd, const char *mode);
1317 gpgrt_stream_t gpgrt_sysopen_nc (gpgrt_syshd_t *syshd, const char *mode);
1318 gpgrt_stream_t gpgrt_fpopen    (FILE *fp, const char *mode);
1319 gpgrt_stream_t gpgrt_fpopen_nc (FILE *fp, const char *mode);
1320 gpgrt_stream_t gpgrt_freopen (const char *_GPGRT__RESTRICT path,
1321                               const char *_GPGRT__RESTRICT mode,
1322                               gpgrt_stream_t _GPGRT__RESTRICT stream);
1323 gpgrt_stream_t gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie,
1324                                   const char *_GPGRT__RESTRICT mode,
1325                                   gpgrt_cookie_io_functions_t functions);
1326 int gpgrt_fclose (gpgrt_stream_t stream);
1327 int gpgrt_fcancel (gpgrt_stream_t stream);
1328 int gpgrt_fclose_snatch (gpgrt_stream_t stream,
1329                          void **r_buffer, size_t *r_buflen);
1330 int gpgrt_onclose (gpgrt_stream_t stream, int mode,
1331                    void (*fnc) (gpgrt_stream_t, void*), void *fnc_value);
1332 int gpgrt_fileno (gpgrt_stream_t stream);
1333 int gpgrt_fileno_unlocked (gpgrt_stream_t stream);
1334 int gpgrt_syshd (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
1335 int gpgrt_syshd_unlocked (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
1336 
1337 void _gpgrt_set_std_fd (int no, int fd);
1338 gpgrt_stream_t _gpgrt_get_std_stream (int fd);
1339 
1340 #define gpgrt_stdin  _gpgrt_get_std_stream (0)
1341 #define gpgrt_stdout _gpgrt_get_std_stream (1)
1342 #define gpgrt_stderr _gpgrt_get_std_stream (2)
1343 
1344 
1345 void gpgrt_flockfile (gpgrt_stream_t stream);
1346 int  gpgrt_ftrylockfile (gpgrt_stream_t stream);
1347 void gpgrt_funlockfile (gpgrt_stream_t stream);
1348 
1349 int gpgrt_feof (gpgrt_stream_t stream);
1350 int gpgrt_feof_unlocked (gpgrt_stream_t stream);
1351 int gpgrt_ferror (gpgrt_stream_t stream);
1352 int gpgrt_ferror_unlocked (gpgrt_stream_t stream);
1353 void gpgrt_clearerr (gpgrt_stream_t stream);
1354 void gpgrt_clearerr_unlocked (gpgrt_stream_t stream);
1355 
1356 int _gpgrt_pending (gpgrt_stream_t stream);          /* (private) */
1357 int _gpgrt_pending_unlocked (gpgrt_stream_t stream); /* (private) */
1358 
1359 #define gpgrt_pending(stream) _gpgrt_pending (stream)
1360 
1361 #define gpgrt_pending_unlocked(stream)              \
1362   (((!(stream)->flags.writing)                  \
1363     && (((stream)->data_offset < (stream)->data_len)        \
1364         || ((stream)->unread_data_len)))                        \
1365    ? 1 : _gpgrt_pending_unlocked ((stream)))
1366 
1367 int gpgrt_fflush (gpgrt_stream_t stream);
1368 int gpgrt_fseek (gpgrt_stream_t stream, long int offset, int whence);
1369 int gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence);
1370 int gpgrt_ftruncate (gpgrt_stream_t stream, gpgrt_off_t length);
1371 long int gpgrt_ftell (gpgrt_stream_t stream);
1372 gpgrt_off_t gpgrt_ftello (gpgrt_stream_t stream);
1373 void gpgrt_rewind (gpgrt_stream_t stream);
1374 
1375 int gpgrt_fgetc (gpgrt_stream_t stream);
1376 int gpgrt_fputc (int c, gpgrt_stream_t stream);
1377 
1378 int _gpgrt_getc_underflow (gpgrt_stream_t stream);       /* (private) */
1379 int _gpgrt_putc_overflow (int c, gpgrt_stream_t stream); /* (private) */
1380 
1381 #define gpgrt_getc_unlocked(stream)             \
1382   (((!(stream)->flags.writing)                  \
1383     && ((stream)->data_offset < (stream)->data_len)     \
1384     && (! (stream)->unread_data_len))               \
1385   ? ((int) (stream)->buffer[((stream)->data_offset)++])     \
1386   : _gpgrt_getc_underflow ((stream)))
1387 
1388 #define gpgrt_putc_unlocked(c, stream)              \
1389   (((stream)->flags.writing                 \
1390     && ((stream)->data_offset < (stream)->buffer_size)      \
1391     && (c != '\n'))                     \
1392   ? ((int) ((stream)->buffer[((stream)->data_offset)++] = (c))) \
1393   : _gpgrt_putc_overflow ((c), (stream)))
1394 
1395 #define gpgrt_getc(stream)    gpgrt_fgetc (stream)
1396 #define gpgrt_putc(c, stream) gpgrt_fputc (c, stream)
1397 
1398 int gpgrt_ungetc (int c, gpgrt_stream_t stream);
1399 
1400 int gpgrt_read (gpgrt_stream_t _GPGRT__RESTRICT stream,
1401                 void *_GPGRT__RESTRICT buffer, size_t bytes_to_read,
1402                 size_t *_GPGRT__RESTRICT bytes_read);
1403 int gpgrt_write (gpgrt_stream_t _GPGRT__RESTRICT stream,
1404                  const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write,
1405                  size_t *_GPGRT__RESTRICT bytes_written);
1406 int gpgrt_write_sanitized (gpgrt_stream_t _GPGRT__RESTRICT stream,
1407                            const void *_GPGRT__RESTRICT buffer, size_t length,
1408                            const char *delimiters,
1409                            size_t *_GPGRT__RESTRICT bytes_written);
1410 int gpgrt_write_hexstring (gpgrt_stream_t _GPGRT__RESTRICT stream,
1411                            const void *_GPGRT__RESTRICT buffer, size_t length,
1412                            int reserved,
1413                            size_t *_GPGRT__RESTRICT bytes_written);
1414 
1415 size_t gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems,
1416                     gpgrt_stream_t _GPGRT__RESTRICT stream);
1417 size_t gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr, size_t size,
1418                      size_t nitems, gpgrt_stream_t _GPGRT__RESTRICT stream);
1419 
1420 char *gpgrt_fgets (char *_GPGRT__RESTRICT s, int n,
1421                    gpgrt_stream_t _GPGRT__RESTRICT stream);
1422 int gpgrt_fputs (const char *_GPGRT__RESTRICT s,
1423                  gpgrt_stream_t _GPGRT__RESTRICT stream);
1424 int gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s,
1425                           gpgrt_stream_t _GPGRT__RESTRICT stream);
1426 
1427 ssize_t gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr,
1428                        size_t *_GPGRT__RESTRICT n,
1429                        gpgrt_stream_t stream);
1430 ssize_t gpgrt_read_line (gpgrt_stream_t stream,
1431                          char **addr_of_buffer, size_t *length_of_buffer,
1432                          size_t *max_length);
1433 
1434 int gpgrt_fprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1435                    const char *_GPGRT__RESTRICT format, ...)
1436                    GPGRT_ATTR_PRINTF(2,3);
1437 int gpgrt_fprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
1438                             const char *_GPGRT__RESTRICT format, ...)
1439                             GPGRT_ATTR_PRINTF(2,3);
1440 
1441 int gpgrt_fprintf_sf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1442                       gpgrt_string_filter_t sf, void *sfvalue,
1443                       const char *_GPGRT__RESTRICT format,
1444                       ...) GPGRT_ATTR_PRINTF(4,5);
1445 int gpgrt_fprintf_sf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
1446                                gpgrt_string_filter_t sf, void *sfvalue,
1447                                const char *_GPGRT__RESTRICT format,
1448                                ...) GPGRT_ATTR_PRINTF(4,5);
1449 
1450 int gpgrt_printf (const char *_GPGRT__RESTRICT format, ...)
1451                   GPGRT_ATTR_PRINTF(1,2);
1452 int gpgrt_printf_unlocked (const char *_GPGRT__RESTRICT format, ...)
1453                            GPGRT_ATTR_PRINTF(1,2);
1454 
1455 int gpgrt_vfprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1456                     const char *_GPGRT__RESTRICT format, va_list ap)
1457                     GPGRT_ATTR_PRINTF(2,0);
1458 int gpgrt_vfprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
1459                              const char *_GPGRT__RESTRICT format, va_list ap)
1460                              GPGRT_ATTR_PRINTF(2,0);
1461 
1462 int gpgrt_setvbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1463                    char *_GPGRT__RESTRICT buf, int mode, size_t size);
1464 void gpgrt_setbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
1465                    char *_GPGRT__RESTRICT buf);
1466 
1467 void gpgrt_set_binary (gpgrt_stream_t stream);
1468 int  gpgrt_set_nonblock (gpgrt_stream_t stream, int onoff);
1469 int  gpgrt_get_nonblock (gpgrt_stream_t stream);
1470 
1471 int gpgrt_poll (gpgrt_poll_t *fdlist, unsigned int nfds, int timeout);
1472 
1473 gpgrt_stream_t gpgrt_tmpfile (void);
1474 
1475 void gpgrt_opaque_set (gpgrt_stream_t _GPGRT__RESTRICT stream,
1476                        void *_GPGRT__RESTRICT opaque);
1477 void *gpgrt_opaque_get (gpgrt_stream_t stream);
1478 
1479 void gpgrt_fname_set (gpgrt_stream_t stream, const char *fname);
1480 const char *gpgrt_fname_get (gpgrt_stream_t stream);
1481 
1482 int gpgrt_asprintf (char **r_buf, const char * _GPGRT__RESTRICT format, ...)
1483                     GPGRT_ATTR_PRINTF(2,3);
1484 int gpgrt_vasprintf (char **r_buf, const char * _GPGRT__RESTRICT format,
1485                      va_list ap)
1486                      GPGRT_ATTR_PRINTF(2,0);
1487 char *gpgrt_bsprintf (const char * _GPGRT__RESTRICT format, ...)
1488                       GPGRT_ATTR_PRINTF(1,2);
1489 char *gpgrt_vbsprintf (const char * _GPGRT__RESTRICT format, va_list ap)
1490                        GPGRT_ATTR_PRINTF(1,0);
1491 int gpgrt_snprintf (char *buf, size_t bufsize,
1492                     const char * _GPGRT__RESTRICT format, ...)
1493                     GPGRT_ATTR_PRINTF(3,4);
1494 int gpgrt_vsnprintf (char *buf,size_t bufsize,
1495                      const char * _GPGRT__RESTRICT format, va_list arg_ptr)
1496                      GPGRT_ATTR_PRINTF(3,0);
1497 
1498 
1499 #ifdef GPGRT_ENABLE_ES_MACROS
1500 # define es_fopen             gpgrt_fopen
1501 # define es_mopen             gpgrt_mopen
1502 # define es_fopenmem          gpgrt_fopenmem
1503 # define es_fopenmem_init     gpgrt_fopenmem_init
1504 # define es_fdopen            gpgrt_fdopen
1505 # define es_fdopen_nc         gpgrt_fdopen_nc
1506 # define es_sysopen           gpgrt_sysopen
1507 # define es_sysopen_nc        gpgrt_sysopen_nc
1508 # define es_fpopen            gpgrt_fpopen
1509 # define es_fpopen_nc         gpgrt_fpopen_nc
1510 # define es_freopen           gpgrt_freopen
1511 # define es_fopencookie       gpgrt_fopencookie
1512 # define es_fclose            gpgrt_fclose
1513 # define es_fclose_snatch     gpgrt_fclose_snatch
1514 # define es_onclose           gpgrt_onclose
1515 # define es_fileno            gpgrt_fileno
1516 # define es_fileno_unlocked   gpgrt_fileno_unlocked
1517 # define es_syshd             gpgrt_syshd
1518 # define es_syshd_unlocked    gpgrt_syshd_unlocked
1519 # define es_stdin             _gpgrt_get_std_stream (0)
1520 # define es_stdout            _gpgrt_get_std_stream (1)
1521 # define es_stderr            _gpgrt_get_std_stream (2)
1522 # define es_flockfile         gpgrt_flockfile
1523 # define es_ftrylockfile      gpgrt_ftrylockfile
1524 # define es_funlockfile       gpgrt_funlockfile
1525 # define es_feof              gpgrt_feof
1526 # define es_feof_unlocked     gpgrt_feof_unlocked
1527 # define es_ferror            gpgrt_ferror
1528 # define es_ferror_unlocked   gpgrt_ferror_unlocked
1529 # define es_clearerr          gpgrt_clearerr
1530 # define es_clearerr_unlocked gpgrt_clearerr_unlocked
1531 # define es_pending           gpgrt_pending
1532 # define es_pending_unlocked  gpgrt_pending_unlocked
1533 # define es_fflush            gpgrt_fflush
1534 # define es_fseek             gpgrt_fseek
1535 # define es_fseeko            gpgrt_fseeko
1536 # define es_ftruncate         gpgrt_ftruncate
1537 # define es_ftell             gpgrt_ftell
1538 # define es_ftello            gpgrt_ftello
1539 # define es_rewind            gpgrt_rewind
1540 # define es_fgetc             gpgrt_fgetc
1541 # define es_fputc             gpgrt_fputc
1542 # define es_getc_unlocked     gpgrt_getc_unlocked
1543 # define es_putc_unlocked     gpgrt_putc_unlocked
1544 # define es_getc              gpgrt_getc
1545 # define es_putc              gpgrt_putc
1546 # define es_ungetc            gpgrt_ungetc
1547 # define es_read              gpgrt_read
1548 # define es_write             gpgrt_write
1549 # define es_write_sanitized   gpgrt_write_sanitized
1550 # define es_write_hexstring   gpgrt_write_hexstring
1551 # define es_fread             gpgrt_fread
1552 # define es_fwrite            gpgrt_fwrite
1553 # define es_fgets             gpgrt_fgets
1554 # define es_fputs             gpgrt_fputs
1555 # define es_fputs_unlocked    gpgrt_fputs_unlocked
1556 # define es_getline           gpgrt_getline
1557 # define es_read_line         gpgrt_read_line
1558 # define es_free              gpgrt_free
1559 # define es_fprintf           gpgrt_fprintf
1560 # define es_fprintf_unlocked  gpgrt_fprintf_unlocked
1561 # define es_printf            gpgrt_printf
1562 # define es_printf_unlocked   gpgrt_printf_unlocked
1563 # define es_vfprintf          gpgrt_vfprintf
1564 # define es_vfprintf_unlocked gpgrt_vfprintf_unlocked
1565 # define es_setvbuf           gpgrt_setvbuf
1566 # define es_setbuf            gpgrt_setbuf
1567 # define es_set_binary        gpgrt_set_binary
1568 # define es_set_nonblock      gpgrt_set_nonblock
1569 # define es_get_nonblock      gpgrt_get_nonblock
1570 # define es_poll              gpgrt_poll
1571 # define es_tmpfile           gpgrt_tmpfile
1572 # define es_opaque_set        gpgrt_opaque_set
1573 # define es_opaque_get        gpgrt_opaque_get
1574 # define es_fname_set         gpgrt_fname_set
1575 # define es_fname_get         gpgrt_fname_get
1576 # define es_asprintf          gpgrt_asprintf
1577 # define es_vasprintf         gpgrt_vasprintf
1578 # define es_bsprintf          gpgrt_bsprintf
1579 # define es_vbsprintf         gpgrt_vbsprintf
1580 #endif /*GPGRT_ENABLE_ES_MACROS*/
1581 
1582 
1583 
1584 /*
1585  * Base64 encode and decode functions.
1586  */
1587 
1588 struct _gpgrt_b64state;
1589 typedef struct _gpgrt_b64state *gpgrt_b64state_t;
1590 
1591 gpgrt_b64state_t gpgrt_b64enc_start (gpgrt_stream_t stream, const char *title);
1592 gpg_err_code_t   gpgrt_b64enc_write (gpgrt_b64state_t state,
1593                                      const void *buffer, size_t nbytes);
1594 gpg_err_code_t   gpgrt_b64enc_finish (gpgrt_b64state_t state);
1595 
1596 gpgrt_b64state_t gpgrt_b64dec_start (const char *title);
1597 gpg_err_code_t   gpgrt_b64dec_proc (gpgrt_b64state_t state,
1598                                     void *buffer, size_t length,
1599                                     size_t *r_nbytes);
1600 gpg_err_code_t   gpgrt_b64dec_finish (gpgrt_b64state_t state);
1601 
1602 
1603 
1604 /*
1605  * Simple string list
1606  */
1607 struct _gpgrt_strlist_s
1608 {
1609   struct _gpgrt_strlist_s *next;
1610   unsigned int flags;
1611   unsigned char _private_flags;  /* Not of your business.  */
1612   char d[1];
1613 };
1614 typedef struct _gpgrt_strlist_s *gpgrt_strlist_t;
1615 
1616 
1617 #define GPGRT_STRLIST_APPEND  1  /* Append and not prepend to the list. */
1618 #define GPGRT_STRLIST_WIPE    2  /* Wipe the string on free.  */
1619 
1620 
1621 /* Free the string list SL.  */
1622 void gpgrt_strlist_free (gpgrt_strlist_t sl);
1623 
1624 /* Add STRING to the LIST.  This function returns NULL and sets ERRNO
1625  * on memory shortage.  If STRING is NULL an empty string is stored
1626  * instead.  FLAGS */
1627 gpgrt_strlist_t gpgrt_strlist_add (gpgrt_strlist_t *list, const char *string,
1628                                    unsigned int flags);
1629 
1630 /* Tokenize STRING using the delimiters from DELIM and append each
1631  * token to the string list LIST.  On success a pointer into LIST with
1632  * the first new token is returned.  Returns NULL on error and sets
1633  * ERRNO.  Take care, an error with ENOENT set mean that no tokens
1634  * were found in STRING.  */
1635 gpgrt_strlist_t gpgrt_strlist_tokenize (gpgrt_strlist_t *list,
1636                                         const char *string,
1637                                         const char *delim, unsigned int flags);
1638 
1639 /* Return a copy of LIST.  On error ERRNO is set and NULL
1640  * returned.  */
1641 gpgrt_strlist_t gpgrt_strlist_copy (gpgrt_strlist_t list);
1642 
1643 /* Reverse the list *LIST in place.  Will not fail. */
1644 gpgrt_strlist_t gpgrt_strlist_rev (gpgrt_strlist_t *list);
1645 
1646 /* In the list starting with HEAD return the item previous to NODE.
1647  * Returns NULL if no previous item exists.  */
1648 gpgrt_strlist_t gpgrt_strlist_prev (gpgrt_strlist_t head, gpgrt_strlist_t node);
1649 
1650 /* Return the last item in the list starting at NODE.  */
1651 gpgrt_strlist_t gpgrt_strlist_last (gpgrt_strlist_t node);
1652 
1653 /* Remove the first item from LIST and return its content in an
1654  * allocated buffer.  This function returns NULl and sets ERRNO on
1655  * error.  */
1656 char *gpgrt_strlist_pop (gpgrt_strlist_t *list);
1657 
1658 /* Return the first item of the string list HAYSTACK whose value
1659  * matches NEEDLE.  If no items match, return NULL.  */
1660 gpgrt_strlist_t gpgrt_strlist_find (gpgrt_strlist_t haystack,
1661                                     const char *needle);
1662 
1663 /* Return the number of items in LIST.  */
1664 static GPG_ERR_INLINE unsigned int
1665 gpgrt_strlist_count (gpgrt_strlist_t list)
1666 {
1667   unsigned int i = 0;
1668 
1669   for (i = 0; list; list = list->next)
1670     i++;
1671 
1672   return i;
1673 }
1674 
1675 
1676 /*
1677  * Name-value parser and writer
1678  */
1679 
1680 struct _gpgrt_name_value_container;
1681 typedef struct _gpgrt_name_value_container *gpgrt_nvc_t;
1682 
1683 struct _gpgrt_name_value_entry;
1684 typedef struct _gpgrt_name_value_entry *gpgrt_nve_t;
1685 
1686 #define GPGRT_NVC_WIPE       2  /* Wipe the values on free.  */
1687 #define GPGRT_NVC_PRIVKEY    4  /* Enable private key mode.  */
1688 #define GPGRT_NVC_SECTION    8  /* Enable section mode.      */
1689 #define GPGRT_NVC_MODIFIED 256  /* Return the modified flag. */
1690 
1691 /* Return a name-value container according to the given flags.
1692  * Returns NULL and sets ERRNO on error.  */
1693 gpgrt_nvc_t gpgrt_nvc_new (unsigned int flags);
1694 
1695 /* Release a name-value container.  */
1696 void gpgrt_nvc_release (gpgrt_nvc_t cont);
1697 
1698 /* Return the specified container FLAG. For the GPGRT_NVC_MODIFIED
1699  * flag the CLEAR arg resets the flag after retrieval.  */
1700 int gpgrt_nvc_get_flag (gpgrt_nvc_t cont, unsigned int flag, int clear);
1701 
1702 /* Add (NAME, VALUE) to CONT.  If an entry with NAME already exists, a
1703  * new entry with that name is appended.  */
1704 gpg_err_code_t gpgrt_nvc_add (gpgrt_nvc_t cont,
1705                               const char *name, const char *value);
1706 
1707 /* Add (NAME, VALUE) to CONT.  If an entry with NAME already exists,
1708  * it is updated by VALUE.  If multiple entries with NAME exist, only
1709  * the first entry is updated.  */
1710 gpg_err_code_t gpgrt_nvc_set (gpgrt_nvc_t cont,
1711                               const char *name, const char *value);
1712 
1713 /* Update entry E to VALUE.  CONT is required to update the internal
1714  * modified flag and to pass container flags to the entry.  */
1715 gpg_err_code_t gpgrt_nve_set (gpgrt_nvc_t cont, gpgrt_nve_t e,
1716                               const char *value);
1717 
1718 /* Delete entries from the container CONT.  Either ENTRY or NAME must
1719  * be given.  If ENTRY is given only this entry is deleted; if NAME is
1720  * given all entries with this name are deleted.  */
1721 void gpgrt_nvc_delete (gpgrt_nvc_t cont, gpgrt_nve_t entry, const char *name);
1722 
1723 /* Get the first entry with the given name.  Return NULL if it does
1724  * not exist.  If NAME is NULL the first non-comment entry is
1725  * returned.  */
1726 gpgrt_nve_t gpgrt_nvc_lookup (gpgrt_nvc_t cont, const char *name);
1727 
1728 /* Parse STREAM and return a newly allocated container structure at
1729  * RESULT.  If ERRLINEP is given, the line number the parser was last
1730  * considering is stored there.  FLAGS are used to allocate the
1731  * container.  */
1732 gpg_err_code_t gpgrt_nvc_parse (gpgrt_nvc_t *result, int *errlinep,
1733                                 gpgrt_stream_t stream, unsigned int flags);
1734 
1735 /* Write a representation of the container CONT to STREAM.  */
1736 gpg_err_code_t gpgrt_nvc_write (gpgrt_nvc_t cont, gpgrt_stream_t stream);
1737 
1738 /* Return the next non-comment entry after ENTRY.  If NAME is given
1739  * the next entry with that name is returned.  */
1740 gpgrt_nve_t gpgrt_nve_next (gpgrt_nve_t entry, const char *name);
1741 
1742 /* Return the name of the entry.  */
1743 const char *gpgrt_nve_name (gpgrt_nve_t entry);
1744 
1745 /* Return the value of the entry.  */
1746 const char *gpgrt_nve_value (gpgrt_nve_t entry);
1747 
1748 /* Convenience function to return the string for the first entry of
1749  * CONT with NAME.  If no such entry is found or its value is the
1750  * empty string NULL is returned.  */
1751 const char *gpgrt_nvc_get_string (gpgrt_nvc_t cont, const char *name);
1752 
1753 /* Convenience function to return true if NAME exists and its value is
1754  * true; that is either "yes", "true", or a decimal value != 0.  */
1755 int gpgrt_nvc_get_bool (gpgrt_nvc_t nvc, const char *name);
1756 
1757 
1758 
1759 /*
1760  * Logging functions
1761  */
1762 
1763 /* Flag values for gpgrt_log_set_prefix. */
1764 #define GPGRT_LOG_WITH_PREFIX  1
1765 #define GPGRT_LOG_WITH_TIME    2
1766 #define GPGRT_LOG_WITH_PID     4
1767 #define GPGRT_LOG_RUN_DETACHED 256
1768 #define GPGRT_LOG_NO_REGISTRY  512
1769 
1770 /* Log levels as used by gpgrt_log.  */
1771 enum gpgrt_log_levels
1772   {
1773     GPGRT_LOGLVL_BEGIN,
1774     GPGRT_LOGLVL_CONT,
1775     GPGRT_LOGLVL_INFO,
1776     GPGRT_LOGLVL_WARN,
1777     GPGRT_LOGLVL_ERROR,
1778     GPGRT_LOGLVL_FATAL,
1779     GPGRT_LOGLVL_BUG,
1780     GPGRT_LOGLVL_DEBUG
1781   };
1782 
1783 
1784 /* The next 5 functions are not thread-safe - call them early.  */
1785 void gpgrt_log_set_sink (const char *name, gpgrt_stream_t stream, int fd);
1786 void gpgrt_log_set_socket_dir_cb (const char *(*fnc)(void));
1787 void gpgrt_log_set_pid_suffix_cb (int (*cb)(unsigned long *r_value));
1788 void gpgrt_log_set_prefix (const char *text, unsigned int flags);
1789 void gpgrt_add_post_log_func (void (*f)(int));
1790 
1791 int  gpgrt_get_errorcount (int clear);
1792 void gpgrt_inc_errorcount (void);
1793 const char *gpgrt_log_get_prefix (unsigned int *flags);
1794 int  gpgrt_log_test_fd (int fd);
1795 int  gpgrt_log_get_fd (void);
1796 gpgrt_stream_t gpgrt_log_get_stream (void);
1797 
1798 void gpgrt_log (int level, const char *fmt, ...) GPGRT_ATTR_PRINTF(2,3);
1799 void gpgrt_logv (int level, const char *fmt,
1800                  va_list arg_ptr) GPGRT_ATTR_PRINTF(2,0);
1801 void gpgrt_logv_prefix (int level, const char *prefix, const char *fmt,
1802                         va_list arg_ptr) GPGRT_ATTR_PRINTF(3,0);
1803 void gpgrt_logv_domain (const char *domain, int level, const char *prefix,
1804                         const void *buffer, size_t length, const char *fmt,
1805                         va_list arg_ptr) GPGRT_ATTR_PRINTF(6,0);
1806 void gpgrt_log_string (int level, const char *string);
1807 void gpgrt_log_bug (const char *fmt, ...)    GPGRT_ATTR_NR_PRINTF(1,2);
1808 void gpgrt_log_fatal (const char *fmt, ...)  GPGRT_ATTR_NR_PRINTF(1,2);
1809 void gpgrt_log_error (const char *fmt, ...)  GPGRT_ATTR_PRINTF(1,2);
1810 void gpgrt_log_info (const char *fmt, ...)   GPGRT_ATTR_PRINTF(1,2);
1811 void gpgrt_log_debug (const char *fmt, ...)  GPGRT_ATTR_PRINTF(1,2);
1812 void gpgrt_log_debug_string (const char *string,
1813                              const char *fmt, ...) GPGRT_ATTR_PRINTF(2,3);
1814 void gpgrt_log_printf (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
1815 void gpgrt_log_printhex (const void *buffer, size_t length,
1816                          const char *fmt, ...) GPGRT_ATTR_PRINTF(3,4);
1817 void gpgrt_log_clock (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
1818 void gpgrt_log_flush (void);
1819 void _gpgrt_log_assert (const char *expr, const char *file, int line,
1820                         const char *func) GPGRT_ATTR_NORETURN;
1821 
1822 #ifdef GPGRT_HAVE_MACRO_FUNCTION
1823 # define gpgrt_assert(expr)                                     \
1824   ((expr)                                                       \
1825    ? (void) 0                                                   \
1826    : _gpgrt_log_assert (#expr, __FILE__, __LINE__, __FUNCTION__))
1827 #else /*!GPGRT_HAVE_MACRO_FUNCTION*/
1828 # define gpgrt_assert(expr)                                     \
1829   ((expr)                                                       \
1830    ? (void) 0                                                   \
1831    : _gpgrt_log_assert (#expr, __FILE__, __LINE__, NULL))
1832 #endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
1833 
1834 #ifdef GPGRT_ENABLE_LOG_MACROS
1835 # define log_get_errorcount      gpgrt_get_errorcount
1836 # define log_inc_errorcount      gpgrt_inc_errorcount
1837 # define log_set_file(a)         gpgrt_log_set_sink ((a), NULL, -1)
1838 # define log_set_fd(a)           gpgrt_log_set_sink (NULL, NULL, (a))
1839 # define log_set_stream(a)       gpgrt_log_set_sink (NULL, (a), -1)
1840 # define log_set_socket_dir_cb   gpgrt_log_set_socket_dir_cb
1841 # define log_set_pid_suffix_cb   gpgrt_log_set_pid_suffix_cb
1842 # define log_set_prefix          gpgrt_log_set_prefix
1843 # define log_get_prefix          gpgrt_log_get_prefix
1844 # define log_test_fd             gpgrt_log_test_fd
1845 # define log_get_fd              gpgrt_log_get_fd
1846 # define log_get_stream          gpgrt_log_get_stream
1847 # define log_log                 gpgrt_log
1848 # define log_logv                gpgrt_logv
1849 # define log_logv_prefix         gpgrt_logv_prefix
1850 # define log_string              gpgrt_log_string
1851 # define log_bug                 gpgrt_log_bug
1852 # define log_fatal               gpgrt_log_fatal
1853 # define log_error               gpgrt_log_error
1854 # define log_info                gpgrt_log_info
1855 # define log_debug               gpgrt_log_debug
1856 # define log_debug_string        gpgrt_log_debug_string
1857 # define log_printf              gpgrt_log_printf
1858 # define log_printhex            gpgrt_log_printhex
1859 # define log_clock               gpgrt_log_clock
1860 # define log_flush               gpgrt_log_flush
1861 # ifdef GPGRT_HAVE_MACRO_FUNCTION
1862 #  define log_assert(expr)                                      \
1863   ((expr)                                                       \
1864    ? (void) 0                                                   \
1865    : _gpgrt_log_assert (#expr, __FILE__, __LINE__, __FUNCTION__))
1866 # else /*!GPGRT_HAVE_MACRO_FUNCTION*/
1867 #  define log_assert(expr)                                      \
1868   ((expr)                                                       \
1869    ? (void) 0                                                   \
1870    : _gpgrt_log_assert (#expr, __FILE__, __LINE__, NULL))
1871 # endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
1872 
1873 #endif /*GPGRT_ENABLE_LOG_MACROS*/
1874 
1875 
1876 /*
1877  * Spawn functions
1878  */
1879 /* Child process is detached to parent process.  */
1880 #define GPGRT_PROCESS_DETACHED            (1 << 1)
1881 
1882 /* Child process has no console (Windows only).  */
1883 #define GPGRT_PROCESS_NO_CONSOLE          (1 << 2)
1884 
1885 /* Allow a detached process with uid != euid (Posix only).  */
1886 #define GPGRT_PROCESS_NO_EUID_CHECK       (1 << 3)
1887 
1888 /* Allow the child process to set the foreground window (Windows only).  */
1889 #define GPGRT_PROCESS_ALLOW_SET_FG        (1 << 4)
1890 
1891 /* Specify how to keep/connect standard fds.  */
1892 #define GPGRT_PROCESS_STDIN_PIPE          (1 << 8)
1893 #define GPGRT_PROCESS_STDOUT_PIPE         (1 << 9)
1894 #define GPGRT_PROCESS_STDERR_PIPE         (1 << 10)
1895 #define GPGRT_PROCESS_STDINOUT_SOCKETPAIR (1 << 11)
1896 #define GPGRT_PROCESS_STDIN_KEEP          (1 << 12)
1897 #define GPGRT_PROCESS_STDOUT_KEEP         (1 << 13)
1898 #define GPGRT_PROCESS_STDERR_KEEP         (1 << 14)
1899 #define GPGRT_PROCESS_STDFDS_SETTING  ( GPGRT_PROCESS_STDIN_PIPE  \
1900   | GPGRT_PROCESS_STDOUT_PIPE         | GPGRT_PROCESS_STDERR_PIPE \
1901   | GPGRT_PROCESS_STDINOUT_SOCKETPAIR | GPGRT_PROCESS_STDIN_KEEP  \
1902   | GPGRT_PROCESS_STDOUT_KEEP         | GPGRT_PROCESS_STDERR_KEEP)
1903 
1904 #define GPGRT_PROCESS_STREAM_NONBLOCK     (1 << 16)
1905 
1906 typedef struct gpgrt_process *gpgrt_process_t;
1907 typedef struct gpgrt_spawn_actions *gpgrt_spawn_actions_t;
1908 gpg_err_code_t gpgrt_spawn_actions_new (gpgrt_spawn_actions_t *r_act);
1909 void gpgrt_spawn_actions_release (gpgrt_spawn_actions_t act);
1910 void gpgrt_spawn_actions_set_env_rev (gpgrt_spawn_actions_t,
1911                                       const char *const*);
1912 void gpgrt_spawn_actions_set_environ (gpgrt_spawn_actions_t, char **);
1913 void gpgrt_spawn_actions_set_redirect (gpgrt_spawn_actions_t, int, int, int);
1914 void gpgrt_spawn_actions_set_inherit_fds (gpgrt_spawn_actions_t, const int *);
1915 void gpgrt_spawn_actions_set_atfork (gpgrt_spawn_actions_t, void (*)(void *), void *);
1916 
1917 enum gpgrt_process_requests
1918   {
1919     /* Portable requests */
1920     GPGRT_PROCESS_NOP           = 0,
1921     GPGRT_PROCESS_GET_PROC_ID   = 1,
1922     GPGRT_PROCESS_GET_EXIT_ID   = 2,
1923 
1924     /* POSIX only */
1925     GPGRT_PROCESS_GET_PID       = 16,
1926     GPGRT_PROCESS_GET_WSTATUS   = 17,
1927     GPGRT_PROCESS_KILL          = 18,
1928 
1929     /* Windows only */
1930     GPGRT_PROCESS_GET_P_HANDLE  = 32,
1931     GPGRT_PROCESS_GET_HANDLES   = 33,
1932     GPGRT_PROCESS_GET_EXIT_CODE = 34,
1933     GPGRT_PROCESS_KILL_WITH_EC  = 35
1934   };
1935 
1936 #if 0
1937 /* Function and convenience macros to create pipes.  */
1938 gpg_err_code_t gpgrt_make_pipe (int filedes[2], gpgrt_stream_t *r_fp,
1939                                 int direction, int nonblock);
1940 #define gpgrt_create_pipe(a)              gpgrt_make_pipe ((a),NULL,  0,  0);
1941 #define gpgrt_create_inbound_pipe(a,b,c)  gpgrt_make_pipe ((a), (b), -1,(c));
1942 #define gpgrt_create_outbound_pipe(a,b,c) gpgrt_make_pipe ((a), (b),  1,(c));
1943 
1944 /* Close all file resources (descriptors), except KEEP_FDS. */
1945 void gpgrt_close_all_fds (int from, int *keep_fds);
1946 #endif /*0*/
1947 
1948 gpg_err_code_t gpgrt_process_spawn (const char *pgmname, const char *argv1[],
1949                                     unsigned int flags,
1950                                     gpgrt_spawn_actions_t act,
1951                                     gpgrt_process_t *r_process);
1952 
1953 gpg_err_code_t gpgrt_process_terminate (gpgrt_process_t process);
1954 
1955 gpg_err_code_t gpgrt_process_get_fds (gpgrt_process_t process,
1956                                       unsigned int flags,
1957                                       int *r_fd_in, int *r_fd_out,
1958                                       int *r_fd_err);
1959 
1960 gpg_err_code_t gpgrt_process_get_streams (gpgrt_process_t process,
1961                                           unsigned int flags,
1962                                           gpgrt_stream_t *r_fp_in,
1963                                           gpgrt_stream_t *r_fp_out,
1964                                           gpgrt_stream_t *r_fp_err);
1965 
1966 gpg_err_code_t gpgrt_process_ctl (gpgrt_process_t process,
1967                                   unsigned int request, ...);
1968 
1969 gpg_err_code_t gpgrt_process_wait (gpgrt_process_t process, int hang);
1970 
1971 void gpgrt_process_release (gpgrt_process_t process);
1972 
1973 /*
1974  * Option parsing.
1975  */
1976 
1977 struct _gpgrt_argparse_internal_s;
1978 typedef struct
1979 {
1980   int  *argc;         /* Pointer to ARGC (value subject to change). */
1981   char ***argv;       /* Pointer to ARGV (value subject to change). */
1982   unsigned int flags; /* Global flags.  May be set prior to calling the
1983                          parser.  The parser may change the value.  */
1984   int err;            /* Print error description for last option.
1985                          Either 0,  ARGPARSE_PRINT_WARNING or
1986                          ARGPARSE_PRINT_ERROR.  */
1987   unsigned int lineno;/* The current line number.  */
1988   int r_opt;          /* Returns option code. */
1989   int r_type;         /* Returns type of option value.  */
1990   union {
1991     int   ret_int;
1992     long  ret_long;
1993     unsigned long ret_ulong;
1994     char *ret_str;
1995   } r;            /* Return values */
1996 
1997   struct _gpgrt_argparse_internal_s *internal;
1998 } gpgrt_argparse_t;
1999 
2000 
2001 typedef struct
2002 {
2003   int          short_opt;
2004   const char  *long_opt;
2005   unsigned int flags;
2006   const char  *description; /* Optional description. */
2007 } gpgrt_opt_t;
2008 
2009 
2010 #ifdef GPGRT_ENABLE_ARGPARSE_MACROS
2011 
2012 /* Global flags for (gpgrt_argparse_t).flags.  */
2013 #define ARGPARSE_FLAG_KEEP        1  /* Do not remove options form argv.     */
2014 #define ARGPARSE_FLAG_ALL         2  /* Do not stop at last option but return
2015                                         remaining args with R_OPT set to -1. */
2016 #define ARGPARSE_FLAG_MIXED       4  /* Assume options and args are mixed.   */
2017 #define ARGPARSE_FLAG_NOSTOP      8  /* Do not stop processing at "--".      */
2018 #define ARGPARSE_FLAG_ARG0       16  /* Do not skip the first arg.           */
2019 #define ARGPARSE_FLAG_ONEDASH    32  /* Allow long options with one dash.    */
2020 #define ARGPARSE_FLAG_NOVERSION  64  /* No output for "--version".           */
2021 #define ARGPARSE_FLAG_RESET     128  /* Request to reset the internal state. */
2022 #define ARGPARSE_FLAG_STOP_SEEN 256  /* Set to true if a "--" has been seen. */
2023 #define ARGPARSE_FLAG_NOLINENO  512  /* Do not zero the lineno field.        */
2024 #define ARGPARSE_FLAG_SYS      1024  /* Use system config file.              */
2025 #define ARGPARSE_FLAG_USER     2048  /* Use user config file.                */
2026 #define ARGPARSE_FLAG_VERBOSE  4096  /* Print additional argparser info.     */
2027 #define ARGPARSE_FLAG_USERVERS 8192  /* Try version-ed user config files.    */
2028 #define ARGPARSE_FLAG_WITHATTR 16384 /* Return attribute bits.  (Make sure   */
2029                                      /* to act upon ARGPARSE_OPT_IGNORE.)    */
2030 #define ARGPARSE_FLAG_COMMAND  32768 /* Allow commands w/o leading dashes.   */
2031 
2032 
2033 /* Constants for (gpgrt_argparse_t).err.  */
2034 #define ARGPARSE_PRINT_WARNING  1    /* Print a diagnostic.                  */
2035 #define ARGPARSE_PRINT_ERROR    2    /* Print a diagnostic and call exit.    */
2036 
2037 /* Special return values of gpgrt_argparse.  */
2038 #define ARGPARSE_IS_ARG            (-1)
2039 #define ARGPARSE_INVALID_OPTION    (-2)
2040 #define ARGPARSE_MISSING_ARG       (-3)
2041 #define ARGPARSE_KEYWORD_TOO_LONG  (-4)
2042 #define ARGPARSE_READ_ERROR        (-5)
2043 #define ARGPARSE_UNEXPECTED_ARG    (-6)
2044 #define ARGPARSE_INVALID_COMMAND   (-7)
2045 #define ARGPARSE_AMBIGUOUS_OPTION  (-8)
2046 #define ARGPARSE_AMBIGUOUS_COMMAND (-9)
2047 #define ARGPARSE_INVALID_ALIAS     (-10)
2048 #define ARGPARSE_OUT_OF_CORE       (-11)
2049 #define ARGPARSE_INVALID_ARG       (-12)
2050 #define ARGPARSE_PERMISSION_ERROR  (-13)
2051 #define ARGPARSE_NO_CONFFILE       (-14)
2052 #define ARGPARSE_CONFFILE          (-15)
2053 #define ARGPARSE_INVALID_META      (-16)
2054 #define ARGPARSE_UNKNOWN_META      (-17)
2055 #define ARGPARSE_UNEXPECTED_META   (-18)
2056 
2057 /* Flags for the option descriptor (gpgrt_opt_t)->flags.  Note that a
2058  * TYPE constant may be or-ed with the OPT constants but when used as
2059  * return value in r_type these OPT constants are normally not
2060  * included.  However with ARGPARSE_FLAG_WITHATTR used and an option
2061  * would normally not be returned, it is returned but
2062  * ARGPARSE_OPT_IGNORE is then set; further ARPARSE_ATTR_* are set.
2063  */
2064 #define ARGPARSE_TYPE_MASK   0x0007  /* Mask for the type bits.           */
2065 #define ARGPARSE_TYPE_NONE        0  /* Does not take an argument.        */
2066 #define ARGPARSE_TYPE_INT         1  /* Takes an int argument.            */
2067 #define ARGPARSE_TYPE_STRING      2  /* Takes a string argument.          */
2068 #define ARGPARSE_TYPE_LONG        3  /* Takes a long argument.            */
2069 #define ARGPARSE_TYPE_ULONG       4  /* Takes an unsigned long argument.  */
2070 #define ARGPARSE_OPT_OPTIONAL (1<<3) /* Argument is optional.             */
2071 #define ARGPARSE_OPT_PREFIX   (1<<4) /* Allow 0x etc. prefixed values.    */
2072 #define ARGPARSE_OPT_IGNORE   (1<<6) /* Ignore command or option.         */
2073 #define ARGPARSE_OPT_COMMAND  (1<<7) /* The argument is a command.        */
2074 #define ARGPARSE_OPT_CONFFILE (1<<8) /* The value is a conffile.          */
2075 #define ARGPARSE_OPT_HEADER   (1<<9) /* The value is printed as a header. */
2076 #define ARGPARSE_OPT_VERBATIM (1<<10)/* The value is printed verbatim.    */
2077 #define ARGPARSE_ATTR_FORCE   (1<<14)/* Attribute force is set.           */
2078 #define ARGPARSE_ATTR_IGNORE  (1<<15)/* Attribute ignore is set.          */
2079 
2080 /* A set of macros to make option definitions easier to read.  */
2081 #define ARGPARSE_x(s,l,t,f,d) \
2082      { (s), (l), ARGPARSE_TYPE_ ## t | (f), (d) }
2083 
2084 #define ARGPARSE_s(s,l,t,d) \
2085      { (s), (l), ARGPARSE_TYPE_ ## t, (d) }
2086 #define ARGPARSE_s_n(s,l,d) \
2087      { (s), (l), ARGPARSE_TYPE_NONE, (d) }
2088 #define ARGPARSE_s_i(s,l,d) \
2089      { (s), (l), ARGPARSE_TYPE_INT, (d) }
2090 #define ARGPARSE_s_s(s,l,d) \
2091      { (s), (l), ARGPARSE_TYPE_STRING, (d) }
2092 #define ARGPARSE_s_l(s,l,d) \
2093      { (s), (l), ARGPARSE_TYPE_LONG, (d) }
2094 #define ARGPARSE_s_u(s,l,d) \
2095      { (s), (l), ARGPARSE_TYPE_ULONG, (d) }
2096 
2097 #define ARGPARSE_o(s,l,t,d) \
2098      { (s), (l), (ARGPARSE_TYPE_ ## t  | ARGPARSE_OPT_OPTIONAL), (d) }
2099 #define ARGPARSE_o_n(s,l,d) \
2100      { (s), (l), (ARGPARSE_TYPE_NONE   | ARGPARSE_OPT_OPTIONAL), (d) }
2101 #define ARGPARSE_o_i(s,l,d) \
2102      { (s), (l), (ARGPARSE_TYPE_INT    | ARGPARSE_OPT_OPTIONAL), (d) }
2103 #define ARGPARSE_o_s(s,l,d) \
2104      { (s), (l), (ARGPARSE_TYPE_STRING | ARGPARSE_OPT_OPTIONAL), (d) }
2105 #define ARGPARSE_o_l(s,l,d) \
2106      { (s), (l), (ARGPARSE_TYPE_LONG   | ARGPARSE_OPT_OPTIONAL), (d) }
2107 #define ARGPARSE_o_u(s,l,d) \
2108      { (s), (l), (ARGPARSE_TYPE_ULONG  | ARGPARSE_OPT_OPTIONAL), (d) }
2109 
2110 #define ARGPARSE_p(s,l,t,d) \
2111      { (s), (l), (ARGPARSE_TYPE_ ## t  | ARGPARSE_OPT_PREFIX), (d) }
2112 #define ARGPARSE_p_n(s,l,d) \
2113      { (s), (l), (ARGPARSE_TYPE_NONE   | ARGPARSE_OPT_PREFIX), (d) }
2114 #define ARGPARSE_p_i(s,l,d) \
2115      { (s), (l), (ARGPARSE_TYPE_INT    | ARGPARSE_OPT_PREFIX), (d) }
2116 #define ARGPARSE_p_s(s,l,d) \
2117      { (s), (l), (ARGPARSE_TYPE_STRING | ARGPARSE_OPT_PREFIX), (d) }
2118 #define ARGPARSE_p_l(s,l,d) \
2119      { (s), (l), (ARGPARSE_TYPE_LONG   | ARGPARSE_OPT_PREFIX), (d) }
2120 #define ARGPARSE_p_u(s,l,d) \
2121      { (s), (l), (ARGPARSE_TYPE_ULONG  | ARGPARSE_OPT_PREFIX), (d) }
2122 
2123 #define ARGPARSE_op(s,l,t,d) \
2124      { (s), (l), (ARGPARSE_TYPE_ ## t \
2125                   | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
2126 #define ARGPARSE_op_n(s,l,d) \
2127      { (s), (l), (ARGPARSE_TYPE_NONE \
2128                   | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
2129 #define ARGPARSE_op_i(s,l,d) \
2130      { (s), (l), (ARGPARSE_TYPE_INT \
2131                   | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
2132 #define ARGPARSE_op_s(s,l,d) \
2133      { (s), (l), (ARGPARSE_TYPE_STRING \
2134                   | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
2135 #define ARGPARSE_op_l(s,l,d) \
2136      { (s), (l), (ARGPARSE_TYPE_LONG \
2137                   | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
2138 #define ARGPARSE_op_u(s,l,d) \
2139      { (s), (l), (ARGPARSE_TYPE_ULONG \
2140                   | ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
2141 
2142 #define ARGPARSE_c(s,l,d) \
2143      { (s), (l), (ARGPARSE_TYPE_NONE | ARGPARSE_OPT_COMMAND), (d) }
2144 
2145 #define ARGPARSE_conffile(s,l,d) \
2146   { (s), (l), (ARGPARSE_TYPE_STRING|ARGPARSE_OPT_CONFFILE), (d) }
2147 
2148 #define ARGPARSE_noconffile(s,l,d) \
2149   { (s), (l), (ARGPARSE_TYPE_NONE|ARGPARSE_OPT_CONFFILE), (d) }
2150 
2151 /* This macro is for stub or obsolete options.  */
2152 #define ARGPARSE_ignore(s,l)                    \
2153   { (s), (l), (ARGPARSE_OPT_IGNORE), "@" }
2154 
2155 /* This is a legacy version of ARGPARSE_verbatim which really does
2156  * verbatim printing.  */
2157 #define ARGPARSE_group(s,d) \
2158   { (s), NULL, 0, (d) }
2159 
2160 /* Verbatim print the string D in the help output.  It does not make
2161  * use of the "@" hack as ARGPARSE_group does.  */
2162 #define ARGPARSE_verbatim(d) \
2163   { 1, NULL, (ARGPARSE_OPT_VERBATIM), (d) }
2164 
2165 /* Same as ARGPARSE_verbatim but also print a colon and a LF.  N can
2166  * be used give a symbolic name to the header.  Nothing is printed if
2167  * D is the empty string.  */
2168 #define ARGPARSE_header(n,d) \
2169   { 1, (n), (ARGPARSE_OPT_HEADER), (d) }
2170 
2171 /* Mark the end of the list (mandatory).  */
2172 #define ARGPARSE_end() \
2173   { 0, NULL, 0, NULL }
2174 
2175 #endif /* GPGRT_ENABLE_ARGPARSE_MACROS */
2176 
2177 /* Values used for gpgrt_set_confdir.  */
2178 #define GPGRT_CONFDIR_USER 1   /* The user's configuration dir.    */
2179 #define GPGRT_CONFDIR_SYS  2   /* The systems's configuration dir. */
2180 
2181 /* Take care: gpgrt_argparse keeps state in ARG and requires that
2182  * either ARGPARSE_FLAG_RESET is used after OPTS has been changed or
2183  * gpgrt_argparse (NULL, ARG, NULL) is called first.  */
2184 int gpgrt_argparse (gpgrt_stream_t fp,
2185                     gpgrt_argparse_t *arg, gpgrt_opt_t *opts);
2186 int gpgrt_argparser (gpgrt_argparse_t *arg, gpgrt_opt_t *opts,
2187                      const char *confname);
2188 void gpgrt_usage (int level);
2189 const char *gpgrt_strusage (int level);
2190 void gpgrt_set_strusage (const char *(*f)(int));
2191 void gpgrt_set_usage_outfnc (int (*f)(int, const char *));
2192 void gpgrt_set_fixed_string_mapper (const char *(*f)(const char*));
2193 void gpgrt_set_confdir (int what, const char *name);
2194 
2195 
2196 /*
2197  * Various helper functions
2198  */
2199 
2200 /* Compare arbitrary version strings.  For the standard m.n.o version
2201  * numbering scheme a LEVEL of 3 is suitable; see the manual.  */
2202 int gpgrt_cmp_version (const char *a, const char *b, int level);
2203 
2204 /* Construct a filename from the NULL terminated list of parts.  Tilde
2205  * expansion is done for the first argument.  The caller must release
2206  * the result using gpgrt_free; on error ERRNO is set and NULL
2207  * returned.  The second function returns an absolute filename.  */
2208 char *gpgrt_fnameconcat (const char *first, ...) GPGRT_ATTR_SENTINEL(0);
2209 char *gpgrt_absfnameconcat (const char *first, ...) GPGRT_ATTR_SENTINEL(0);
2210 
2211 
2212 #ifdef __cplusplus
2213 }
2214 #endif
2215 #endif  /* GPGRT_H */
2216 #endif  /* GPG_ERROR_H */
2217 /*
2218 Local Variables:
2219 buffer-read-only: t
2220 End:
2221 */