diff options
author | Jeremy Allison <jra@samba.org> | 2019-05-16 21:56:13 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2019-05-24 19:00:05 +0000 |
commit | 5c34fa0b85e4d9a3c5fd4fa0b39af4772ec023db (patch) | |
tree | fc4693042655dfd45f4065139f125d47f115689b /lib | |
parent | f20538de041eed1cadbabe2149b2b7cfcb779cb5 (diff) | |
download | samba-5c34fa0b85e4d9a3c5fd4fa0b39af4772ec023db.tar.gz |
lib: util: Add file_ploadv().
Not yet used.
Duplicate code to file_pload() except uses vectored
argument list. file_pload() will be removed once all
callers are converted.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13964
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/samba_util.h | 1 | ||||
-rw-r--r-- | lib/util/util_file.c | 46 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h index 0722426216e..cf8602e2015 100644 --- a/lib/util/samba_util.h +++ b/lib/util/samba_util.h @@ -405,6 +405,7 @@ bool file_compare(const char *path1, const char *path2); load from a pipe into memory. */ char *file_pload(const char *syscmd, size_t *size); +char *file_ploadv(char * const argl[], size_t *size); /* The following definitions come from lib/util/util.c */ diff --git a/lib/util/util_file.c b/lib/util/util_file.c index 7a8644e3f5d..1541a08f935 100644 --- a/lib/util/util_file.c +++ b/lib/util/util_file.c @@ -443,3 +443,49 @@ char *file_pload(const char *syscmd, size_t *size) return p; } + +/** + Load from a pipe into memory. +**/ +char *file_ploadv(char * const argl[], size_t *size) +{ + int fd, n; + char *p = NULL; + char buf[1024]; + size_t total; + + fd = sys_popenv(argl); + if (fd == -1) { + return NULL; + } + + total = 0; + + while ((n = sys_read(fd, buf, sizeof(buf))) > 0) { + p = talloc_realloc(NULL, p, char, total + n + 1); + if (p == NULL) { + DBG_ERR("failed to expand buffer!\n"); + close(fd); + return NULL; + } + memcpy(p+total, buf, n); + total += n; + } + + if (p != NULL) { + p[total] = 0; + } + + /* + * FIXME: Perhaps ought to check that the command completed + * successfully (returned 0); if not the data may be + * truncated. + */ + sys_pclose(fd); + + if (size) { + *size = total; + } + + return p; +} |