]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Run stat() before open() on some files to allow bailing out earlier
authorRamiro Polla <ramiro.polla@gmail.com>
Thu, 15 Jul 2010 17:28:55 +0000 (14:28 -0300)
committerRamiro Polla <ramiro.polla@gmail.com>
Thu, 15 Jul 2010 19:41:38 +0000 (16:41 -0300)
ccache.c
hashutil.c

index 7678ba524eabb5aed8cfb7f42bee103b1c031529..dc21fa1b442f75af1bb83843ad050093f1c40801 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -350,20 +350,21 @@ static void remember_include_file(char *path, size_t path_len)
                goto ignore;
        }
 
-       /* Let's hash the include file. */
-       fd = open(path, O_RDONLY|O_BINARY);
-       if (fd == -1) {
-               cc_log("Failed to open include file %s", path);
-               goto failure;
-       }
-       if (fstat(fd, &st) != 0) {
-               cc_log("Failed to fstat include file %s", path);
+       if (stat(path, &st) != 0) {
+               cc_log("Failed to stat include file %s", path);
                goto failure;
        }
        if (S_ISDIR(st.st_mode)) {
                /* Ignore directory, typically $PWD. */
                goto ignore;
        }
+
+       /* Let's hash the include file. */
+       fd = open(path, O_RDONLY|O_BINARY);
+       if (fd == -1) {
+               cc_log("Failed to open include file %s", path);
+               goto failure;
+       }
        if (!(sloppiness & SLOPPY_INCLUDE_FILE_MTIME)
            && st.st_mtime >= time_of_compilation) {
                cc_log("Include file %s too new", path);
index b2aa15dfc31420cf85b320e34ce2d45d154b16ce..2b745b362b00feca60a2c3726bf9e6283a63a485 100644 (file)
@@ -204,20 +204,18 @@ hash_source_code_file(struct mdfour *hash, const char *path)
        char *data;
        int result;
 
-       fd = open(path, O_RDONLY|O_BINARY);
-       if (fd == -1) {
-               cc_log("Failed to open %s", path);
-               return HASH_SOURCE_CODE_ERROR;
-       }
-       if (fstat(fd, &st) == -1) {
-               cc_log("Failed to fstat %s", path);
-               close(fd);
+       if (stat(path, &st) == -1) {
+               cc_log("Failed to stat %s", path);
                return HASH_SOURCE_CODE_ERROR;
        }
        if (st.st_size == 0) {
-               close(fd);
                return HASH_SOURCE_CODE_OK;
        }
+       fd = open(path, O_RDONLY|O_BINARY);
+       if (fd == -1) {
+               cc_log("Failed to open %s", path);
+               return HASH_SOURCE_CODE_ERROR;
+       }
        data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        close(fd);
        if (data == (void *)-1) {