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);
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 {
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
/*
* 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;