SCCS-vsn: sbin/fsck/main.c 5.22
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)main.c 5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c 5.22 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
#include <fstab.h>
#include <strings.h>
#include <ctype.h>
#include <fstab.h>
#include <strings.h>
#include <ctype.h>
#include "fsck.h"
void catch(), catchquit(), voidquit();
#include "fsck.h"
void catch(), catchquit(), voidquit();
int argc;
char *argv[];
{
int argc;
char *argv[];
{
- extern int (docheck)(), (checkfilesys)();
+ extern int docheck(), checkfilesys();
+ extern char *optarg;
+ extern int optind;
- while (--argc > 0 && **++argv == '-') {
- switch (*++*argv) {
-
+ while ((ch = getopt(argc, argv, "cdpnNyYb:l:m:")) != EOF) {
+ switch (ch) {
case 'p':
preen++;
break;
case 'b':
case 'p':
preen++;
break;
case 'b':
- if (argv[0][1] != '\0') {
- bflag = atoi(argv[0]+1);
- } else {
- bflag = atoi(*++argv);
- argc--;
- }
+ if (!isdigit(*optarg))
+ errexit("-b flag requires a number\n");
+ bflag = atoi(optarg);
printf("Alternate super block location: %d\n", bflag);
break;
printf("Alternate super block location: %d\n", bflag);
break;
- if (!isdigit(argv[1][0]))
errexit("-l flag requires a number\n");
errexit("-l flag requires a number\n");
- maxrun = atoi(*++argv);
- argc--;
- if (!isdigit(argv[1][0]))
errexit("-m flag requires a mode\n");
errexit("-m flag requires a mode\n");
- sscanf(*++argv, "%o", &lfmode);
+ sscanf(optarg, "%o", &lfmode);
if (lfmode &~ 07777)
errexit("bad mode to -m: %o\n", lfmode);
if (lfmode &~ 07777)
errexit("bad mode to -m: %o\n", lfmode);
printf("** lost+found creation mode %o\n", lfmode);
break;
printf("** lost+found creation mode %o\n", lfmode);
break;
- errexit("%c option?\n", **argv);
+ errexit("%c option?\n", ch);
+ argc -= optind;
+ argv += optind;
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
(void)signal(SIGINT, catch);
if (preen)
(void)signal(SIGQUIT, catchquit);
if (argc) {
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
(void)signal(SIGINT, catch);
if (preen)
(void)signal(SIGQUIT, catchquit);
if (argc) {
- while (argc-- > 0) {
- hotroot = 0;
exit(0);
}
ret = checkfstab(preen, maxrun, docheck, checkfilesys);
exit(0);
}
ret = checkfstab(preen, maxrun, docheck, checkfilesys);