Add a convenience function for building nmount iov arrays.

This commit is contained in:
Poul-Henning Kamp 2004-11-25 13:31:46 +00:00
parent 53805858d2
commit 3e7c7ae093
2 changed files with 25 additions and 0 deletions

View File

@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <err.h>
#include <errno.h>
@ -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;
}

View File

@ -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);