Hmm. After a quick read of the glib docs, I'd agree with you about the
$HOME variable, which is a fallback if glib can't work out the home
directory from /etc/passwd or similar. I've amended the patch slightly
below, to use g_getenv() as you suggest, and to g_strdup() the result
before assigning to dotgnucash. This should have the double effect of
a) Having a string that's safe to g_free() -- though I'm not sure it
will be, as dotgnucash is a static variable. Better to be safe though.
b) Having a string that won't mutate next time someone calls
g_[get|set|unset]env()
James
Christian Stimming wrote:
Am Mittwoch, 21. März 2007 09:53 schrieb Derek Atkins:
Why not just run:
HOME=... gnucash
??? Or does this no longer work now that we've changed to
g_get_home_dir()?
According to the documentation of g_get_home_dir, this does *not* work any
longer. I think this is a good extension.
@James: The patch looks fine, except that you should use g_getenv instead of
getenv (and IIRC there were some reversed semantics when changing from one
such call to the other). Also, the result of g_build_filename is owned by the
caller and will be freed later, and I'm not so sure whether this is correct
for a string that was retrieved from getenv/g_getenv.
Thanks for the contribution in any case,
Christian
Index: src/engine/gnc-filepath-utils.c
===================================================================
--- src/engine/gnc-filepath-utils.c (revision 15738)
+++ src/engine/gnc-filepath-utils.c (working copy)
@@ -382,14 +382,17 @@
if (dotgnucash)
return dotgnucash;
- home = g_get_home_dir();
- if (!home) {
- g_warning("Cannot find home directory. Using tmp directory instead.");
- home = g_get_tmp_dir();
+ dotgnucash = g_strdup(g_getenv("GNC_DOT_DIR"));
+ if(!dotgnucash) {
+ home = g_get_home_dir();
+ if (!home) {
+ g_warning("Cannot find home directory. Using tmp directory
instead.");
+ home = g_get_tmp_dir();
+ }
+ g_assert(home);
+
+ dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
}
- g_assert(home);
-
- dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
gnc_validate_directory(dotgnucash);
/* Since we're in code that is only executed once.... */
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel