function.c (9d08e419b97c8747fa74185cdaa16768f7d1b32e) | function.c (127d7563c4779d9be231b4657388dd55622139a4) |
---|---|
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 --- 298 unchanged lines hidden (view full) --- 307 new->e_len[cnt] = 0; 308 } 309 } 310 new->e_argv[cnt] = new->e_orig[cnt] = NULL; 311 312 *argvp = argv + 1; 313 return (new); 314} | 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 --- 298 unchanged lines hidden (view full) --- 307 new->e_len[cnt] = 0; 308 } 309 } 310 new->e_argv[cnt] = new->e_orig[cnt] = NULL; 311 312 *argvp = argv + 1; 313 return (new); 314} |
315 316/* 317 * -execdir utility [arg ... ] ; functions -- 318 * 319 * True if the executed utility returns a zero value as exit status. 320 * The end of the primary expression is delimited by a semicolon. If 321 * "{}" occurs anywhere, it gets replaced by the unqualified pathname. 322 * The current directory for the execution of utility is the same as 323 * the directory where the file lives. 324 */ 325int 326f_execdir(plan, entry) 327 register PLAN *plan; 328 FTSENT *entry; 329{ 330 extern int dotfd; 331 register int cnt; 332 pid_t pid; 333 int status; 334 char *file; |
|
315 | 335 |
336 /* XXX - if file/dir ends in '/' this will not work -- can it? */ 337 if ((file = strrchr(entry->fts_path, '/'))) 338 file++; 339 else 340 file = entry->fts_path; 341 342 for (cnt = 0; plan->e_argv[cnt]; ++cnt) 343 if (plan->e_len[cnt]) 344 brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt], 345 file, plan->e_len[cnt]); 346 347 /* don't mix output of command with find output */ 348 fflush(stdout); 349 fflush(stderr); 350 351 switch (pid = vfork()) { 352 case -1: 353 err(1, "fork"); 354 /* NOTREACHED */ 355 case 0: 356 execvp(plan->e_argv[0], plan->e_argv); 357 warn("%s", plan->e_argv[0]); 358 _exit(1); 359 } 360 pid = waitpid(pid, &status, 0); 361 return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status)); 362} 363 |
|
316/* | 364/* |
365 * c_execdir -- 366 * build three parallel arrays, one with pointers to the strings passed 367 * on the command line, one with (possibly duplicated) pointers to the 368 * argv array, and one with integer values that are lengths of the 369 * strings, but also flags meaning that the string has to be massaged. 370 */ 371PLAN * 372c_execdir(argvp) 373 char ***argvp; 374{ 375 PLAN *new; /* node returned */ 376 register int cnt; 377 register char **argv, **ap, *p; 378 379 ftsoptions &= ~FTS_NOSTAT; 380 isoutput = 1; 381 382 new = palloc(N_EXECDIR, f_execdir); 383 384 for (ap = argv = *argvp;; ++ap) { 385 if (!*ap) 386 errx(1, 387 "-execdir: no terminating \";\""); 388 if (**ap == ';') 389 break; 390 } 391 392 cnt = ap - *argvp + 1; 393 new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *)); 394 new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *)); 395 new->e_len = (int *)emalloc((u_int)cnt * sizeof(int)); 396 397 for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) { 398 new->e_orig[cnt] = *argv; 399 for (p = *argv; *p; ++p) 400 if (p[0] == '{' && p[1] == '}') { 401 new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN); 402 new->e_len[cnt] = MAXPATHLEN; 403 break; 404 } 405 if (!*p) { 406 new->e_argv[cnt] = *argv; 407 new->e_len[cnt] = 0; 408 } 409 } 410 new->e_argv[cnt] = new->e_orig[cnt] = NULL; 411 412 *argvp = argv + 1; 413 return (new); 414} 415 416/* |
|
317 * -follow functions -- 318 * 319 * Always true, causes symbolic links to be followed on a global 320 * basis. 321 */ 322PLAN * 323c_follow() 324{ --- 817 unchanged lines hidden --- | 417 * -follow functions -- 418 * 419 * Always true, causes symbolic links to be followed on a global 420 * basis. 421 */ 422PLAN * 423c_follow() 424{ --- 817 unchanged lines hidden --- |