summaryrefslogtreecommitdiff
path: root/source/lib/util_file.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2000-12-07 19:26:04 +0000
committerJeremy Allison <jra@samba.org>2000-12-07 19:26:04 +0000
commit76b8dd376d13eb4469417be217c966d54d333367 (patch)
tree9c4419fb3123eeb29f547b39c92422a6bb4d85c3 /source/lib/util_file.c
parentf3b5e2a172a777e1c3bbf6ac72fe5c7cdb8324b3 (diff)
downloadsamba-76b8dd376d13eb4469417be217c966d54d333367.tar.gz
file_lines_load/file_lines_pload can now optionally convert unix_to_dos()
on read. Jeremy.
Diffstat (limited to 'source/lib/util_file.c')
-rw-r--r--source/lib/util_file.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/source/lib/util_file.c b/source/lib/util_file.c
index 33a687950d4..1184dd0634e 100644
--- a/source/lib/util_file.c
+++ b/source/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);
}
/****************************************************************************