Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-17 08:27:10

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