]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add size hint to read_text_file()
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 5 Oct 2010 20:39:50 +0000 (22:39 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 Oct 2010 20:40:04 +0000 (22:40 +0200)
ccache.h
stats.c
test/test_lockfile.c
util.c

index 1c8e5777de347e58eafadb514db6e991de169491..9db24f8106f5f092e43cb33f8dce316025bcd213 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -140,7 +140,7 @@ bool is_full_path(const char *path);
 void update_mtime(const char *path);
 int x_rename(const char *oldpath, const char *newpath);
 char *x_readlink(const char *path);
-char *read_text_file(const char *path);
+char *read_text_file(const char *path, size_t size_hint);
 bool read_file(const char *path, size_t size_hint, char **data, size_t *size);
 #ifndef HAVE_STRTOK_R
 char *strtok_r(char *str, const char *delim, char **saveptr);
diff --git a/stats.c b/stats.c
index 1494007f612fccc0be964947328f8568a31c86c6..ac6d1008c5536c468106d808378e85a0cefe8c76 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -178,7 +178,7 @@ stats_update_size(enum stats stat, size_t size, unsigned files)
 void
 stats_read(const char *sfile, struct counters *counters)
 {
-       char *data = read_text_file(sfile);
+       char *data = read_text_file(sfile, 1024);
        if (data) {
                parse_stats(counters, data);
        } else {
index ec9889494b0a019b596dab900458e862d68741df..9af995f973b6bcc8ccdb1b7bea2d62b765b94422 100644 (file)
@@ -59,7 +59,7 @@ TEST(lock_breaking)
        CHECK(lockfile_acquire("test", 1000));
 
 #ifdef _WIN32
-       p = read_text_file("test.lock");
+       p = read_text_file("test.lock", 0);
 #else
        p = x_readlink("test.lock");
 #endif
diff --git a/util.c b/util.c
index 814a83877465effbdceabc6e56aec7ebd6ad07f0..ae07da11e0f0e0d57af101d91b96690cf68efffa 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1161,15 +1161,15 @@ read_file(const char *path, size_t size_hint, char **data, size_t *size)
 
 /*
  * Return the content (with NUL termination) of a text file, or NULL on error.
- * Caller frees.
+ * Caller frees. Size hint 0 means no hint.
  */
 char *
-read_text_file(const char *path)
+read_text_file(const char *path, size_t size_hint)
 {
        size_t size;
        char *data;
 
-       if (read_file(path, 0, &data, &size)) {
+       if (read_file(path, size_hint, &data, &size)) {
                data = x_realloc(data, size + 1);
                data[size] = '\0';
                return data;