summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-02-14 16:48:54 +0100
committerJeremy Allison <jra@samba.org>2015-02-24 17:52:08 +0100
commita610336886259b960317f172d3084de6ecc5a396 (patch)
tree9b63f877848f1c1de1dd6216739b85e1f9931db8 /lib
parentd5de29b8601a8e0d6afed779aae2da370358e4ca (diff)
downloadsamba-a610336886259b960317f172d3084de6ecc5a396.tar.gz
lib: Move "iov_buf.[ch]" to lib/util
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/async_req/async_sock.c2
-rw-r--r--lib/util/iov_buf.c88
-rw-r--r--lib/util/iov_buf.h32
-rwxr-xr-xlib/util/wscript_build5
4 files changed, 126 insertions, 1 deletions
diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c
index b986e45b0aa..ee91b8f16c8 100644
--- a/lib/async_req/async_sock.c
+++ b/lib/async_req/async_sock.c
@@ -27,7 +27,7 @@
#include <talloc.h>
#include <tevent.h>
#include "lib/async_req/async_sock.h"
-#include "lib/iov_buf.h"
+#include "lib/util/iov_buf.h"
/* Note: lib/util/ is currently GPL */
#include "lib/util/tevent_unix.h"
diff --git a/lib/util/iov_buf.c b/lib/util/iov_buf.c
new file mode 100644
index 00000000000..82a4af5323b
--- /dev/null
+++ b/lib/util/iov_buf.c
@@ -0,0 +1,88 @@
+/*
+ * 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)
+{
+ 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<iovcnt; i++) {
+ size_t thislen = iov[i].iov_len;
+ size_t tmp;
+
+ tmp = needed + thislen;
+
+ if (tmp < needed) {
+ /* wrap */
+ return -1;
+ }
+ needed = tmp;
+
+ if (needed <= buflen) {
+ memcpy(p, iov[i].iov_base, thislen);
+ p += thislen;
+ }
+ }
+
+ return needed;
+}
+
+bool iov_advance(struct iovec **iov, int *iovcnt, size_t n)
+{
+ struct iovec *v = *iov;
+ int cnt = *iovcnt;
+
+ while (n > 0) {
+ if (cnt == 0) {
+ return false;
+ }
+ if (n < v->iov_len) {
+ v->iov_base = (char *)v->iov_base + n;
+ v->iov_len -= n;
+ break;
+ }
+ n -= v->iov_len;
+ v += 1;
+ cnt -= 1;
+ }
+
+ /*
+ * Skip 0-length iovec's
+ */
+
+ while ((cnt > 0) && (v->iov_len == 0)) {
+ v += 1;
+ cnt -= 1;
+ }
+
+ *iov = v;
+ *iovcnt = cnt;
+ return true;
+}
diff --git a/lib/util/iov_buf.h b/lib/util/iov_buf.h
new file mode 100644
index 00000000000..8f0ca266da9
--- /dev/null
+++ b/lib/util/iov_buf.h
@@ -0,0 +1,32 @@
+/*
+ * 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 <stdint.h>
+#include <stdbool.h>
+
+ssize_t iov_buflen(const struct iovec *iov, int iovlen);
+ssize_t iov_buf(const struct iovec *iov, int iovcnt,
+ uint8_t *buf, size_t buflen);
+bool iov_advance(struct iovec **iov, int *iovcnt, size_t n);
+
+#endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 3121e1ff5b2..25887424857 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -36,6 +36,11 @@ bld.SAMBA_LIBRARY('socket-blocking',
local_include=False,
private_library=True)
+bld.SAMBA_LIBRARY('iov_buf',
+ source='iov_buf.c',
+ local_include=False,
+ private_library=True)
+
bld.SAMBA_SUBSYSTEM('samba-util-core',
source='''xfile.c data_blob.c util_file.c time.c
signal.c util.c idtree.c fault.c