]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Stat file to get size hint in read_file()
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 12 Sep 2010 14:33:16 +0000 (16:33 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 12 Sep 2010 14:33:16 +0000 (16:33 +0200)
util.c

diff --git a/util.c b/util.c
index bb3d909d9fa8943e780d1faf8b3e4374937c650c..1cf9192605a5ded36cb5ad3437b166fbfb5678be 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1076,12 +1076,21 @@ bool
 read_file(const char *path, size_t size_hint, char **data, size_t *size)
 {
        int fd, ret;
-       size_t pos = 0, allocated = (size_hint == 0) ? 16384 : size_hint;
+       size_t pos = 0, allocated;
+
+       if (size_hint == 0) {
+               struct stat st;
+               if (stat(path, &st) == 0) {
+                       size_hint = st.st_size;
+               }
+       }
+       size_hint = (size_hint < 1024) ? 1024 : size_hint;
 
        fd = open(path, O_RDONLY);
        if (fd == -1) {
                return false;
        }
+       allocated = size_hint;
        *data = x_malloc(allocated);
        ret = 0;
        do {