lib: Add iov_buf
authorVolker Lendecke <vl@samba.org>
Sun, 2 Mar 2014 18:33:08 +0000 (19:33 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 23 Apr 2014 20:33:08 +0000 (22:33 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/util_sock.c

index 983a4d009480e9728758d279e3793445ff382b1d..0a4db861a82ba9aec1ce85fed3a11321e73d914d 100644 (file)
@@ -584,6 +584,7 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
 NTSTATUS read_data(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,
index b8149cad83845ae54590e98ecad0c21edf85ce3c..c5de61a094b2110f6fa69888b906338e39967476 100644 (file)
@@ -219,6 +219,31 @@ ssize_t iov_buflen(const struct iovec *iov, int iovcnt)
        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