|
|
0d20ef |
From 970ac8e8d3b4add1c31086f211b8796365287bbc Mon Sep 17 00:00:00 2001
|
|
|
0d20ef |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
0d20ef |
Date: Mon, 13 Oct 2014 16:49:59 +0200
|
|
|
0d20ef |
Subject: [PATCH] cat, diff: avoid double slashes in paths (RHBZ#1151910).
|
|
|
0d20ef |
|
|
|
0d20ef |
In full_path, skip the trailing slash in the base directory when
|
|
|
0d20ef |
different than "/", as the slash will eventually be added when building
|
|
|
0d20ef |
the resulting path.
|
|
|
0d20ef |
|
|
|
0d20ef |
(cherry picked from commit 87941d183f4a96b4d936c2e94a79a60288f0dc74)
|
|
|
0d20ef |
---
|
|
|
0d20ef |
cat/visit.c | 9 +++++++--
|
|
|
0d20ef |
1 file changed, 7 insertions(+), 2 deletions(-)
|
|
|
0d20ef |
|
|
|
0d20ef |
diff --git a/cat/visit.c b/cat/visit.c
|
|
|
0d20ef |
index 963beb8..49b779e 100644
|
|
|
0d20ef |
--- a/cat/visit.c
|
|
|
0d20ef |
+++ b/cat/visit.c
|
|
|
0d20ef |
@@ -138,13 +138,18 @@ full_path (const char *dir, const char *name)
|
|
|
0d20ef |
{
|
|
|
0d20ef |
int r;
|
|
|
0d20ef |
char *path;
|
|
|
0d20ef |
+ int len;
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ len = strlen (dir);
|
|
|
0d20ef |
+ if (len > 0 && dir[len - 1] == '/')
|
|
|
0d20ef |
+ --len;
|
|
|
0d20ef |
|
|
|
0d20ef |
if (STREQ (dir, "/"))
|
|
|
0d20ef |
r = asprintf (&path, "/%s", name ? name : "");
|
|
|
0d20ef |
else if (name)
|
|
|
0d20ef |
- r = asprintf (&path, "%s/%s", dir, name);
|
|
|
0d20ef |
+ r = asprintf (&path, "%.*s/%s", len, dir, name);
|
|
|
0d20ef |
else
|
|
|
0d20ef |
- r = asprintf (&path, "%s", dir);
|
|
|
0d20ef |
+ r = asprintf (&path, "%.*s", len, dir);
|
|
|
0d20ef |
|
|
|
0d20ef |
if (r == -1) {
|
|
|
0d20ef |
perror ("asprintf");
|
|
|
0d20ef |
--
|
|
|
0d20ef |
1.8.3.1
|
|
|
0d20ef |
|