]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: util: Add file_ploadv().
authorJeremy Allison <jra@samba.org>
Fri, 17 May 2019 04:56:13 +0000 (21:56 -0700)
committerKarolin Seeger <kseeger@samba.org>
Thu, 13 Jun 2019 10:22:04 +0000 (10:22 +0000)
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>
(cherry picked from commit 5c34fa0b85e4d9a3c5fd4fa0b39af4772ec023db)

lib/util/samba_util.h
lib/util/util_file.c

index fff5478cd6d20cdd5a191ee6ff24ed87bde4191a..a4817f40ad9f4999cc8cde79cce28851849ba71d 100644 (file)
@@ -398,6 +398,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  */
 
index 90d39f7cdd356087d76382b98bf3b92917060714..af709dc52d0d716583d8057c0b5f8571d03937d8 100644 (file)
@@ -410,3 +410,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;
+}