s3:util: Move static file_pload() function to lib/util
authorAliaksei Karaliou <akaraliou@panasas.com>
Thu, 27 Dec 2018 09:25:47 +0000 (04:25 -0500)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 11 Feb 2019 06:43:31 +0000 (07:43 +0100)
file_pload() is static private function in Samba3 library, however it
does not have any special dependencies and might be widely used as
common function, so moving it into common samba-util library.

Signed-off-by: Aliaksei Karaliou <akaraliou@panasas.com>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/samba_util.h
lib/util/util_file.c
source3/lib/util_file.c

index 1cd1235f8f113952f3df97e818245bb8ef04e87d..8c21c30ebc9c048d3afd257758897064982fabc1 100644 (file)
@@ -394,6 +394,11 @@ _PUBLIC_ int fdprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
  */
 bool file_compare(const char *path1, const char *path2);
 
+/*
+  load from a pipe into memory.
+ */
+char *file_pload(const char *syscmd, size_t *size);
+
 /* The following definitions come from lib/util/util.c  */
 
 
index 926eda240f6c196d02cd6933521b8db631f2cd3f..90d39f7cdd356087d76382b98bf3b92917060714 100644 (file)
@@ -24,6 +24,8 @@
 #include "system/filesys.h"
 #include <talloc.h>
 #include "lib/util/samba_util.h"
+#include "lib/util/sys_popen.h"
+#include "lib/util/sys_rw.h"
 #include "lib/util/debug.h"
 
 /**
@@ -362,3 +364,49 @@ bool file_compare(const char *path1, const char *path2)
        talloc_free(mem_ctx);
        return true;
 }
+
+
+/**
+ Load from a pipe into memory.
+**/
+char *file_pload(const char *syscmd, size_t *size)
+{
+       int fd, n;
+       char *p;
+       char buf[1024];
+       size_t total;
+
+       fd = sys_popen(syscmd);
+       if (fd == -1) {
+               return NULL;
+       }
+
+       p = NULL;
+       total = 0;
+
+       while ((n = sys_read(fd, buf, sizeof(buf))) > 0) {
+               p = talloc_realloc(NULL, p, char, total + n + 1);
+               if (!p) {
+                       DEBUG(0,("file_pload: failed to expand buffer!\n"));
+                       close(fd);
+                       return NULL;
+               }
+               memcpy(p+total, buf, n);
+               total += n;
+       }
+
+       if (p) {
+               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;
+}
index 94e1118225f9064696e269157634687162453925..cfbcf278caaef47c69a1f413201a7f13e60f0245 100644 (file)
@@ -151,53 +151,6 @@ int file_pload_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
        return 0;
 }
 
-/**
- Load from a pipe into memory.
-**/
-
-static char *file_pload(const char *syscmd, size_t *size)
-{
-       int fd, n;
-       char *p;
-       char buf[1024];
-       size_t total;
-
-       fd = sys_popen(syscmd);
-       if (fd == -1) {
-               return NULL;
-       }
-
-       p = NULL;
-       total = 0;
-
-       while ((n = sys_read(fd, buf, sizeof(buf))) > 0) {
-               p = talloc_realloc(NULL, p, char, total + n + 1);
-               if (!p) {
-                       DEBUG(0,("file_pload: failed to expand buffer!\n"));
-                       close(fd);
-                       return NULL;
-               }
-               memcpy(p+total, buf, n);
-               total += n;
-       }
-
-       if (p) {
-               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;
-}
-
-
 
 /**
  Load a pipe into memory and return an array of pointers to lines in the data