int main(int argc, char *argv[]) { char **p, **start; int ch; (void)time(&now); /* initialize the time-of-day */ (void)setlocale(LC_ALL, ""); /* array to hold dir list. at most (argc - 1) elements. */ p = start = malloc(argc * sizeof (char *)); if (p == NULL) err(1, NULL); ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; while ((ch = getopt(argc, argv, "HLPdEf:hsXx")) != -1) switch (ch) { case 'H': ftsoptions &= ~FTS_LOGICAL; ftsoptions |= FTS_PHYSICAL|FTS_COMFOLLOW; break; case 'L': ftsoptions &= ~(FTS_COMFOLLOW|FTS_PHYSICAL); ftsoptions |= FTS_LOGICAL; break; case 'P': ftsoptions &= ~(FTS_COMFOLLOW|FTS_LOGICAL); ftsoptions |= FTS_PHYSICAL; break; case 'd': isdepth = 1; break; case 'E': regcomp_flags = REG_EXTENDED; break; case 'f': *p++ = optarg; break; case 'h': ftsoptions &= ~FTS_PHYSICAL; ftsoptions |= FTS_LOGICAL; break; case 's': issort = 1; break; case 'X': isxargs = 1; break; case 'x': ftsoptions |= FTS_XDEV; break; case '?': default: break; } argc -= optind; argv += optind; /* * Find first option to delimit the file list. The first argument * that starts with a -, or is a ! or a ( must be interpreted as a * part of the find expression, according to POSIX .2. */ for (; *argv != NULL; *p++ = *argv++) { if (argv[0][0] == '-') break; if ((argv[0][0] == '!' || argv[0][0] == '(') && argv[0][1] == '\0') break; } if (p == start) usage(); *p = NULL; if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) err(1, "."); exit(find_execute(find_formplan(argv), start)); }
int main(int argc, char *argv[]) { struct sigaction sa; char **p, **paths, **paths2; int ch; memset(&sa, 0, sizeof sa); sa.sa_handler = show_path; sa.sa_flags = SA_RESTART; (void)time(&now); /* initialize the time-of-day */ p = paths = (char **) emalloc(sizeof(char *) * argc); sigaction(SIGINFO, &sa, NULL); ftsoptions = FTS_NOSTAT|FTS_PHYSICAL; while ((ch = getopt(argc, argv, "Hdf:hLXx")) != -1) switch(ch) { case 'H': ftsoptions |= FTS_COMFOLLOW; ftsoptions |= FTS_PHYSICAL; ftsoptions &= ~FTS_LOGICAL; break; case 'd': isdepth = 1; break; case 'f': *p++ = optarg; break; case 'h': case 'L': ftsoptions &= ~FTS_COMFOLLOW; ftsoptions &= ~FTS_PHYSICAL; ftsoptions |= FTS_LOGICAL; break; case 'X': isxargs = 1; break; case 'x': ftsoptions &= ~FTS_NOSTAT; ftsoptions |= FTS_XDEV; break; case '?': default: usage(); } argc -= optind; argv += optind; /* The first argument that starts with a -, or is a ! or a (, and all * subsequent arguments shall be interpreted as an expression ... * (POSIX.2). */ while (*argv) { if (**argv == '-' || ((**argv == '!' || **argv == '(') && (*argv)[1] == '\0')) break; *p++ = *argv++; } if (p == paths) usage(); *p = NULL; if (!(paths2 = realloc(paths, sizeof(char *) * (p - paths + 1)))) err(1, NULL); paths = paths2; dotfd = open(".", O_RDONLY, 0); exit(find_execute(find_formplan(argv), paths)); }
int main(int argc, char *argv[]) { char **p, **start; int Hflag, Lflag, ch; (void)setlocale(LC_ALL, ""); (void)time(&now); /* initialize the time-of-day */ p = start = argv; Hflag = Lflag = 0; ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; while ((ch = getopt(argc, argv, "EHLPXdf:sx")) != -1) switch (ch) { case 'E': regexp_flags |= REG_EXTENDED; break; case 'H': Hflag = 1; Lflag = 0; break; case 'L': Lflag = 1; Hflag = 0; break; case 'P': Hflag = Lflag = 0; break; case 'X': isxargs = 1; break; case 'd': isdepth = 1; break; case 'f': *p++ = optarg; break; case 's': issort = 1; break; case 'x': ftsoptions |= FTS_XDEV; break; case '?': default: usage(); } argc -= optind; argv += optind; if (Hflag) ftsoptions |= FTS_COMFOLLOW; if (Lflag) { ftsoptions &= ~FTS_PHYSICAL; ftsoptions |= FTS_LOGICAL; } /* * Find first option to delimit the file list. The first argument * that starts with a -, or is a ! or a ( must be interpreted as a * part of the find expression, according to POSIX .2. */ for (; *argv != NULL; *p++ = *argv++) { if (argv[0][0] == '-') break; if ((argv[0][0] == '!' || argv[0][0] == '(') && argv[0][1] == '\0') break; } if (p == start) usage(); *p = NULL; if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) < 0) ftsoptions |= FTS_NOCHDIR; exit(find_execute(find_formplan(argv), start)); }