Rewrite catopt(), as in mount(8).

This commit is contained in:
mycroft 1997-10-31 09:48:04 +00:00
parent 04b8837e23
commit 3cd66a1543

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsck.c,v 1.15 1997/10/31 09:11:53 mycroft Exp $ */ /* $NetBSD: fsck.c,v 1.16 1997/10/31 09:48:04 mycroft Exp $ */
/* /*
* Copyright (c) 1996 Christos Zoulas. All rights reserved. * Copyright (c) 1996 Christos Zoulas. All rights reserved.
@ -40,7 +40,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: fsck.c,v 1.15 1997/10/31 09:11:53 mycroft Exp $"); __RCSID("$NetBSD: fsck.c,v 1.16 1997/10/31 09:48:04 mycroft Exp $");
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -87,7 +87,7 @@ static void addoption __P((char *));
static const char *getoptions __P((const char *)); static const char *getoptions __P((const char *));
static void addentry __P((struct fstypelist *, const char *, const char *)); static void addentry __P((struct fstypelist *, const char *, const char *));
static void maketypelist __P((char *)); static void maketypelist __P((char *));
static char *catopt __P((char *, const char *, int)); static void catopt __P((char **, const char *));
static void mangle __P((char *, int *, const char ***, int *)); static void mangle __P((char *, int *, const char ***, int *));
static char *getfslab __P((const char *)); static char *getfslab __P((const char *));
static void usage __P((void)); static void usage __P((void));
@ -126,7 +126,7 @@ main(argc, argv)
case 'f': case 'f':
case 'y': case 'y':
globopt[1] = i; globopt[1] = i;
options = catopt(options, globopt, 1); catopt(&options, globopt);
break; break;
case 'l': case 'l':
@ -232,17 +232,11 @@ checkfs(vfstype, spec, mntpt, auxarg, pidp)
if (!strcmp(vfstype, "ufs")) if (!strcmp(vfstype, "ufs"))
vfstype = MOUNT_UFS; vfstype = MOUNT_UFS;
if (options) { optbuf = NULL;
if (extra) if (options)
optbuf = catopt(options, extra, 0); catopt(&optbuf, options);
else if (extra)
optbuf = estrdup(options); catopt(&optbuf, extra);
} else {
if (extra)
optbuf = estrdup(extra);
else
optbuf = NULL;
}
maxargc = 64; maxargc = 64;
argv = emalloc(sizeof(char *) * maxargc); argv = emalloc(sizeof(char *) * maxargc);
@ -366,7 +360,7 @@ addoption(optstr)
for (e = opthead.tqh_first; e != NULL; e = e->entries.tqe_next) for (e = opthead.tqh_first; e != NULL; e = e->entries.tqe_next)
if (!strncmp(e->type, optstr, MFSNAMELEN)) { if (!strncmp(e->type, optstr, MFSNAMELEN)) {
e->options = catopt(e->options, newoptions, 1); catopt(&e->options, newoptions);
return; return;
} }
addentry(&opthead, optstr, newoptions); addentry(&opthead, optstr, newoptions);
@ -410,25 +404,23 @@ maketypelist(fslist)
} }
static char * static void
catopt(s0, s1, fr) catopt(sp, o)
char *s0; char **sp;
const char *s1; const char *o;
int fr;
{ {
size_t i; char *s;
char *cp; size_t i, j;
if (s0 && *s0) { s = *sp;
i = strlen(s0) + strlen(s1) + 1 + 1; if (s) {
cp = emalloc(i); i = strlen(s);
(void)snprintf(cp, i, "%s,%s", s0, s1); j = i + 1 + strlen(o) + 1;
s = erealloc(s, j);
(void)snprintf(s + i, j, ",%s", o);
} else } else
cp = estrdup(s1); s = estrdup(o);
*sp = s;
if (s0 && fr)
free(s0);
return (cp);
} }