From 1f1cfa864d07fc596e449bf079ab3c03818fa442 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 5 Oct 2010 22:39:50 +0200 Subject: [PATCH] Add size hint to read_text_file() --- ccache.h | 2 +- stats.c | 2 +- test/test_lockfile.c | 2 +- util.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ccache.h b/ccache.h index 1c8e5777d..9db24f810 100644 --- 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 1494007f6..ac6d1008c 100644 --- 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 { diff --git a/test/test_lockfile.c b/test/test_lockfile.c index ec9889494..9af995f97 100644 --- a/test/test_lockfile.c +++ b/test/test_lockfile.c @@ -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 814a83877..ae07da11e 100644 --- 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; -- 2.47.3