summaryrefslogtreecommitdiff
path: root/source3/lib/util_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/util_file.c')
-rw-r--r--source3/lib/util_file.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 023f3e131c..4e2adc97bc 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -368,21 +368,15 @@ char *file_pload(char *syscmd, size_t *size)
return p;
}
-
/****************************************************************************
-load a file into memory
-****************************************************************************/
-char *file_load(char *fname, size_t *size)
+load a file into memory from a fd.
+****************************************************************************/
+
+char *fd_load(int fd, size_t *size)
{
- int fd;
SMB_STRUCT_STAT sbuf;
char *p;
- if (!fname || !*fname) return NULL;
-
- fd = open(fname,O_RDONLY);
- if (fd == -1) return NULL;
-
if (sys_fstat(fd, &sbuf) != 0) return NULL;
p = (char *)malloc(sbuf.st_size+1);
@@ -394,13 +388,31 @@ char *file_load(char *fname, size_t *size)
}
p[sbuf.st_size] = 0;
- close(fd);
-
if (size) *size = sbuf.st_size;
return p;
}
+/****************************************************************************
+load a file into memory
+****************************************************************************/
+char *file_load(char *fname, size_t *size)
+{
+ int fd;
+ char *p;
+
+ if (!fname || !*fname) return NULL;
+
+ fd = open(fname,O_RDONLY);
+ if (fd == -1) return NULL;
+
+ p = fd_load(fd, size);
+
+ close(fd);
+
+ return p;
+}
+
/****************************************************************************
parse a buffer into lines
@@ -459,6 +471,22 @@ char **file_lines_load(char *fname, int *numlines, BOOL convert)
return file_lines_parse(p, size, numlines, convert);
}
+/****************************************************************************
+load a fd into memory and return an array of pointers to lines in the file
+must be freed with file_lines_free(). If convert is true calls unix_to_dos on
+the list.
+****************************************************************************/
+char **fd_lines_load(int fd, int *numlines, BOOL convert)
+{
+ char *p;
+ size_t size;
+
+ p = fd_load(fd, &size);
+ if (!p) return NULL;
+
+ return file_lines_parse(p, size, numlines, convert);
+}
+
/****************************************************************************
load a pipe into memory and return an array of pointers to lines in the data