Deleted Added
sdiff udiff text old ( 96785 ) new ( 97736 )
full compact
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Cimarron D. Taylor of the University of California, Berkeley.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 26 unchanged lines hidden (view full) ---

35 */
36
37#ifndef lint
38#if 0
39static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
40#endif
41#endif /* not lint */
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/usr.bin/find/function.c 96785 2002-05-17 05:11:07Z jmallett $");
44
45#include <sys/param.h>
46#include <sys/ucred.h>
47#include <sys/stat.h>
48#include <sys/wait.h>
49#include <sys/mount.h>
50#include <sys/timeb.h>
51
52#include <dirent.h>
53#include <err.h>
54#include <errno.h>
55#include <fnmatch.h>
56#include <fts.h>
57#include <grp.h>
58#include <pwd.h>
59#include <regex.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <unistd.h>
64
65#include "find.h"

--- 457 unchanged lines hidden (view full) ---

523 FTSENT *entry;
524{
525 extern int dotfd;
526 int cnt;
527 pid_t pid;
528 int status;
529 char *file;
530
531 /* XXX - if file/dir ends in '/' this will not work -- can it? */
532 if ((plan->flags & F_EXECDIR) && \
533 (file = strrchr(entry->fts_path, '/')))
534 file++;
535 else
536 file = entry->fts_path;
537
538 for (cnt = 0; plan->e_argv[cnt]; ++cnt)
539 if (plan->e_len[cnt])
540 brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
541 file, plan->e_len[cnt]);
542
543 if ((plan->flags & F_NEEDOK) && !queryuser(plan->e_argv))
544 return 0;
545
546 /* make sure find output is interspersed correctly with subprocesses */
547 fflush(stdout);
548 fflush(stderr);
549
550 switch (pid = fork()) {
551 case -1:

--- 4 unchanged lines hidden (view full) ---

556 if (!(plan->flags & F_EXECDIR) && fchdir(dotfd)) {
557 warn("chdir");
558 _exit(1);
559 }
560 execvp(plan->e_argv[0], plan->e_argv);
561 warn("%s", plan->e_argv[0]);
562 _exit(1);
563 }
564 pid = waitpid(pid, &status, 0);
565 return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
566}
567
568/*
569 * c_exec, c_execdir, c_ok --
570 * build three parallel arrays, one with pointers to the strings passed
571 * on the command line, one with (possibly duplicated) pointers to the
572 * argv array, and one with integer values that are lengths of the
573 * strings, but also flags meaning that the string has to be massaged.
574 */
575PLAN *
576c_exec(option, argvp)
577 OPTION *option;
578 char ***argvp;
579{
580 PLAN *new; /* node returned */
581 int cnt;
582 char **argv, **ap, *p;
583
584 /* XXX - was in c_execdir, but seems unnecessary!?
585 ftsoptions &= ~FTS_NOSTAT;
586 */
587 isoutput = 1;
588
589 /* XXX - this is a change from the previous coding */
590 new = palloc(option);
591
592 for (ap = argv = *argvp;; ++ap) {
593 if (!*ap)
594 errx(1,
595 "%s: no terminating \";\"", option->name);
596 if (**ap == ';')
597 break;
598 }
599
600 if (ap == argv)
601 errx(1, "%s: no command specified", option->name);
602
603 cnt = ap - *argvp + 1;
604 if ((new->e_argv = malloc(cnt * sizeof(char *))) == NULL)
605 err(1, NULL);
606 if ((new->e_orig = malloc(cnt * sizeof(char *))) == NULL)
607 err(1, NULL);
608 if ((new->e_len = malloc(cnt * sizeof(int))) == NULL)
609 err(1, NULL);
610
611 for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
612 new->e_orig[cnt] = *argv;
613 for (p = *argv; *p; ++p)
614 if (p[0] == '{' && p[1] == '}') {
615 if ((new->e_argv[cnt] =
616 malloc(MAXPATHLEN)) == NULL)
617 err(1, NULL);
618 new->e_len[cnt] = MAXPATHLEN;
619 break;
620 }
621 if (!*p) {
622 new->e_argv[cnt] = *argv;
623 new->e_len[cnt] = 0;
624 }
625 }
626 new->e_argv[cnt] = new->e_orig[cnt] = NULL;
627
628 *argvp = argv + 1;
629 return new;
630}
631
632int
633f_flags(plan, entry)
634 PLAN *plan;
635 FTSENT *entry;
636{

--- 909 unchanged lines hidden ---