]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed fetch command
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 28 Oct 2019 13:57:06 +0000 (09:57 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 28 Oct 2019 13:57:06 +0000 (09:57 -0400)
src/fetch.c

index d217489099bfc2657a64d417056fc816f22145b7..f1b77c995765909d771fad9269b0a4c1e507641b 100644 (file)
@@ -40,7 +40,7 @@ char* eval(char* str)
 
     regmatch_t matches[2] = {{0},{0}};
     int result = regexec(&regex, str, nelem(matches), matches, 0);
-    if ((result == 0) && (matches[1].rm_so > 0))
+    if (result >= 0 && matches[1].rm_so > 0)
     {
         char* var = strndup(str+matches[1].rm_so, matches[1].rm_eo-matches[1].rm_so);
         char* val = getvar(var);
@@ -97,9 +97,10 @@ bool var_isdir(char* var)
     bool ret = false;
     struct stat st = {0};
     char* path = eval(var);
-    if (!stat(path, &st) && !errno && S_ISDIR(st.st_mode))
+    bool exists = (stat(eval(var), &st) >= 0);
+    if (exists && S_ISDIR(st.st_mode))
     {
-        setenv("dir", var, 1);
+        setenv("dir", path, 1);
         ret = true;
     }
     return ret;
@@ -110,7 +111,8 @@ bool var_isfile(char* var)
     bool ret = false;
     struct stat st = {0};
     char* path = eval(var);
-    if (!stat(eval(var), &st) && !errno && !S_ISDIR(st.st_mode))
+    bool exists = (stat(eval(var), &st) >= 0);
+    if (exists && !S_ISDIR(st.st_mode))
     {
         setenv("file", path, 1);
         ret = true;
@@ -149,13 +151,13 @@ bool exec(char* cmd)
     {
         if (pid == 0)
         {
-            runcmd(cmd);
+        runcmd(cmd);
         }
         else
         {
-            waitpid(pid, &status, 0);
+        waitpid(pid, &status, 0);
             ret = (status == 0);
-        }
+    }
     }
     return ret;
 }