diff options
author | Colin Watson <cjwatson@debian.org> | 2005-09-14 12:45:47 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2005-09-14 12:45:47 +0000 |
commit | 9b71add4cecf753c45f5fbd6ff0913bc95b3e95d (patch) | |
tree | d4ea8fdb30c7949c6433f5277c39548ea579d4dc /sftp.c | |
parent | ed07bcbea56007ab5b218ddf3aa6a7d4e21966e0 (diff) | |
parent | 16704d57999d987fb8d9ba53379841a79f016d67 (diff) |
Merge 4.2p1 to the trunk.
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 53 |
1 files changed, 34 insertions, 19 deletions
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | 18 | ||
19 | RCSID("$OpenBSD: sftp.c,v 1.63 2005/03/10 22:01:05 deraadt Exp $"); | 19 | RCSID("$OpenBSD: sftp.c,v 1.66 2005/08/08 13:22:48 jaredy Exp $"); |
20 | 20 | ||
21 | #ifdef USE_LIBEDIT | 21 | #ifdef USE_LIBEDIT |
22 | #include <histedit.h> | 22 | #include <histedit.h> |
@@ -404,7 +404,7 @@ get_pathname(const char **cpp, char **path) | |||
404 | { | 404 | { |
405 | const char *cp = *cpp, *end; | 405 | const char *cp = *cpp, *end; |
406 | char quot; | 406 | char quot; |
407 | int i, j; | 407 | u_int i, j; |
408 | 408 | ||
409 | cp += strspn(cp, WHITESPACE); | 409 | cp += strspn(cp, WHITESPACE); |
410 | if (!*cp) { | 410 | if (!*cp) { |
@@ -664,14 +664,15 @@ sdirent_comp(const void *aa, const void *bb) | |||
664 | static int | 664 | static int |
665 | do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) | 665 | do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) |
666 | { | 666 | { |
667 | int n, c = 1, colspace = 0, columns = 1; | 667 | int n; |
668 | u_int c = 1, colspace = 0, columns = 1; | ||
668 | SFTP_DIRENT **d; | 669 | SFTP_DIRENT **d; |
669 | 670 | ||
670 | if ((n = do_readdir(conn, path, &d)) != 0) | 671 | if ((n = do_readdir(conn, path, &d)) != 0) |
671 | return (n); | 672 | return (n); |
672 | 673 | ||
673 | if (!(lflag & LS_SHORT_VIEW)) { | 674 | if (!(lflag & LS_SHORT_VIEW)) { |
674 | int m = 0, width = 80; | 675 | u_int m = 0, width = 80; |
675 | struct winsize ws; | 676 | struct winsize ws; |
676 | char *tmp; | 677 | char *tmp; |
677 | 678 | ||
@@ -747,7 +748,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, | |||
747 | int lflag) | 748 | int lflag) |
748 | { | 749 | { |
749 | glob_t g; | 750 | glob_t g; |
750 | int i, c = 1, colspace = 0, columns = 1; | 751 | u_int i, c = 1, colspace = 0, columns = 1; |
751 | Attrib *a = NULL; | 752 | Attrib *a = NULL; |
752 | 753 | ||
753 | memset(&g, 0, sizeof(g)); | 754 | memset(&g, 0, sizeof(g)); |
@@ -783,7 +784,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, | |||
783 | } | 784 | } |
784 | 785 | ||
785 | if (!(lflag & LS_SHORT_VIEW)) { | 786 | if (!(lflag & LS_SHORT_VIEW)) { |
786 | int m = 0, width = 80; | 787 | u_int m = 0, width = 80; |
787 | struct winsize ws; | 788 | struct winsize ws; |
788 | 789 | ||
789 | /* Count entries for sort and find longest filename */ | 790 | /* Count entries for sort and find longest filename */ |
@@ -1236,7 +1237,7 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) | |||
1236 | char *dir = NULL; | 1237 | char *dir = NULL; |
1237 | char cmd[2048]; | 1238 | char cmd[2048]; |
1238 | struct sftp_conn *conn; | 1239 | struct sftp_conn *conn; |
1239 | int err; | 1240 | int err, interactive; |
1240 | EditLine *el = NULL; | 1241 | EditLine *el = NULL; |
1241 | #ifdef USE_LIBEDIT | 1242 | #ifdef USE_LIBEDIT |
1242 | History *hl = NULL; | 1243 | History *hl = NULL; |
@@ -1294,14 +1295,15 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) | |||
1294 | xfree(dir); | 1295 | xfree(dir); |
1295 | } | 1296 | } |
1296 | 1297 | ||
1297 | #if HAVE_SETVBUF | 1298 | #if defined(HAVE_SETVBUF) && !defined(BROKEN_SETVBUF) |
1298 | setvbuf(stdout, NULL, _IOLBF, 0); | 1299 | setvbuf(stdout, NULL, _IOLBF, 0); |
1299 | setvbuf(infile, NULL, _IOLBF, 0); | 1300 | setvbuf(infile, NULL, _IOLBF, 0); |
1300 | #else | 1301 | #else |
1301 | setlinebuf(stdout); | 1302 | setlinebuf(stdout); |
1302 | setlinebuf(infile); | 1303 | setlinebuf(infile); |
1303 | #endif | 1304 | #endif |
1304 | 1305 | ||
1306 | interactive = !batchmode && isatty(STDIN_FILENO); | ||
1305 | err = 0; | 1307 | err = 0; |
1306 | for (;;) { | 1308 | for (;;) { |
1307 | char *cp; | 1309 | char *cp; |
@@ -1309,20 +1311,28 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) | |||
1309 | signal(SIGINT, SIG_IGN); | 1311 | signal(SIGINT, SIG_IGN); |
1310 | 1312 | ||
1311 | if (el == NULL) { | 1313 | if (el == NULL) { |
1312 | printf("sftp> "); | 1314 | if (interactive) |
1315 | printf("sftp> "); | ||
1313 | if (fgets(cmd, sizeof(cmd), infile) == NULL) { | 1316 | if (fgets(cmd, sizeof(cmd), infile) == NULL) { |
1314 | printf("\n"); | 1317 | if (interactive) |
1318 | printf("\n"); | ||
1315 | break; | 1319 | break; |
1316 | } | 1320 | } |
1317 | if (batchmode) /* Echo command */ | 1321 | if (!interactive) { /* Echo command */ |
1318 | printf("%s", cmd); | 1322 | printf("sftp> %s", cmd); |
1323 | if (strlen(cmd) > 0 && | ||
1324 | cmd[strlen(cmd) - 1] != '\n') | ||
1325 | printf("\n"); | ||
1326 | } | ||
1319 | } else { | 1327 | } else { |
1320 | #ifdef USE_LIBEDIT | 1328 | #ifdef USE_LIBEDIT |
1321 | const char *line; | 1329 | const char *line; |
1322 | int count = 0; | 1330 | int count = 0; |
1323 | 1331 | ||
1324 | if ((line = el_gets(el, &count)) == NULL || count <= 0) | 1332 | if ((line = el_gets(el, &count)) == NULL || count <= 0) { |
1325 | break; | 1333 | printf("\n"); |
1334 | break; | ||
1335 | } | ||
1326 | history(hl, &hev, H_ENTER, line); | 1336 | history(hl, &hev, H_ENTER, line); |
1327 | if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { | 1337 | if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { |
1328 | fprintf(stderr, "Error: input line too long\n"); | 1338 | fprintf(stderr, "Error: input line too long\n"); |
@@ -1345,6 +1355,11 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) | |||
1345 | } | 1355 | } |
1346 | xfree(pwd); | 1356 | xfree(pwd); |
1347 | 1357 | ||
1358 | #ifdef USE_LIBEDIT | ||
1359 | if (el != NULL) | ||
1360 | el_end(el); | ||
1361 | #endif /* USE_LIBEDIT */ | ||
1362 | |||
1348 | /* err == 1 signifies normal "quit" exit */ | 1363 | /* err == 1 signifies normal "quit" exit */ |
1349 | return (err >= 0 ? 0 : -1); | 1364 | return (err >= 0 ? 0 : -1); |
1350 | } | 1365 | } |
@@ -1475,7 +1490,7 @@ main(int argc, char **argv) | |||
1475 | 1490 | ||
1476 | /* Allow "-" as stdin */ | 1491 | /* Allow "-" as stdin */ |
1477 | if (strcmp(optarg, "-") != 0 && | 1492 | if (strcmp(optarg, "-") != 0 && |
1478 | (infile = fopen(optarg, "r")) == NULL) | 1493 | (infile = fopen(optarg, "r")) == NULL) |
1479 | fatal("%s (%s).", strerror(errno), optarg); | 1494 | fatal("%s (%s).", strerror(errno), optarg); |
1480 | showprogress = 0; | 1495 | showprogress = 0; |
1481 | batchmode = 1; | 1496 | batchmode = 1; |
@@ -1561,8 +1576,8 @@ main(int argc, char **argv) | |||
1561 | err = interactive_loop(in, out, file1, file2); | 1576 | err = interactive_loop(in, out, file1, file2); |
1562 | 1577 | ||
1563 | #if !defined(USE_PIPES) | 1578 | #if !defined(USE_PIPES) |
1564 | shutdown(in, SHUT_RDWR); | 1579 | shutdown(in, SHUT_RDWR); |
1565 | shutdown(out, SHUT_RDWR); | 1580 | shutdown(out, SHUT_RDWR); |
1566 | #endif | 1581 | #endif |
1567 | 1582 | ||
1568 | close(in); | 1583 | close(in); |