diff options
author | Colin Walters <walters@verbum.org> | 2013-09-13 16:40:07 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-09-13 16:40:07 -0400 |
commit | 34fc4d48819574345d87ba3005211091250f4369 (patch) | |
tree | 7a2025da20c899cf032b0977dad77be9e5c94a1f | |
parent | c72d84a0a9edcccb366ba41b74e7a41a6d625ab1 (diff) | |
download | libgsystem-34fc4d48819574345d87ba3005211091250f4369.tar.gz |
fileutils: Avoid crash if g_set_prgname() has not been called
While we're here, also squash spaces in the filename to '_'.
-rw-r--r-- | gsystem-file-utils.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index e23f17e..6c70594 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -444,12 +444,24 @@ get_default_tmp_prefix (void) const char *prgname = g_get_prgname (); const char *p; char *prefix; + char *iter; - p = strrchr (prgname, '/'); - if (p) - prgname = p + 1; - + if (prgname) + { + p = strrchr (prgname, '/'); + if (p) + prgname = p + 1; + } + else + prgname = ""; + prefix = g_strdup_printf ("tmp-%s%u-", prgname, getuid ()); + for (iter = prefix; *iter; iter++) + { + char c = *iter; + if (c == ' ') + *iter = '_'; + } g_once_init_leave (&tmpprefix, prefix); } |