Deleted Added
full compact
apply.c (70692) apply.c (71326)
1/*-
2 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Jan-Simon Pendry.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static const char sccsid[] = "@(#)apply.c 8.4 (Berkeley) 4/4/94";
40#endif
41static const char rcsid[] =
1/*-
2 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Jan-Simon Pendry.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static const char sccsid[] = "@(#)apply.c 8.4 (Berkeley) 4/4/94";
40#endif
41static const char rcsid[] =
42 "$FreeBSD: head/usr.bin/apply/apply.c 70692 2001-01-05 18:15:17Z will $";
42 "$FreeBSD: head/usr.bin/apply/apply.c 71326 2001-01-21 08:37:35Z will $";
43#endif /* not lint */
44
45#include <sys/types.h>
46
47#include <sys/wait.h>
48
49#include <ctype.h>
50#include <err.h>
51#include <paths.h>
52#include <signal.h>
53#include <stdio.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57
43#endif /* not lint */
44
45#include <sys/types.h>
46
47#include <sys/wait.h>
48
49#include <ctype.h>
50#include <err.h>
51#include <paths.h>
52#include <signal.h>
53#include <stdio.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57
58void usage(void);
59static int exec_shell(char *, char *, const char *);
58#define EXEC "exec "
60
59
61#define EXEC "exec "
60static int exec_shell(const char *, char *, char *);
61static void usage(void);
62
63int
62
63int
64main(int argc, char **argv) {
65 int ch, debug, i, magic, n, nargs, rval, offset;
66 size_t clen, l, cmdsize;
67 char *c, *cmd, *p, *q, *shell, *name, *tmpshell, *slashp;
64main(int argc, char *argv[]) {
65 int ch, debug, i, magic, n, nargs, offset, rval;
66 size_t clen, cmdsize, l;
67 char *c, *cmd, *name, *p, *q, *shell, *slashp, *tmpshell;
68
69 debug = 0;
70 magic = '%'; /* Default magic char is `%'. */
71 nargs = -1;
72 while ((ch = getopt(argc, argv, "a:d0123456789")) != -1)
73 switch (ch) {
74 case 'a':
75 if (optarg[1] != '\0')

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

126
127 /*
128 * If there were any %digit references, then use those, otherwise
129 * build a new command string with sufficient %digit references at
130 * the end to consume (nargs) arguments each time round the loop.
131 * Allocate enough space to hold the maximum command. Save the
132 * size to pass to snprintf().
133 */
68
69 debug = 0;
70 magic = '%'; /* Default magic char is `%'. */
71 nargs = -1;
72 while ((ch = getopt(argc, argv, "a:d0123456789")) != -1)
73 switch (ch) {
74 case 'a':
75 if (optarg[1] != '\0')

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

126
127 /*
128 * If there were any %digit references, then use those, otherwise
129 * build a new command string with sufficient %digit references at
130 * the end to consume (nargs) arguments each time round the loop.
131 * Allocate enough space to hold the maximum command. Save the
132 * size to pass to snprintf().
133 */
134 cmdsize = sizeof(EXEC) - 1 + strlen(argv[0]) + 9 *
135 (sizeof(" %1") - 1) + 1;
134 cmdsize = sizeof(EXEC) - 1 + strlen(argv[0])
135 + 9 * (sizeof(" %1") - 1) + 1;
136 if ((cmd = malloc(cmdsize)) == NULL)
137 err(1, NULL);
138
139 if (n == 0) {
140 /* If nargs not set, default to a single argument. */
141 if (nargs == -1)
142 nargs = 1;
143

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

202
203 /* Terminate the command string. */
204 *q = '\0';
205
206 /* Run the command. */
207 if (debug)
208 (void)printf("%s\n", c);
209 else
136 if ((cmd = malloc(cmdsize)) == NULL)
137 err(1, NULL);
138
139 if (n == 0) {
140 /* If nargs not set, default to a single argument. */
141 if (nargs == -1)
142 nargs = 1;
143

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

202
203 /* Terminate the command string. */
204 *q = '\0';
205
206 /* Run the command. */
207 if (debug)
208 (void)printf("%s\n", c);
209 else
210 if (exec_shell(shell, name, c))
210 if (exec_shell(c, shell, name))
211 rval = 1;
212 }
213
214 if (argc != 1)
215 errx(1, "expecting additional argument%s after \"%s\"",
216 (nargs - argc) ? "s" : "", argv[argc - 1]);
211 rval = 1;
212 }
213
214 if (argc != 1)
215 errx(1, "expecting additional argument%s after \"%s\"",
216 (nargs - argc) ? "s" : "", argv[argc - 1]);
217
218 free(cmd);
219 free(c);
220 free(shell);
221 exit(rval);
222}
223
224/*
225 * exec_shell --
226 * Execute a shell command using passed use_shell and use_name
227 * arguments.
228 */
229static int
217 free(cmd);
218 free(c);
219 free(shell);
220 exit(rval);
221}
222
223/*
224 * exec_shell --
225 * Execute a shell command using passed use_shell and use_name
226 * arguments.
227 */
228static int
230exec_shell(char *use_shell, char *use_name, const char *command)
229exec_shell(const char *command, char *use_shell, char *use_name)
231{
232 pid_t pid;
233 int omask, pstat;
234 sig_t intsave, quitsave;
235
236 if (!command) /* just checking... */
237 return(1);
238

--- 27 unchanged lines hidden ---
230{
231 pid_t pid;
232 int omask, pstat;
233 sig_t intsave, quitsave;
234
235 if (!command) /* just checking... */
236 return(1);
237

--- 27 unchanged lines hidden ---