From cf5b71994d6cdb2f81c390579f4a0e676926c6b9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Dec 2000 19:26:04 +0000 Subject: file_lines_load/file_lines_pload can now optionally convert unix_to_dos() on read. Jeremy. (This used to be commit 76b8dd376d13eb4469417be217c966d54d333367) --- source3/lib/util_file.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source3/lib/util_file.c') diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 33a687950d..1184dd0634 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -405,7 +405,7 @@ char *file_load(char *fname, size_t *size) /**************************************************************************** parse a buffer into lines ****************************************************************************/ -static char **file_lines_parse(char *p, size_t size, int *numlines) +static char **file_lines_parse(char *p, size_t size, int *numlines, BOOL convert) { int i; char *s, **ret; @@ -434,15 +434,21 @@ static char **file_lines_parse(char *p, size_t size, int *numlines) if (s[0] == '\r') s[0] = 0; } + if (convert) { + for (i = 0; i < *numlines; i++) + unix_to_dos(ret[i], True); + } + return ret; } /**************************************************************************** load a file into memory and return an array of pointers to lines in the file -must be freed with file_lines_free() +must be freed with file_lines_free(). If convert is true calls unix_to_dos on +the list. ****************************************************************************/ -char **file_lines_load(char *fname, int *numlines) +char **file_lines_load(char *fname, int *numlines, BOOL convert) { char *p; size_t size; @@ -450,15 +456,16 @@ char **file_lines_load(char *fname, int *numlines) p = file_load(fname, &size); if (!p) return NULL; - return file_lines_parse(p, size, numlines); + return file_lines_parse(p, size, numlines, convert); } /**************************************************************************** load a pipe into memory and return an array of pointers to lines in the data -must be freed with file_lines_free() +must be freed with file_lines_free(). If convert is true calls unix_to_dos on +the list. ****************************************************************************/ -char **file_lines_pload(char *syscmd, int *numlines) +char **file_lines_pload(char *syscmd, int *numlines, BOOL convert) { char *p; size_t size; @@ -466,7 +473,7 @@ char **file_lines_pload(char *syscmd, int *numlines) p = file_pload(syscmd, &size); if (!p) return NULL; - return file_lines_parse(p, size, numlines); + return file_lines_parse(p, size, numlines, convert); } /**************************************************************************** -- cgit