]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: Reuse streq whenever possible.
authorThiago Fransosi Farina <thiago.farina@gmail.com>
Wed, 13 Aug 2014 13:47:30 +0000 (06:47 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 13 Aug 2014 13:47:30 +0000 (06:47 -0700)
Basically this cleanup replaces all the usage usages of strcmp() == 0,
found by the following command line:

$ grep -R strcmp cmd/dist | grep "0"

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/123330043

src/cmd/dist/plan9.c
src/cmd/dist/unix.c
src/cmd/dist/windows.c

index 8d492ebc67ca2d92330072a9bfe78f3a5b2517cd..e4bf2514753096862589d52c80fa6546df2535b6 100644 (file)
@@ -23,7 +23,7 @@ bprintf(Buf *b, char *fmt, ...)
 {
        va_list arg;
        char buf[4096];
-       
+
        breset(b);
        va_start(arg, fmt);
        vsnprintf(buf, sizeof buf, fmt, arg);
@@ -572,10 +572,10 @@ bool
 hassuffix(char *p, char *suffix)
 {
        int np, ns;
-       
+
        np = strlen(p);
        ns = strlen(suffix);
-       return np >= ns && strcmp(p+np-ns, suffix) == 0;
+       return np >= ns && streq(p+np-ns, suffix);
 }
 
 // hasprefix reports whether p begins with prefix.
index 8b943a2d9577a0eabf45c07dfe18b6b70e2cefa0..4a78684b44ad5cd46da1bcecf2214ebeab299767 100644 (file)
@@ -431,7 +431,7 @@ xremoveall(char *p)
        }
        
        bfree(&b);
-       vfree(&dir);    
+       vfree(&dir);
 }
 
 // xreaddir replaces dst with a list of the names of the files in dir.
@@ -441,13 +441,13 @@ xreaddir(Vec *dst, char *dir)
 {
        DIR *d;
        struct dirent *dp;
-       
+
        vreset(dst);
        d = opendir(dir);
        if(d == nil)
                fatal("opendir %s: %s", dir, strerror(errno));
        while((dp = readdir(d)) != nil) {
-               if(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
+               if(streq(dp->d_name, ".") || streq(dp->d_name, ".."))
                        continue;
                vadd(dst, dp->d_name);
        }
@@ -461,7 +461,7 @@ xworkdir(void)
 {
        Buf b;
        char *p;
-       
+
        binit(&b);
 
        xgetenv(&b, "TMPDIR");
@@ -546,10 +546,10 @@ bool
 hassuffix(char *p, char *suffix)
 {
        int np, ns;
-       
+
        np = strlen(p);
        ns = strlen(suffix);
-       return np >= ns && strcmp(p+np-ns, suffix) == 0;
+       return np >= ns && streq(p+np-ns, suffix);
 }
 
 // hasprefix reports whether p begins with prefix.
@@ -712,7 +712,7 @@ main(int argc, char **argv)
                        fatal("unknown architecture: %s", u.machine);
        }
 
-       if(strcmp(gohostarch, "arm") == 0)
+       if(streq(gohostarch, "arm"))
                maxnbg = 1;
 
        // The OS X 10.6 linker does not support external linking mode.
@@ -724,7 +724,7 @@ main(int argc, char **argv)
        //
        // Roughly, OS X 10.N shows up as uname release (N+4),
        // so OS X 10.6 is uname version 10 and OS X 10.8 is uname version 12.
-       if(strcmp(gohostos, "darwin") == 0) {
+       if(streq(gohostos, "darwin")) {
                if(uname(&u) < 0)
                        fatal("uname: %s", strerror(errno));
                osx = atoi(u.release) - 4;
index 2839c4bc5171efd69328ced26c763a086ff8419c..1102adff5e3831d823ccd7ef34e10d44a529c0b4 100644 (file)
@@ -770,10 +770,10 @@ bool
 hassuffix(char *p, char *suffix)
 {
        int np, ns;
-       
+
        np = strlen(p);
        ns = strlen(suffix);
-       return np >= ns && strcmp(p+np-ns, suffix) == 0;
+       return np >= ns && streq(p+np-ns, suffix);
 }
 
 bool