From 6a3decdc7cb62e64a66a863bce2090ffe61d43b1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 4 Dec 2010 19:08:23 +0200 Subject: [PATCH] * mu_util_dir_expand fix issue #30: wrong use of realpath(3) --- src/mu-util.c | 12 ++++++------ src/mu-util.h | 3 ++- src/tests/test-mu-util.c | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mu-util.c b/src/mu-util.c index 03640121..92ca0ad0 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -56,7 +56,7 @@ do_wordexp (const char *path) char *dir; if (!path) { - g_debug ("%s: path is empty", __FUNCTION__); + /* g_debug ("%s: path is empty", __FUNCTION__); */ return NULL; } @@ -87,17 +87,17 @@ mu_util_dir_expand (const char *path) { char *dir; char resolved[PATH_MAX + 1]; - + g_return_val_if_fail (path, NULL); dir = do_wordexp (path); if (!dir) return NULL; /* error */ - /* now, resolve any symlinks, .. etc. */ - if (!realpath (dir, resolved)) { - /* g_debug ("%s: could not get realpath for '%s': %s", */ - /* __FUNCTION__, dir, strerror(errno)); */ + /* now resolve any symlinks, .. etc. */ + if (realpath (dir, resolved) == NULL) { + g_debug ("%s: could not get realpath for '%s': %s", + __FUNCTION__, dir, strerror(errno)); g_free (dir); return NULL; } else diff --git a/src/mu-util.h b/src/mu-util.h index 06cf433a..ba106683 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -33,7 +33,8 @@ G_BEGIN_DECLS gboolean mu_util_init_system (void); /** - * get the expanded path; ie. perform shell expansion on the path + * get the expanded path; ie. perform shell expansion on the path. the + * path does not have to exist * * @param path path to expand * diff --git a/src/tests/test-mu-util.c b/src/tests/test-mu-util.c index 882e42ae..b93a9959 100644 --- a/src/tests/test-mu-util.c +++ b/src/tests/test-mu-util.c @@ -17,7 +17,7 @@ ** */ -#ifdef HAVE_CONFIG_H +#if HAVE_CONFIG_H #include "config.h" #endif /*HAVE_CONFIG_H*/ @@ -37,7 +37,7 @@ test_mu_util_dir_expand_01 (void) got = mu_util_dir_expand ("~/Desktop"); expected = g_strdup_printf ("%s%cDesktop", - getenv("HOME"), G_DIR_SEPARATOR); + getenv("HOME"), G_DIR_SEPARATOR); g_assert_cmpstr (got,==,expected);