summaryrefslogtreecommitdiff
path: root/scp.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-05-08 20:27:25 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-05-08 20:27:25 +0000
commit387c472660ef173c2e469e70eb1a25d47f6e8887 (patch)
tree4686516a373bbb5ca9594c4cb285aedc6a72aa8d /scp.c
parent69128668938c82e8d428e77726ef00b2b6f799b9 (diff)
- mouring@cvs.openbsd.org 2001/05/08 19:45:25
[misc.c misc.h scp.c sftp.c] Use addargs() in sftp plus some clean up of addargs(). OK Markus
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c55
1 files changed, 13 insertions, 42 deletions
diff --git a/scp.c b/scp.c
index 10b77af6..52fd513c 100644
--- a/scp.c
+++ b/scp.c
@@ -75,7 +75,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.69 2001/05/03 23:09:53 mouring Exp $");
+RCSID("$OpenBSD: scp.c,v 1.70 2001/05/08 19:45:24 mouring Exp $");
#include "xmalloc.h"
#include "atomicio.h"
@@ -107,8 +107,8 @@ void progressmeter(int);
int getttywidth(void);
int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc);
-/* setup arguments for the call to ssh */
-void addargs(char *fmt, ...) __attribute__((format(printf, 1, 2)));
+/* Struct for addargs */
+arglist args;
/* Time a transfer started. */
static struct timeval start;
@@ -131,13 +131,6 @@ int showprogress = 1;
/* This is the program to execute for the secured connection. ("ssh" or -S) */
char *ssh_program = _PATH_SSH_PROGRAM;
-/* This is the list of arguments that scp passes to ssh */
-struct {
- char **list;
- int num;
- int nalloc;
-} args;
-
/*
* This function executes the given command as the specified user on the
* given host. This returns < 0 if execution fails, and >= 0 otherwise. This
@@ -181,9 +174,9 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
args.list[0] = ssh_program;
if (remuser != NULL)
- addargs("-l%s", remuser);
- addargs("%s", host);
- addargs("%s", cmd);
+ addargs(&args, "-l%s", remuser);
+ addargs(&args, "%s", host);
+ addargs(&args, "%s", cmd);
execvp(ssh_program, args.list);
perror(ssh_program);
@@ -238,9 +231,9 @@ main(argc, argv)
__progname = get_progname(argv[0]);
args.list = NULL;
- addargs("ssh"); /* overwritten with ssh_program */
- addargs("-x");
- addargs("-oFallBackToRsh no");
+ addargs(&args, "ssh"); /* overwritten with ssh_program */
+ addargs(&args, "-x");
+ addargs(&args, "-oFallBackToRsh no");
fflag = tflag = 0;
while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != -1)
@@ -249,18 +242,18 @@ main(argc, argv)
case '4':
case '6':
case 'C':
- addargs("-%c", ch);
+ addargs(&args, "-%c", ch);
break;
case 'o':
case 'c':
case 'i':
- addargs("-%c%s", ch, optarg);
+ addargs(&args, "-%c%s", ch, optarg);
break;
case 'P':
- addargs("-p%s", optarg);
+ addargs(&args, "-p%s", optarg);
break;
case 'B':
- addargs("-oBatchmode yes");
+ addargs(&args, "-oBatchmode yes");
break;
case 'p':
pflag = 1;
@@ -1212,25 +1205,3 @@ getttywidth(void)
else
return (80);
}
-
-void
-addargs(char *fmt, ...)
-{
- va_list ap;
- char buf[1024];
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
-
- if (args.list == NULL) {
- args.nalloc = 32;
- args.num = 0;
- args.list = xmalloc(args.nalloc * sizeof(char *));
- } else if (args.num+2 >= args.nalloc) {
- args.nalloc *= 2;
- args.list = xrealloc(args.list, args.nalloc * sizeof(char *));
- }
- args.list[args.num++] = xstrdup(buf);
- args.list[args.num] = NULL;
-}