From: Joel Rosdahl Date: Thu, 4 Mar 2010 19:30:27 +0000 (+0100) Subject: Fix caching of empty source files in direct mode X-Git-Tag: v3.0pre1~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=baf2ff5d6b882052d558815ff5d701ab65b3fb6f;p=thirdparty%2Fccache.git Fix caching of empty source files in direct mode --- diff --git a/comments.c b/comments.c index 117395447..771b38b88 100644 --- a/comments.c +++ b/comments.c @@ -128,6 +128,10 @@ int hash_file_ignoring_comments(struct mdfour *hash, const char *path) close(fd); return 0; } + if (st.st_size == 0) { + close(fd); + return 1; + } data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); if (data == (void *)-1) { diff --git a/test.sh b/test.sh index eda5443be..cded5cc3d 100755 --- a/test.sh +++ b/test.sh @@ -717,6 +717,20 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 2 + ################################################################## + # Check that it's possible to compile and cache an empty source code file. + testname="empty source file" + $CCACHE -Cz >/dev/null + cp /dev/null empty.c + $CCACHE_COMPILE -c empty.c + checkstat 'cache hit (direct)' 0 + checkstat 'cache hit (preprocessed)' 0 + checkstat 'cache miss' 1 + $CCACHE_COMPILE -c empty.c + checkstat 'cache hit (direct)' 1 + checkstat 'cache hit (preprocessed)' 0 + checkstat 'cache miss' 1 + ################################################################## # Reset things. CCACHE_NODIRECT=1