diff options
| author | Jesper Nilsson <[email protected]> | 2013-10-10 11:09:52 +0200 |
|---|---|---|
| committer | Jesper Nilsson <[email protected]> | 2013-10-10 11:12:16 +0200 |
| commit | 2aad67171b36c94ea8f391ecea2834df0cb9f953 (patch) | |
| tree | 3c476f148baa602e5d8c6295ff38425322902181 | |
| parent | 401230026c26a327328fcf394a7bc2a2e5cb594d (diff) | |
| download | axis-profile-master.tar.gz | |
A normal file-map is always bigger than 512 bytes,
bump the buffer to 10k to avoid lots of reallocations.
Signed-off-by: Jesper Nilsson <[email protected]>
| -rw-r--r-- | file.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -60,10 +60,12 @@ char *get_pid_file(unsigned int pid, const char *filename) return get_proc_file(proc_file); } +#define MAPS_FILESIZE 20480 + char *get_proc_file(const char *filename) { FILE *f; - size_t buffer_size = MAX_STRING_LEN; + size_t buffer_size = MAPS_FILESIZE; char command[MAX_STRING_LEN]; char *file = malloc(buffer_size + 1); size_t file_size = 0; @@ -78,15 +80,15 @@ char *get_proc_file(const char *filename) } while (!feof(f)) { - size_t bytes = fread(file + file_size, 1, MAX_STRING_LEN, f); + size_t bytes = fread(file + file_size, 1, MAPS_FILESIZE, f); file_size += bytes; - if (bytes < MAX_STRING_LEN) { + if (bytes < MAPS_FILESIZE) { break; } - file = realloc(file, buffer_size += MAX_STRING_LEN); + file = realloc(file, buffer_size += MAPS_FILESIZE); } file[file_size] = '\0'; |
