+
+ /*
+ * If there were any %digit references, then
+ * simply use those, otherwise build a new command
+ * string with sufficient %digit references at
+ * the end to consume (nargs) arguments each time
+ * round the loop.
+ */
+ c = malloc(sizeof("exec") + strlen(cmd) + 3 * nargs + 1);
+ if (c == NULL)
+ err(1, NULL);
+
+ if (n > 0) {
+ (void)sprintf(c, "exec %s", cmd);
+ nargs = n;
+ } else {
+ int i;
+
+ p = c;
+ p += sprintf(c, "exec %s", cmd);
+ for (i = 1; i <= nargs; i++)
+ p += sprintf(p, " %c%d", magic, i);