summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index b876c0030..29e928886 100644
--- a/misc.c
+++ b/misc.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26#include "includes.h" 26#include "includes.h"
27RCSID("$OpenBSD: misc.c,v 1.41 2006/01/05 23:43:53 djm Exp $"); 27RCSID("$OpenBSD: misc.c,v 1.42 2006/01/31 10:19:02 djm Exp $");
28 28
29#ifdef SSH_TUN_OPENBSD 29#ifdef SSH_TUN_OPENBSD
30#include <net/if.h> 30#include <net/if.h>
@@ -391,12 +391,15 @@ void
391addargs(arglist *args, char *fmt, ...) 391addargs(arglist *args, char *fmt, ...)
392{ 392{
393 va_list ap; 393 va_list ap;
394 char buf[1024]; 394 char *cp;
395 u_int nalloc; 395 u_int nalloc;
396 int r;
396 397
397 va_start(ap, fmt); 398 va_start(ap, fmt);
398 vsnprintf(buf, sizeof(buf), fmt, ap); 399 r = vasprintf(&cp, fmt, ap);
399 va_end(ap); 400 va_end(ap);
401 if (r == -1)
402 fatal("addargs: argument too long");
400 403
401 nalloc = args->nalloc; 404 nalloc = args->nalloc;
402 if (args->list == NULL) { 405 if (args->list == NULL) {
@@ -407,10 +410,44 @@ addargs(arglist *args, char *fmt, ...)
407 410
408 args->list = xrealloc(args->list, nalloc * sizeof(char *)); 411 args->list = xrealloc(args->list, nalloc * sizeof(char *));
409 args->nalloc = nalloc; 412 args->nalloc = nalloc;
410 args->list[args->num++] = xstrdup(buf); 413 args->list[args->num++] = cp;
411 args->list[args->num] = NULL; 414 args->list[args->num] = NULL;
412} 415}
413 416
417void
418replacearg(arglist *args, u_int which, char *fmt, ...)
419{
420 va_list ap;
421 char *cp;
422 int r;
423
424 va_start(ap, fmt);
425 r = vasprintf(&cp, fmt, ap);
426 va_end(ap);
427 if (r == -1)
428 fatal("replacearg: argument too long");
429
430 if (which >= args->num)
431 fatal("replacearg: tried to replace invalid arg %d >= %d",
432 which, args->num);
433 xfree(args->list[which]);
434 args->list[which] = cp;
435}
436
437void
438freeargs(arglist *args)
439{
440 u_int i;
441
442 if (args->list != NULL) {
443 for (i = 0; i < args->num; i++)
444 xfree(args->list[i]);
445 xfree(args->list);
446 args->nalloc = args->num = 0;
447 args->list = NULL;
448 }
449}
450
414/* 451/*
415 * Expands tildes in the file name. Returns data allocated by xmalloc. 452 * Expands tildes in the file name. Returns data allocated by xmalloc.
416 * Warning: this calls getpw*. 453 * Warning: this calls getpw*.