summaryrefslogtreecommitdiff
path: root/common/strutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/strutils.c')
-rw-r--r--common/strutils.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/common/strutils.c b/common/strutils.c
index 5d9fa65..47494de 100644
--- a/common/strutils.c
+++ b/common/strutils.c
@@ -100,15 +100,16 @@ char* extract_file_path(const char *APath)
// canonicalize_filename() is stolen from glib-2.16
// Copyright (C) 2006-2007 Alexander Larsson <alexl@redhat.com>
-static char *
+char *
canonicalize_filename (const char *filename)
{
char *canon, *start, *p, *q;
int i;
-
+
canon = g_strdup (filename);
start = (char *)g_path_skip_root (canon);
+ if (start == NULL) start = canon;
/* POSIX allows double slashes at the start to
* mean something special (as does windows too).
@@ -127,7 +128,7 @@ canonicalize_filename (const char *filename)
start -= i;
memmove (start, start+i, strlen (start+i)+1);
}
-
+
p = start;
while (*p != 0)
{
@@ -153,7 +154,7 @@ canonicalize_filename (const char *filename)
/* Skip until next separator */
while (*p != 0 && !G_IS_DIR_SEPARATOR (*p))
p++;
-
+
if (*p != 0)
{
/* Canonicalize one separator */
@@ -173,7 +174,7 @@ canonicalize_filename (const char *filename)
/* Remove trailing slashes */
if (p > start && G_IS_DIR_SEPARATOR (*(p-1)))
*(p-1) = 0;
-
+
return canon;
}
@@ -183,12 +184,12 @@ char* resolve_relative(const char *source, const char *point_to)
if (source == NULL) return NULL;
if (point_to == NULL) return strdup(source);
if (g_path_is_absolute(point_to)) return strdup(point_to);
-
+
char *rel = g_build_filename(source, point_to, NULL);
log("resolve_relative: rel = '%s'\n", rel);
char *canon = canonicalize_filename(rel);
log("resolve_relative: canon = '%s'\n", canon);
free(rel);
-
- return canon;
+
+ return canon;
}