]> git.kaiwu.me - haproxy.git/commit
MINOR: tools: add read_line_to_mem() to read a line into a growing buffer
authorDongwon Jang <contact@dongwonjang.com>
Tue, 17 Nov 2026 01:33:04 +0000 (10:33 +0900)
committerWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 10:33:05 +0000 (11:33 +0100)
commit44556c0c0aabb9190f4cbf46863148a3d98f77eb
tree5c9821e6a4ebe951b3704e56356e8c19f3e6d357
parente99253b70269ef455eaa8576acd839012a7bd312
MINOR: tools: add read_line_to_mem() to read a line into a growing buffer

read_line_to_trash() reads the first line of a file into the trash, so
longer lines are truncated to the trash size. Some callers need to read
lines of any length from an already opened file instead, such as the
pattern file readers, which run before the trash is resized to
tune.bufsize.

read_line_to_mem() reads the next line of a file into a caller-provided
heap buffer that grows as needed, as parse_cfg() does for configuration
lines. Unlike read_line_to_trash(), the trailing LF is kept. A full buffer
is detected by checking whether fgets() overwrote its last byte rather
than from the string length, so that lines containing NUL bytes are read
entirely as well. getline() is not used since it was removed for
portability reasons by commit fbc3d46b9 ("BUILD: stats: remove non
portable getline() usage").

It will be used by the next commit to fix the pattern file readers, and
will have to be backported along with it.
include/haproxy/tools.h
src/tools.c