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 71615 2001-01-25 03:40:17Z 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> --- 90 unchanged lines hidden (view full) --- 141 if (nargs == -1) 142 nargs = 1; 143 144 p = cmd; 145 offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]); 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); 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; --- 30 unchanged lines hidden (view full) --- 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 ((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'; 208 209 /* Run the command. */ 210 if (debug) --- 57 unchanged lines hidden --- |