diff options
| author | Volker Lendecke <vl@samba.org> | 2014-03-02 19:33:08 +0100 |
|---|---|---|
| committer | Jeremy Allison <jra@samba.org> | 2014-04-23 22:33:08 +0200 |
| commit | e2683605b0c00a0911d59a9123210fe55400a732 (patch) | |
| tree | 4fa8b95139e09336e595633a392d4970d4d94071 /source3 | |
| parent | 7009b4921c6b05af2e27457500b9b2d838d40b28 (diff) | |
| download | samba-e2683605b0c00a0911d59a9123210fe55400a732.tar.gz samba-e2683605b0c00a0911d59a9123210fe55400a732.tar.xz samba-e2683605b0c00a0911d59a9123210fe55400a732.zip | |
lib: Add iov_buf
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
| -rw-r--r-- | source3/include/proto.h | 1 | ||||
| -rw-r--r-- | source3/lib/util_sock.c | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index 983a4d0094..0a4db861a8 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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, diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index b8149cad83..c5de61a094 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -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 |
