diff options
author | Volker Lendecke <vl@samba.org> | 2014-11-19 14:21:17 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-12-07 00:12:07 +0100 |
commit | 214fc09a3443ab62772666a985975fa548b215fa (patch) | |
tree | 3ff90a94c972deabf6a200de528e1ec1eeadfc64 /source3/lib/iov_buf.c | |
parent | a8491cb95a2c181d40b0b94cceff8d69d137935c (diff) | |
download | samba-214fc09a3443ab62772666a985975fa548b215fa.tar.gz samba-214fc09a3443ab62772666a985975fa548b215fa.tar.xz samba-214fc09a3443ab62772666a985975fa548b215fa.zip |
lib: Split out iov_buf[len]
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/lib/iov_buf.c')
-rw-r--r-- | source3/lib/iov_buf.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/source3/lib/iov_buf.c b/source3/lib/iov_buf.c new file mode 100644 index 0000000000..dd99da3625 --- /dev/null +++ b/source3/lib/iov_buf.c @@ -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; +} |