lib: Split out iov_buf[len]
authorVolker Lendecke <vl@samba.org>
Wed, 19 Nov 2014 14:21:17 +0000 (14:21 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 6 Dec 2014 23:12:07 +0000 (00:12 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/iov_buf.c [new file with mode: 0644]
source3/lib/iov_buf.h [new file with mode: 0644]
source3/lib/messages.c
source3/lib/messages_ctdbd.c
source3/lib/util_sock.c
source3/wscript_build

index dcecf74a8661a2193b14cbd8aa99afc0913968a0..d9815f49f164a774e6b99cb169af64afede7bbf5 100644 (file)
@@ -566,9 +566,8 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
                                  unsigned int time_out,
                                  size_t *size_ret);
 NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N);
+
 ssize_t write_data(int fd, const char *buffer, size_t N);
-ssize_t iov_buflen(const struct iovec *iov, int iovlen);
-uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt);
 ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt);
 bool send_keepalive(int client);
 NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
diff --git a/source3/lib/iov_buf.c b/source3/lib/iov_buf.c
new file mode 100644 (file)
index 0000000..dd99da3
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "iov_buf.h"
+
+ssize_t iov_buflen(const struct iovec *iov, int iovcnt)
+{
+       size_t buflen = 0;
+       int i;
+
+       for (i=0; i<iovcnt; i++) {
+               size_t thislen = iov[i].iov_len;
+               size_t tmp = buflen + thislen;
+
+               if ((tmp < buflen) || (tmp < thislen)) {
+                       /* overflow */
+                       return -1;
+               }
+               buflen = tmp;
+       }
+       return buflen;
+}
+
+uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt)
+{
+       int i;
+       ssize_t buflen;
+       uint8_t *buf, *p;
+
+       buflen = iov_buflen(iov, iovcnt);
+       if (buflen == -1) {
+               return NULL;
+       }
+       buf = talloc_array(mem_ctx, uint8_t, buflen);
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       p = buf;
+       for (i=0; i<iovcnt; i++) {
+               size_t len = iov[i].iov_len;
+
+               memcpy(p, iov[i].iov_base, len);
+               p += len;
+       }
+       return buf;
+}
diff --git a/source3/lib/iov_buf.h b/source3/lib/iov_buf.h
new file mode 100644 (file)
index 0000000..a884bdb
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIB_IOV_BUF_H__
+#define __LIB_IOV_BUF_H__
+
+#include <unistd.h>
+#include <talloc.h>
+
+ssize_t iov_buflen(const struct iovec *iov, int iovlen);
+uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt);
+
+#endif
index d4c580fdd25546150240e0f0140903c51cd620e6..5b4daa2932679434a6572d989f7e2f1388c76ff3 100644 (file)
@@ -52,6 +52,7 @@
 #include "lib/util/tevent_unix.h"
 #include "lib/background.h"
 #include "lib/messages_dgm.h"
+#include "lib/iov_buf.h"
 
 struct messaging_callback {
        struct messaging_callback *prev, *next;
index eb7e929fc38d6921531ba6ba77e92a672beddaa7..59f5976da0b8a397f8f537887192d7955e250070 100644 (file)
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "messages.h"
 #include "util_tdb.h"
+#include "lib/iov_buf.h"
 
 /*
  * It is not possible to include ctdb.h and tdb_compat.h (included via
index d93e22d702c5a537076a1fff3fa59b45db1d42e3..163045a8a2c043a72652fdb7777c2890bbdcedd6 100644 (file)
@@ -29,6 +29,7 @@
 #include "../lib/util/tevent_ntstatus.h"
 #include "../lib/tsocket/tsocket.h"
 #include "lib/sys_rw.h"
+#include "lib/iov_buf.h"
 
 const char *client_addr(int fd, char *addr, size_t addrlen)
 {
@@ -202,49 +203,6 @@ NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N)
        return read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
 }
 
-ssize_t iov_buflen(const struct iovec *iov, int iovcnt)
-{
-       size_t buflen = 0;
-       int i;
-
-       for (i=0; i<iovcnt; i++) {
-               size_t thislen = iov[i].iov_len;
-               size_t tmp = buflen + thislen;
-
-               if ((tmp < buflen) || (tmp < thislen)) {
-                       /* overflow */
-                       return -1;
-               }
-               buflen = tmp;
-       }
-       return buflen;
-}
-
-uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt)
-{
-       int i;
-       ssize_t buflen;
-       uint8_t *buf, *p;
-
-       buflen = iov_buflen(iov, iovcnt);
-       if (buflen == -1) {
-               return NULL;
-       }
-       buf = talloc_array(mem_ctx, uint8_t, buflen);
-       if (buf == NULL) {
-               return NULL;
-       }
-
-       p = buf;
-       for (i=0; i<iovcnt; i++) {
-               size_t len = iov[i].iov_len;
-
-               memcpy(p, iov[i].iov_base, len);
-               p += len;
-       }
-       return buf;
-}
-
 /****************************************************************************
  Write all data from an iov array
  NB. This can be called with a non-socket fd, don't add dependencies
index 787c4e25514f50b1d863ef51b0a65a315d86d26c..591b1be77e3bcb74b3e78e7a7e13b0f01ceeb43b 100755 (executable)
@@ -258,6 +258,11 @@ bld.SAMBA3_LIBRARY('sys_rw',
                    deps='replace',
                    private_library=True)
 
+bld.SAMBA3_LIBRARY('iov_buf',
+                   source='lib/iov_buf.c',
+                   deps='replace talloc',
+                   private_library=True)
+
 bld.SAMBA3_SUBSYSTEM('samba3util',
                    source='''lib/system.c
                    lib/sendfile.c
@@ -269,7 +274,7 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
                    lib/util_sock.c
                    lib/util_transfer_file.c
                    lib/sock_exec.c''',
-                   deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash sys_rw')
+                   deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash sys_rw iov_buf')
 
 if bld.CONFIG_GET("CTDB_CFLAGS") and bld.CONFIG_GET("CTDB_INCLUDE"):
     SAMBA_CLUSTER_SUPPORT_SOURCES='''