From: Volker Lendecke Date: Sat, 6 Dec 2014 10:22:35 +0000 (+0100) Subject: lib: Simplify iov_buf[len] X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=d775c386e498d4c2062f8fc65f515f991d127dc1;p=obnox%2Fsamba%2Fsamba-obnox.git lib: Simplify iov_buf[len] This makes iov_buf independent of talloc Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/iov_buf.c b/source3/lib/iov_buf.c index dd99da3625e..e05dfc95248 100644 --- a/source3/lib/iov_buf.c +++ b/source3/lib/iov_buf.c @@ -23,43 +23,33 @@ ssize_t iov_buflen(const struct iovec *iov, int iovcnt) { - size_t buflen = 0; + return iov_buf(iov, iovcnt, NULL, 0); +} + +ssize_t iov_buf(const struct iovec *iov, int iovcnt, + uint8_t *buf, size_t buflen) +{ + size_t needed = 0; + uint8_t *p = buf; int i; for (i=0; i #include +#include 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 iov_buf(const struct iovec *iov, int iovcnt, + uint8_t *buf, size_t buflen); #endif diff --git a/source3/lib/messages_ctdbd.c b/source3/lib/messages_ctdbd.c index 59f5976da0b..53aeb1fd057 100644 --- a/source3/lib/messages_ctdbd.c +++ b/source3/lib/messages_ctdbd.c @@ -100,16 +100,23 @@ static int messaging_ctdb_send(struct server_id src, backend->private_data, struct messaging_ctdbd_context); struct messaging_rec msg; uint8_t *buf; + ssize_t buflen; NTSTATUS status; if (num_fds > 0) { return ENOSYS; } - buf = iov_buf(talloc_tos(), iov, iovlen); - if (buf == NULL) { + buflen = iov_buflen(iov, iovlen); + if (buflen == -1) { + return EMSGSIZE; + } + + buf = talloc_array(talloc_tos(), uint8_t, buflen); + if (buflen == NULL) { return ENOMEM; } + iov_buf(iov, iovlen, buf, buflen); msg = (struct messaging_rec) { .msg_version = MESSAGE_VERSION, diff --git a/source3/wscript_build b/source3/wscript_build index 18f6b6db7c5..51d72e78b64 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -260,7 +260,7 @@ bld.SAMBA3_LIBRARY('sys_rw', bld.SAMBA3_LIBRARY('iov_buf', source='lib/iov_buf.c', - deps='replace talloc', + deps='replace', private_library=True) bld.SAMBA3_SUBSYSTEM('samba3util',