summaryrefslogtreecommitdiff
path: root/source3/lib/util_file.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-04-13 00:37:00 +0000
committerJeremy Allison <jra@samba.org>2001-04-13 00:37:00 +0000
commit50e78a9ac8cf0949c2471fafde844c674f97d73d (patch)
tree4b9489a28767ea782a679e4c8c3b93ce5a1f19ba /source3/lib/util_file.c
parentd85924a028f35e4789c70c068f903d677caf7ca0 (diff)
downloadsamba-50e78a9ac8cf0949c2471fafde844c674f97d73d.tar.gz
samba-50e78a9ac8cf0949c2471fafde844c674f97d73d.tar.bz2
samba-50e78a9ac8cf0949c2471fafde844c674f97d73d.zip
As Andrew suggested, make smbrun return a fd for a deleted file which can then
be read. Jeremy. (This used to be commit e7d59d6de89a5fdd201e4b5c6072dab08b1519db)
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