logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

commit 7401e7406458729ee93001b307abac0eec1c7d29
parent 18b169de57754001c0196acaf38b94c1c6e0cc5c
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue, 16 Nov 2021 12:23:04 +0100

Switch to using getline(3) instead of fgets(3).

This allows reading lines of arbitrary length, and performance testing
using hyperfine didn't show any significant regressions.

Diffstat:
Msrc/config.h | 3+--
Msrc/logswan.c | 8+++++---
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/config.h b/src/config.h @@ -4,7 +4,7 @@ * https://www.logswan.org * * Created: 2015-05-31 - * Last Updated: 2021-02-15 + * Last Updated: 2021-11-16 * * Logswan is released under the BSD 2-Clause license. * See LICENSE file for details. @@ -19,7 +19,6 @@ enum { HLL_BITS = 20, - LINE_LENGTH_MAX = 65536, STATUS_CODE_MAX = 512, CONTINENTS = 7, diff --git a/src/logswan.c b/src/logswan.c @@ -4,7 +4,7 @@ * https://www.logswan.org * * Created: 2015-05-31 - * Last Updated: 2021-02-15 + * Last Updated: 2021-11-16 * * Logswan is released under the BSD 2-Clause license. * See LICENSE file for details. @@ -75,7 +75,8 @@ main(int argc, char *argv[]) int opt; const char *errstr; - char linebuffer[LINE_LENGTH_MAX]; + char *linebuffer = NULL; + size_t linesize = 0; char *input; char *db = NULL; @@ -167,7 +168,7 @@ main(int argc, char *argv[]) results.file_name = input; results.file_size = logfile_stat.st_size; - while (fgets(linebuffer, LINE_LENGTH_MAX, logfile)) { + while (getline(&linebuffer, &linesize, logfile) != -1) { /* Parse and tokenize line */ parse_line(&parsed_line, linebuffer); @@ -315,6 +316,7 @@ main(int argc, char *argv[]) fprintf(stderr, "Processed %" PRIu64 " lines in %f seconds.\n", results.processed_lines, results.runtime); /* Clean up */ + free(linebuffer); fclose(logfile); if (geoip)