Browse Source

IS_DIR should not crash if the file does not exist

rexim 4 years ago
parent
commit
6ff8d06c93
2 changed files with 6 additions and 1 deletions
  1. 1 0
      examples/file.c
  2. 5 1
      nobuild.h

+ 1 - 0
examples/file.c

@@ -8,5 +8,6 @@ int main(int argc, char *argv[])
 {
 {
     DEMO(IS_DIR("./nobuild.c"));
     DEMO(IS_DIR("./nobuild.c"));
     DEMO(IS_DIR("./examples"));
     DEMO(IS_DIR("./examples"));
+    DEMO(IS_DIR("./file_that_does_not_exist"));
     return 0;
     return 0;
 }
 }

+ 5 - 1
nobuild.h

@@ -599,7 +599,11 @@ int nobuild__is_dir(const char *path)
 #else
 #else
     struct stat statbuf = {0};
     struct stat statbuf = {0};
     if (stat(path, &statbuf) < 0) {
     if (stat(path, &statbuf) < 0) {
-        ERRO("could not retrieve information about file %s: ",
+        if (errno == ENOENT) {
+            return 0;
+        }
+
+        ERRO("could not retrieve information about file %s: %s",
              path, strerror(errno));
              path, strerror(errno));
         exit(1);
         exit(1);
     }
     }