summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2012-02-06 20:50:47 +0100
committerWerner Koch <wk@gnupg.org>2012-02-06 20:50:47 +0100
commiteb0faef81dae2cba1f62056fdc4dc2a7d58ac86a (patch)
tree7ada65b8c11f45aeb6beae3fce3959d4513c5ac3 /tools
parentAlso let GENKEY and PKDECRYPT send the INQUIRE_MAXLEN status message. (diff)
downloadgnupg2-eb0faef81dae2cba1f62056fdc4dc2a7d58ac86a.tar.xz
gnupg2-eb0faef81dae2cba1f62056fdc4dc2a7d58ac86a.zip
common: Add a global variable to for the default error source.
For the shared code parts it is cumbersome to pass an error sourse variable to each function. Its value is always a constant for a given binary and thus a global variable makes things a lot easier than the former macro stuff. * common/init.c (default_errsource): New global var. (init_common_subsystems): Rename to _init_common_subsystems. Set DEFAULT_ERRSOURCE. * common/init.h: Assert value of GPG_ERR_SOURCE_DEFAULT. (init_common_subsystems): New macro. * common/util.h (default_errsource): Add declaration. * kbx/keybox-defs.h: Add some GPG_ERR_SOURCE_DEFAULT trickery.
Diffstat (limited to 'tools')
-rw-r--r--tools/gpg-check-pattern.c37
-rw-r--r--tools/gpg-connect-agent.c1
-rw-r--r--tools/gpgconf.c2
-rw-r--r--tools/gpgtar.c15
-rw-r--r--tools/symcryptrun.c1
5 files changed, 31 insertions, 25 deletions
diff --git a/tools/gpg-check-pattern.c b/tools/gpg-check-pattern.c
index 42a6c62f0..e6b8b276b 100644
--- a/tools/gpg-check-pattern.c
+++ b/tools/gpg-check-pattern.c
@@ -45,9 +45,10 @@
#include "util.h"
#include "i18n.h"
#include "sysutils.h"
+#include "../common/init.h"
-enum cmd_and_opt_values
+enum cmd_and_opt_values
{ aNull = 0,
oVerbose = 'v',
oArmor = 'a',
@@ -66,12 +67,12 @@ enum cmd_and_opt_values
/* The list of commands and options. */
static ARGPARSE_OPTS opts[] = {
-
+
{ 301, NULL, 0, N_("@Options:\n ") },
{ oVerbose, "verbose", 0, "verbose" },
- { oHomedir, "homedir", 2, "@" },
+ { oHomedir, "homedir", 2, "@" },
{ oCheck, "check", 0, "run only a syntax check on the patternfile" },
{ oNull, "null", 0, "input is expected to be null delimited" },
@@ -80,7 +81,7 @@ static ARGPARSE_OPTS opts[] = {
/* Global options are accessed through the usual OPT structure. */
-static struct
+static struct
{
int verbose;
const char *homedir;
@@ -99,7 +100,7 @@ enum {
/* An object to decibe an item of our pattern table. */
struct pattern_s
{
- int type;
+ int type;
unsigned int lineno; /* Line number of the pattern file. */
union {
struct {
@@ -111,7 +112,7 @@ struct pattern_s
we need for PAT_STRING and we expect only a few regex in a
patternfile. It would be a waste of core to have so many
unused stuff in the table. */
- regex_t *regex;
+ regex_t *regex;
} r; /*PAT_REGEX*/
} u;
};
@@ -141,14 +142,14 @@ my_strusage (int level)
case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
case 1:
- case 40:
+ case 40:
p = _("Usage: gpg-check-pattern [options] patternfile (-h for help)\n");
break;
- case 41:
+ case 41:
p = _("Syntax: gpg-check-pattern [options] patternfile\n"
"Check a passphrase given on stdin against the patternfile\n");
break;
-
+
default: p = NULL;
}
return p;
@@ -165,7 +166,7 @@ main (int argc, char **argv )
set_strusage (my_strusage);
gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
- log_set_prefix ("gpg-check-pattern", 1);
+ log_set_prefix ("gpg-check-pattern", 1);
/* Make sure that our subsystems are ready. */
i18n_init ();
@@ -194,13 +195,13 @@ main (int argc, char **argv )
case oHomedir: opt.homedir = pargs.r.ret_str; break;
case oCheck: opt.checkonly = 1; break;
case oNull: opt.null = 1; break;
-
+
default : pargs.err = 2; break;
}
}
if (log_get_errorcount(0))
exit (2);
-
+
if (argc != 1)
usage (1);
@@ -239,7 +240,7 @@ read_file (const char *fname, size_t *r_length)
FILE *fp;
char *buf;
size_t buflen;
-
+
if (!strcmp (fname, "-"))
{
size_t nread, bufsize = 0;
@@ -251,7 +252,7 @@ read_file (const char *fname, size_t *r_length)
buf = NULL;
buflen = 0;
#define NCHUNK 8192
- do
+ do
{
bufsize += NCHUNK;
if (!buf)
@@ -282,14 +283,14 @@ read_file (const char *fname, size_t *r_length)
log_error ("can't open `%s': %s\n", fname, strerror (errno));
return NULL;
}
-
+
if (fstat (fileno(fp), &st))
{
log_error ("can't stat `%s': %s\n", fname, strerror (errno));
fclose (fp);
return NULL;
}
-
+
buflen = st.st_size;
buf = xmalloc (buflen+1);
if (fread (buf, buflen, 1, fp) != 1)
@@ -331,7 +332,7 @@ parse_pattern_file (char *data, size_t datalen)
pattern_t *array;
size_t arraysize, arrayidx;
unsigned int lineno = 0;
-
+
/* Estimate the number of entries by counting the non-comment lines. */
arraysize = 0;
p = data;
@@ -456,7 +457,7 @@ process (FILE *fp, pattern_t *patarray)
int c;
unsigned long lineno = 0;
pattern_t *pat;
-
+
idx = 0;
c = 0;
while (idx < sizeof buffer -1 && c != EOF )
diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c
index 7472728c6..d340c7f0e 100644
--- a/tools/gpg-connect-agent.c
+++ b/tools/gpg-connect-agent.c
@@ -37,6 +37,7 @@
#ifdef HAVE_W32_SYSTEM
# include "../common/exechelp.h"
#endif
+#include "../common/init.h"
#define CONTROL_D ('D' - 'A' + 1)
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index da10e4d73..cff6e4b3c 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -26,6 +26,8 @@
#include "gpgconf.h"
#include "i18n.h"
#include "sysutils.h"
+#include "../common/init.h"
+
/* Constants to identify the commands and options. */
enum cmd_and_opt_values
diff --git a/tools/gpgtar.c b/tools/gpgtar.c
index ace45c42d..b6dd5e10a 100644
--- a/tools/gpgtar.c
+++ b/tools/gpgtar.c
@@ -37,6 +37,7 @@
#include "i18n.h"
#include "sysutils.h"
#include "../common/openpgpdefs.h"
+#include "../common/init.h"
#include "gpgtar.h"
@@ -71,7 +72,7 @@ enum cmd_and_opt_values
/* The list of commands and options. */
static ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@Commands:\n ")),
-
+
ARGPARSE_c (aEncrypt, "encrypt", N_("create an archive")),
ARGPARSE_c (aDecrypt, "decrypt", N_("extract an archive")),
ARGPARSE_c (aSign, "sign", N_("create a signed archive")),
@@ -146,7 +147,7 @@ set_cmd (enum cmd_and_opt_values *ret_cmd, enum cmd_and_opt_values new_cmd)
cmd = aSignEncrypt;
else if (cmd == aEncrypt && new_cmd == aSign)
cmd = aSignEncrypt;
- else
+ else
{
log_error (_("conflicting commands\n"));
exit (2);
@@ -194,7 +195,7 @@ main (int argc, char **argv)
case oNoVerbose: opt.verbose = 0; break;
case oFilesFrom: files_from = pargs.r.ret_str; break;
case oNull: null_names = 1; break;
-
+
case aList:
case aDecrypt:
case aEncrypt:
@@ -217,7 +218,7 @@ main (int argc, char **argv)
default: pargs.err = 2; break;
}
}
-
+
if ((files_from && !null_names) || (!files_from && null_names))
log_error ("--files-from and --null may only be used in conjunction\n");
if (files_from && strcmp (files_from, "-"))
@@ -324,7 +325,7 @@ write_record (estream_t stream, const void *record)
}
else
err = 0;
-
+
return err;
}
@@ -341,9 +342,9 @@ openpgp_message_p (estream_t fp)
if (ctb != EOF)
{
if (es_ungetc (ctb, fp))
- log_fatal ("error ungetting first byte: %s\n",
+ log_fatal ("error ungetting first byte: %s\n",
gpg_strerror (gpg_error_from_syserror ()));
-
+
if ((ctb & 0x80))
{
switch ((ctb & 0x40) ? (ctb & 0x3f) : ((ctb>>2)&0xf))
diff --git a/tools/symcryptrun.c b/tools/symcryptrun.c
index c75f637e6..942fafa09 100644
--- a/tools/symcryptrun.c
+++ b/tools/symcryptrun.c
@@ -89,6 +89,7 @@
#define JNLIB_NEED_LOG_LOGV
#include "i18n.h"
#include "../common/util.h"
+#include "../common/init.h"
#include "mkdtemp.h"
/* FIXME: Bah. For spwq_secure_free. */