diff options
author | Werner Koch <[email protected]> | 2016-06-07 08:59:46 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-06-07 08:59:46 +0000 |
commit | 22a7ef01aa2c0eb77bcc40174d09104acc35cab1 (patch) | |
tree | 3782b20549fcc48d2598128676227d9a16f785b6 /common/homedir.c | |
parent | po: Update Japanese translation. (diff) | |
download | gnupg-22a7ef01aa2c0eb77bcc40174d09104acc35cab1.tar.gz gnupg-22a7ef01aa2c0eb77bcc40174d09104acc35cab1.zip |
Replace use of opt.homedir by accessor functions.
* common/homedir.c (the_gnupg_homedir): New var.
(gnupg_set_homedir): New.
(gnupg_homedir): New.
* g10/options.h (struct opt): Remove 'homedir' and replace all users
by the new accessor functions.
* g13/g13-common.h (struct opt): Ditto.
* scd/scdaemon.h (struct opt): Ditto.
* sm/gpgsm.h (struct opt): Ditto.
* dirmngr/dirmngr.h (struct opt): Ditto.
* agent/preset-passphrase.c (opt_homedir): Ditto.
* agent/protect-tool.c (opt_homedir): Ditto.
--
This will make detection of a non-default homedir easier.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/homedir.c')
-rw-r--r-- | common/homedir.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/common/homedir.c b/common/homedir.c index 5bf517360..eccffeccf 100644 --- a/common/homedir.c +++ b/common/homedir.c @@ -1,6 +1,6 @@ /* homedir.c - Setup the home directory. * Copyright (C) 2004, 2006, 2007, 2010 Free Software Foundation, Inc. - * Copyright (C) 2013 Werner Koch + * Copyright (C) 2013, 2016 Werner Koch * * This file is part of GnuPG. * @@ -58,6 +58,12 @@ #include "util.h" #include "sysutils.h" + +/* The GnuPG homedir. This is only accessed by the functions + * gnupg_homedir and gnupg_set_homedir. Malloced. */ +static char *the_gnupg_homedir; + + #ifdef HAVE_W32_SYSTEM /* A flag used to indicate that a control file for gpgconf has been detected. Under Windows the presence of this file indicates a @@ -368,6 +374,30 @@ w32_commondir (void) #endif /*HAVE_W32_SYSTEM*/ +/* Change the homedir. Some care must be taken to set this early + * enough becuase previous calls to gnupg_homedir may else return a + * different string. */ +void +gnupg_set_homedir (const char *newdir) +{ + if (!newdir || !*newdir) + newdir = default_homedir (); + xfree (the_gnupg_homedir); + the_gnupg_homedir = xstrdup (newdir); +} + + +/* Return the homedir. The returned string is valid until another + * gnupg-set-homedir call. Note that this may be a relative string. + * This function replaced the former global opt.homedir. */ +const char * +gnupg_homedir (void) +{ + /* If a homedir has not been set, set it to the default. */ + if (!the_gnupg_homedir) + the_gnupg_homedir = xstrdup (default_homedir ()); + return the_gnupg_homedir; +} /* Return the name of the sysconfdir. This is a static string. This |