aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/pack
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2013-07-26 16:56:24 +1000
committerAlex Brainman <alex.brainman@gmail.com>2013-07-26 16:56:24 +1000
commita79e125b2f4c064f54689705fe2dd70899012df5 (patch)
tree8158c58c80c56ee79329912fe993b8abf4010c55 /src/cmd/pack
parent32a3ce67993fab5d0a46dd697d0fbd5b2c4e306e (diff)
downloadgo-a79e125b2f4c064f54689705fe2dd70899012df5.tar.gz
go-a79e125b2f4c064f54689705fe2dd70899012df5.zip
cmd/pack: support removing of leading file prefix on windows
Fixes #5550 R=golang-dev, r CC=golang-dev https://golang.org/cl/11904043
Diffstat (limited to 'src/cmd/pack')
-rw-r--r--src/cmd/pack/ar.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/cmd/pack/ar.c b/src/cmd/pack/ar.c
index 7053f841f3..284eff5ca5 100644
--- a/src/cmd/pack/ar.c
+++ b/src/cmd/pack/ar.c
@@ -1618,6 +1618,25 @@ int (*reader[256])(Biobuf*, Prog*) = {
[Obj386] = _read8,
};
+#define isdelim(c) ((c) == '/' || (c) == '\\')
+
+/*
+ * check if p is start of windows full path, like C:\ or c:/.
+ * return 1 if so. also set drive parameter to its
+ * upper-case drive letter.
+ */
+int
+iswinpathstart(char *p, char *drive)
+{
+ if('A' <= p[0] || p[0] <= 'Z')
+ *drive = p[0];
+ else if('a' <= p[0] || p[0] <= 'z')
+ *drive = p[0] - ('a' - 'A');
+ else
+ return 0;
+ return p[1] == ':' && isdelim(p[2]);
+}
+
/*
* copy b into bp->member but rewrite object
* during copy to drop prefix from all file names.
@@ -1630,7 +1649,7 @@ arread_cutprefix(Biobuf *b, Armember *bp)
vlong offset, o, end;
int n, t;
int (*rd)(Biobuf*, Prog*);
- char *w, *inprefix;
+ char *w, *inprefix, d1, d2;
Prog p;
offset = Boffset(b);
@@ -1666,12 +1685,15 @@ arread_cutprefix(Biobuf *b, Armember *bp)
if(inprefix == nil && prefix[0] == '/' && p.id[1] == '/' && p.id[2] == '\0') {
// leading /
inprefix = prefix+1;
+ } else if(inprefix == nil && iswinpathstart(prefix, &d1) && iswinpathstart(p.id + 1, &d2) && d1 == d2 && p.id[4] == '\0') {
+ // leading c:\ ...
+ inprefix = prefix+3;
} else if(inprefix != nil) {
// handle subsequent elements
n = strlen(p.id+1);
- if(strncmp(p.id+1, inprefix, n) == 0 && (inprefix[n] == '/' || inprefix[n] == '\0')) {
+ if(strncmp(p.id+1, inprefix, n) == 0 && (isdelim(inprefix[n]) || inprefix[n] == '\0')) {
inprefix += n;
- if(inprefix[0] == '/')
+ if(isdelim(inprefix[0]))
inprefix++;
}
}