tilde_expand
Leonard den Ottolander
leonard at den.ottolander.nl
Mon Sep 13 09:15:16 UTC 2004
Hi,
I wrote:
> Seeking a bit of basic advise. I was wondering if passwd gets freed in
> the next example (taken from src/utilunix.c), or whether it should be
> freed explicitly.
> return g_strconcat (passwd->pw_dir, PATH_SEP_STR, q, NULL);
> }
Well, explicitly g_freeing passwd causes a segfault, so I guess for some
reason it gets freed automatically. Anyone cares to explain?
However, there is a problem expanding ~username<dir> in that code, as
the result returns an extra slash. Fix below (only the q++ is
essential):
--- src/utilunix.c.000 2004-09-03 14:40:09.000000000 +0200
+++ src/utilunix.c 2004-09-13 01:47:35.000000000 +0200
@@ -270,18 +270,18 @@ tilde_expand (const char *directory)
p = directory + 1;
- q = strchr (p, PATH_SEP);
-
/* d = "~" or d = "~/" */
if (!(*p) || (*p == PATH_SEP)) {
passwd = getpwuid (geteuid ());
q = (*p == PATH_SEP) ? p + 1 : "";
} else {
+ q = strchr (p, PATH_SEP);
if (!q) {
passwd = getpwnam (p);
} else {
name = g_strndup (p, q - p);
passwd = getpwnam (name);
+ q++;
g_free (name);
}
}
Leonard.
--
mount -t life -o ro /dev/dna /genetic/research
More information about the mc-devel
mailing list