r20091: remove blank lines at the end of text lines loaded from a file
authorAndrew Tridgell <tridge@samba.org>
Sat, 9 Dec 2006 03:12:33 +0000 (03:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:29:03 +0000 (14:29 -0500)
(This used to be commit afcc797e8a25d99269f67e05fe57e952dd5d65bc)

source4/lib/util/util_file.c

index 5d7ec40b30903e93522951be3fa650f60363245b..887efb98364bea526e60cab8fbba51d056b886ad 100644 (file)
@@ -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));
        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++) {
 
        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;
        }
 
                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;
 }
 
        return ret;
 }