aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common/homedir.c32
-rw-r--r--common/util.h2
2 files changed, 33 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
diff --git a/common/util.h b/common/util.h
index 7634885e7..634ae06a9 100644
--- a/common/util.h
+++ b/common/util.h
@@ -220,6 +220,8 @@ const char *openpgp_is_curve_supported (const char *name, int *r_algo);
/*-- homedir.c --*/
const char *standard_homedir (void);
const char *default_homedir (void);
+void gnupg_set_homedir (const char *newdir);
+const char *gnupg_homedir (void);
const char *gnupg_sysconfdir (void);
const char *gnupg_bindir (void);
const char *gnupg_libexecdir (void);