summaryrefslogtreecommitdiffstats
path: root/usr.bin/diff/diffreg.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2012-05-22 12:30:24 +0000
committermillert <millert@openbsd.org>2012-05-22 12:30:24 +0000
commit782453306cbb5c6a2b9a69d6f07600709ab921ee (patch)
treea89b4b940c595f842eef07e9bbc9793c69a9839a /usr.bin/diff/diffreg.c
parentSwitch all of the various choose- and list- commands over to the format (diff)
downloadwireguard-openbsd-782453306cbb5c6a2b9a69d6f07600709ab921ee.tar.xz
wireguard-openbsd-782453306cbb5c6a2b9a69d6f07600709ab921ee.zip
Strip trailing slashes from directory in splice() before
appending the file portion. OK krw@ matthew@
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r--usr.bin/diff/diffreg.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 328ce07dddd..80907aa5554 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.80 2011/04/01 17:25:26 nicm Exp $ */
+/* $OpenBSD: diffreg.c,v 1.81 2012/05/22 12:30:24 millert Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -536,12 +536,16 @@ char *
splice(char *dir, char *file)
{
char *tail, *buf;
+ size_t dirlen;
+ dirlen = strlen(dir);
+ while (dirlen != 0 && dir[dirlen - 1] == '/')
+ dirlen--;
if ((tail = strrchr(file, '/')) == NULL)
tail = file;
else
tail++;
- xasprintf(&buf, "%s/%s", dir, tail);
+ xasprintf(&buf, "%.*s/%s", (int)dirlen, dir, tail);
return (buf);
}