From 5235e6518cd9d9f5edac9424a4cc43023dd96b7f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 9 Dec 2006 03:12:33 +0000 Subject: r20091: remove blank lines at the end of text lines loaded from a file (This used to be commit afcc797e8a25d99269f67e05fe57e952dd5d65bc) --- source4/lib/util/util_file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/util/util_file.c') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 5d7ec40b30..887efb9836 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -263,7 +263,6 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * talloc_steal(ret, p); memset(ret, 0, sizeof(ret[0])*(i+2)); - if (numlines) *numlines = i; ret[0] = p; for (s = p, i=0; s < p+size; s++) { @@ -275,6 +274,13 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * if (s[0] == '\r') s[0] = 0; } + /* remove any blank lines at the end */ + while (i > 0 && ret[i-1][0] == 0) { + i--; + } + + if (numlines) *numlines = i; + return ret; } -- cgit