Use build_iovec() to make it less cryptic. This also fixes warnings.

This commit is contained in:
Jung-uk Kim 2013-03-06 00:36:33 +00:00
parent 7eb5d3cfa5
commit 067041766e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=247861
2 changed files with 13 additions and 32 deletions

View File

@ -9,7 +9,6 @@ LDADD= -lkiconv
MOUNT= ${.CURDIR}/../mount MOUNT= ${.CURDIR}/../mount
CFLAGS+= -I${MOUNT} -I${.CURDIR}/../../sys CFLAGS+= -I${MOUNT} -I${.CURDIR}/../../sys
.PATH: ${MOUNT} .PATH: ${MOUNT}
WARNS?= 1
# Needs to be dynamically linked for optional dlopen() access to # Needs to be dynamically linked for optional dlopen() access to
# userland libiconv # userland libiconv

View File

@ -73,14 +73,15 @@ void usage(void);
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct iovec iov[12]; char mntpath[MAXPATHLEN];
int ch, i, mntflags, udf_flags; char fstype[] = "udf";
char *dev, *dir, mntpath[MAXPATHLEN]; struct iovec *iov;
char *cs_disk, *cs_local; char *cs_disk, *cs_local, *dev, *dir;
int verbose; int ch, i, iovlen, mntflags, udf_flags, verbose;
i = mntflags = udf_flags = verbose = 0; i = iovlen = mntflags = udf_flags = verbose = 0;
cs_disk = cs_local = NULL; cs_disk = cs_local = NULL;
iov = NULL;
while ((ch = getopt(argc, argv, "o:vC:")) != -1) while ((ch = getopt(argc, argv, "o:vC:")) != -1)
switch (ch) { switch (ch) {
case 'o': case 'o':
@ -120,32 +121,13 @@ main(int argc, char **argv)
*/ */
mntflags |= MNT_RDONLY; mntflags |= MNT_RDONLY;
iov[i].iov_base = "fstype"; build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1);
iov[i++].iov_len = sizeof("fstype"); build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1);
iov[i].iov_base = "udf"; build_iovec(&iov, &iovlen, "from", dev, (size_t)-1);
iov[i].iov_len = strlen(iov[i].iov_base) + 1; build_iovec(&iov, &iovlen, "flags", &udf_flags, sizeof(udf_flags));
i++;
iov[i].iov_base = "fspath";
iov[i++].iov_len = sizeof("fspath");
iov[i].iov_base = mntpath;
iov[i++].iov_len = strlen(mntpath) + 1;
iov[i].iov_base = "from";
iov[i++].iov_len = sizeof("from");
iov[i].iov_base = dev;
iov[i++].iov_len = strlen(dev) + 1;
iov[i].iov_base = "flags";
iov[i++].iov_len = sizeof("flags");
iov[i].iov_base = &udf_flags;
iov[i++].iov_len = sizeof(udf_flags);
if (udf_flags & UDFMNT_KICONV) { if (udf_flags & UDFMNT_KICONV) {
iov[i].iov_base = "cs_disk"; build_iovec(&iov, &iovlen, "cs_disk", cs_disk, (size_t)-1);
iov[i++].iov_len = sizeof("cs_disk"); build_iovec(&iov, &iovlen, "cs_local", cs_local, (size_t)-1);
iov[i].iov_base = cs_disk;
iov[i++].iov_len = strlen(cs_disk) + 1;
iov[i].iov_base = "cs_local";
iov[i++].iov_len = sizeof("cs_local");
iov[i].iov_base = cs_local;
iov[i++].iov_len = strlen(cs_local) + 1;
} }
if (nmount(iov, i, mntflags) < 0) if (nmount(iov, i, mntflags) < 0)
err(1, "%s", dev); err(1, "%s", dev);