summaryrefslogtreecommitdiffstats
path: root/lib/canonicalize.c
diff options
context:
space:
mode:
authorKarel Zak2012-02-24 21:26:11 +0100
committerKarel Zak2012-02-24 21:26:11 +0100
commit28074a0952469aebf021821d95238cfb964d13ff (patch)
treef911c80ebe93c0555437dbeff2b996c4b4360b78 /lib/canonicalize.c
parenttests: test non-canonical paths in fstab (diff)
downloadkernel-qcow2-util-linux-28074a0952469aebf021821d95238cfb964d13ff.tar.gz
kernel-qcow2-util-linux-28074a0952469aebf021821d95238cfb964d13ff.tar.xz
kernel-qcow2-util-linux-28074a0952469aebf021821d95238cfb964d13ff.zip
lib/canonicalize: always remove tailing slash
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/canonicalize.c')
-rw-r--r--lib/canonicalize.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index ab32c1043..fd18af42c 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -174,9 +174,16 @@ canonicalize_path(const char *path)
if (path == NULL)
return NULL;
- if (!myrealpath(path, canonical, PATH_MAX+1))
- return strdup(path);
-
+ if (!myrealpath(path, canonical, PATH_MAX+1)) {
+ char *res = strdup(path);
+ if (res) {
+ p = strrchr(res, '/');
+ /* delete trailing slash */
+ if (p && p > res && *(p + 1) == '\0')
+ *p = '\0';
+ }
+ return res;
+ }
p = strrchr(canonical, '/');
if (p && strncmp(p, "/dm-", 4) == 0 && isdigit(*(p + 4))) {