summaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-30 20:16:20 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-08-30 20:16:20 (GMT)
commit8cca3541498950b79633001555f2f221f9cb1594 (patch)
treecb66621a9c06820cace4fd83bcbb27cb05e482dc /file
parent1ed088fc5625c7ce1124e8557bd843105f4a458d (diff)
downloadeeshow-8cca3541498950b79633001555f2f221f9cb1594.zip
eeshow-8cca3541498950b79633001555f2f221f9cb1594.tar.gz
eeshow-8cca3541498950b79633001555f2f221f9cb1594.tar.bz2
file/file.c (file_cleanup): clean up static getline buffer
Diffstat (limited to 'file')
-rw-r--r--file/file.c18
-rw-r--r--file/file.h2
2 files changed, 15 insertions, 5 deletions
diff --git a/file/file.c b/file/file.c
index 274d88f..80c19a7 100644
--- a/file/file.c
+++ b/file/file.c
@@ -22,6 +22,10 @@
#include "file/file.h"
+static char *getline_buf = NULL;
+static size_t getline_n = 0;
+
+
void *file_oid(const struct file *file)
{
if (!file->vcs)
@@ -220,18 +224,16 @@ bool file_read(struct file *file,
bool (*parse)(const struct file *file, void *user, const char *line),
void *user)
{
- static char *buf = NULL;
- static size_t n = 0;
char *nl;
if (file->vcs)
return vcs_read(file->vcs, file, parse, user);
- while (getline(&buf, &n, file->file) > 0) {
- nl = strchr(buf, '\n');
+ while (getline(&getline_buf, &getline_n, file->file) > 0) {
+ nl = strchr(getline_buf, '\n');
if (nl)
*nl = 0;
file->lineno++;
- if (!parse(file, user, buf))
+ if (!parse(file, user, getline_buf))
return 0;
}
return 1;
@@ -246,3 +248,9 @@ void file_close(struct file *file)
vcs_close(file->vcs);
free((char *) file->name);
}
+
+
+void file_cleanup(void)
+{
+ free(getline_buf);
+}
diff --git a/file/file.h b/file/file.h
index 8f6c855..15ebc1a 100644
--- a/file/file.h
+++ b/file/file.h
@@ -42,4 +42,6 @@ bool file_read(struct file *file,
void *user);
void file_close(struct file *file);
+void file_cleanup(void);
+
#endif /* !FILE_FILE_H */