From: Sebastian Harl Date: Mon, 23 Aug 2010 17:02:06 +0000 (+0200) Subject: src/utils_tail: Remove newline characters at the end of a line. X-Git-Tag: collectd-4.9.4~18 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7a58a2fc82acfec330a6dd1f8f051b60120039c3;p=collectd.git src/utils_tail: Remove newline characters at the end of a line. The tool is supposed to work line-based, so a) the newline character is implicit and b) imho, does not belong to the string which is then further processed. Also, this allows '$' to match the end of a line when applying a regex to the line, no matter if the REG_NEWLINE flag has been used when compiling the regex or not. --- diff --git a/src/utils_tail.c b/src/utils_tail.c index 904a5212..5b7551d3 100644 --- a/src/utils_tail.c +++ b/src/utils_tail.c @@ -220,6 +220,8 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback, while (42) { + size_t len; + status = cu_tail_readline (obj, buf, buflen); if (status != 0) { @@ -232,6 +234,13 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback, if (buf[0] == 0) break; + len = strlen (buf); + while (len > 0) { + if (buf[len - 1] != '\n') + break; + buf[len - 1] = '\0'; + } + status = callback (data, buf, buflen); if (status != 0) {