From 3e7c7ae093ed387a7c9713449a01a562a0e2dffc Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Thu, 25 Nov 2004 13:31:46 +0000 Subject: [PATCH] Add a convenience function for building nmount iov arrays. --- sbin/mount/getmntopts.c | 24 ++++++++++++++++++++++++ sbin/mount/mntopts.h | 1 + 2 files changed, 25 insertions(+) diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c index 0a6ceb123054..2e8676ddce3e 100644 --- a/sbin/mount/getmntopts.c +++ b/sbin/mount/getmntopts.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -138,3 +139,26 @@ checkpath(path, resolved) } else errx(EX_USAGE, "%s: %s", resolved, strerror(errno)); } + +void +build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int len) +{ + int i; + + if (iovlen < 0) + return; + i = *iovlen; + *iov = realloc(*iov, sizeof **iov * (i + 2)); + if (*iov == NULL) { + *iovlen = -1; + return; + } + (*iov)[i].iov_base = strdup(name); + (*iov)[i].iov_len = strlen(name) + 1; + i++; + (*iov)[i].iov_base = val; + if (len < 0) + len = strlen(val) + 1; + (*iov)[i].iov_len = len; + *iovlen = ++i; +} diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h index 7fd807613d6b..5205195fd3f1 100644 --- a/sbin/mount/mntopts.h +++ b/sbin/mount/mntopts.h @@ -92,3 +92,4 @@ void getmntopts(const char *, const struct mntopt *, int *, int *); void rmslashes(char *, char *); void checkpath(const char *, char resolved_path[]); extern int getmnt_silent; +void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int len);