+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <malloc.h>
-#include <inttypes.h>
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
char *s = ff->data, *e = ff->data, *t = ff->data;
uint32_t l = 0, w = 0;
e += ff->len;
-
+
ff->lines = pflines_add(ff->lines, w);
if(unlikely(!ff->lines)) goto cleanup;
procfile *procfile_readall(procfile *ff) {
debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.", ff->filename);
- ssize_t s = 0, r = ff->size, x = ff->size;
+ ssize_t s, r = 1, x;
ff->len = 0;
- while(likely(r == x)) {
- if(s) {
+ while(likely(r > 0)) {
+ s = ff->len;
+ x = ff->size - s;
+
+ if(!x) {
debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s'.", ff->filename);
procfile *new = realloc(ff, sizeof(procfile) + ff->size + PROCFILE_INCREMENT_BUFFER);
}
ff = new;
ff->size += PROCFILE_INCREMENT_BUFFER;
- x = PROCFILE_INCREMENT_BUFFER;
}
debug(D_PROCFILE, "Reading file '%s', from position %ld with length %ld", ff->filename, s, ff->size - s);
}
ff->len += r;
- s = ff->len;
}
debug(D_PROCFILE, "Rewinding file '%s'", ff->filename);