From ff807bbde4523e96d12f518a9dd9db89b08b612c Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 13 Sep 2016 20:50:35 +1000 Subject: [PATCH] * src/sources/files.c : implement next() --- src/sources/files.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sources/files.c b/src/sources/files.c index 777e672..33e49f9 100644 --- a/src/sources/files.c +++ b/src/sources/files.c @@ -196,7 +196,26 @@ stop(cfg_t *cfg) { bool next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { assert(cfg != NULL); - /* TODO */ + assert(buf != NULL); + assert(bufsize > 0); + + if (reset || cfg->current == NULL) + cfg->current = cfg->files; + + for (f2b_file_t *file = cfg->current; file != NULL; file = file->next) { + if (file_rotated(file)) + file_close(file); + if (!file->opened && !file_open(file, NULL)) { + if (cfg->errcb) { + snprintf(cfg->error, sizeof(cfg->error), "can't open file -- %s", file->path); + cfg->errcb(cfg->error); + } + continue; + } + if (file_getline(file, buf, bufsize)) + return true; + } + return false; }