Deleted Added
full compact
apply.c (82051) apply.c (82057)
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 82051 2001-08-21 11:24:53Z brian $";
42 "$FreeBSD: head/usr.bin/apply/apply.c 82057 2001-08-21 12:54:15Z brian $";
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>

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

138
139 if (n == 0) {
140 /* If nargs not set, default to a single argument. */
141 if (nargs == -1)
142 nargs = 1;
143
144 p = cmd;
145 offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]);
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>

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

138
139 if (n == 0) {
140 /* If nargs not set, default to a single argument. */
141 if (nargs == -1)
142 nargs = 1;
143
144 p = cmd;
145 offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]);
146 if (offset < 0 || offset >= cmdsize)
146 if ((size_t)offset >= cmdsize)
147 err(1, "snprintf() failed");
148 p += offset;
149 cmdsize -= offset;
150 for (i = 1; i <= nargs; i++) {
151 offset = snprintf(p, cmdsize, " %c%d", magic, i);
147 err(1, "snprintf() failed");
148 p += offset;
149 cmdsize -= offset;
150 for (i = 1; i <= nargs; i++) {
151 offset = snprintf(p, cmdsize, " %c%d", magic, i);
152 if (offset < 0 || offset >= cmdsize)
152 if ((size_t)offset >= cmdsize)
153 err(1, "snprintf() failed");
154 p += offset;
155 cmdsize -= offset;
156 }
157
158 /*
159 * If nargs set to the special value 0, eat a single
160 * argument for each command execution.
161 */
162 if (nargs == 0)
163 nargs = 1;
164 } else {
165 offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]);
153 err(1, "snprintf() failed");
154 p += offset;
155 cmdsize -= offset;
156 }
157
158 /*
159 * If nargs set to the special value 0, eat a single
160 * argument for each command execution.
161 */
162 if (nargs == 0)
163 nargs = 1;
164 } else {
165 offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]);
166 if (offset < 0 || offset >= cmdsize)
166 if ((size_t)offset >= cmdsize)
167 err(1, "snprintf() failed");
168 nargs = n;
169 }
170
171 /*
172 * Grab some space in which to build the command. Allocate
173 * as necessary later, but no reason to build it up slowly
174 * for the normal case.

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

191 if (l > clen && (c = realloc(c, clen = l)) == NULL)
192 err(1, NULL);
193
194 /* Expand command argv references. */
195 for (p = cmd, q = c; *p != '\0'; ++p)
196 if (p[0] == magic && isdigit(p[1]) && p[1] != '0') {
197 offset = snprintf(q, l, "%s",
198 argv[(++p)[0] - '0']);
167 err(1, "snprintf() failed");
168 nargs = n;
169 }
170
171 /*
172 * Grab some space in which to build the command. Allocate
173 * as necessary later, but no reason to build it up slowly
174 * for the normal case.

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

191 if (l > clen && (c = realloc(c, clen = l)) == NULL)
192 err(1, NULL);
193
194 /* Expand command argv references. */
195 for (p = cmd, q = c; *p != '\0'; ++p)
196 if (p[0] == magic && isdigit(p[1]) && p[1] != '0') {
197 offset = snprintf(q, l, "%s",
198 argv[(++p)[0] - '0']);
199 if (offset < 0 || offset >= l)
199 if ((size_t)offset >= l)
200 err(1, "snprintf() failed");
201 q += offset;
202 l -= offset;
203 } else
204 *q++ = *p;
205
206 /* Terminate the command string. */
207 *q = '\0';

--- 60 unchanged lines hidden ---
200 err(1, "snprintf() failed");
201 q += offset;
202 l -= offset;
203 } else
204 *q++ = *p;
205
206 /* Terminate the command string. */
207 *q = '\0';

--- 60 unchanged lines hidden ---