]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix islocalname on windows
authorRuss Cox <rsc@golang.org>
Tue, 27 Apr 2010 20:52:43 +0000 (13:52 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 27 Apr 2010 20:52:43 +0000 (13:52 -0700)
Fixes #732.

R=ken2
CC=golang-dev
https://golang.org/cl/956050

src/cmd/gc/go.h
src/cmd/gc/lex.c

index dabf5d3f5998edc81a1cfada2797640f2779ec93..8f7450ef480e4e42d601a448e6fcbb24a4c6682d 100644 (file)
@@ -1242,3 +1242,9 @@ int       duintxx(Sym *s, int off, uint64 v, int wid);
 void   genembedtramp(Type*, Type*, Sym*);
 int    gen_as_init(Node*);
 
+
+enum {
+       SysUnix = 1<<1,
+       SysWindows = 1<<2,
+};
+int    systemtype(int);
index 57d6e184d7f4b5d7b04850e5524ade672b2c9f6c..f6359da560010ea29bfd37fb40e6e0c17f01dfe2 100644 (file)
@@ -24,6 +24,7 @@ main(int argc, char *argv[])
 {
        int i, c;
        NodeList *l;
+       char *p;
 
        localpkg = mkpkg(strlit(""));
        localpkg->prefix = "\"\"";
@@ -80,6 +81,13 @@ main(int argc, char *argv[])
        if(getwd(pathname, 999) == 0)
                strcpy(pathname, "/???");
 
+       if(systemtype(SysWindows)) {
+               // Canonicalize path by converting \ to / (Windows accepts both).
+               for(p=pathname; *p; p++)
+                       if(*p == '\\')
+                               *p = '/';
+       }
+
        fmtinstall('O', Oconv);         // node opcodes
        fmtinstall('E', Econv);         // etype opcodes
        fmtinstall('J', Jconv);         // all the node flags
@@ -239,8 +247,11 @@ addidir(char* dir)
 int
 islocalname(Strlit *name)
 {
-       if(name->len >= 1 && name->s[0] == '/')
+       if(systemtype(SysUnix) && name->len >= 1 && name->s[0] == '/')
                return 1;
+       if(systemtype(SysWindows) && name->len >= 3 &&
+          isalpha(name->s[0]) && name->s[1] == ':' && name->s[2] == '/')
+               return 1;
        if(name->len >= 2 && strncmp(name->s, "./", 2) == 0)
                return 1;
        if(name->len >= 3 && strncmp(name->s, "../", 3) == 0)
@@ -1662,3 +1673,13 @@ mkpackage(char* pkgname)
                outfile = smprint("%s.%c", namebuf, thechar);
        }
 }
+
+int
+systemtype(int sys)
+{
+#ifdef __MINGW32__
+       return sys&SysWindows;
+#else
+       return sys&SysUnix;
+#endif
+}