Skip to content

Commit 58a5828

Browse files
committed
Fix formatting issues with prompt/memory release.
1 parent 2417559 commit 58a5828

File tree

5 files changed

+168
-27
lines changed

5 files changed

+168
-27
lines changed
32 KB
Binary file not shown.

contrib/win32/win32compat/fileio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ fileio_fstat(struct w32_io* pio, struct _stat64 *buf) {
559559

560560
int
561561
fileio_stat(const char *path, struct _stat64 *buf) {
562-
wchar_t* wpath[MAX_PATH];
562+
wchar_t wpath[MAX_PATH];
563563
wchar_t* wtmp = NULL;
564564

565565
if ((wtmp = utf8_to_utf16(path)) == NULL)
566566
fatal("failed to covert input arguments");
567-
strcpy(wpath, wtmp);
567+
wcscpy(&wpath[0], wtmp);
568568
free(wtmp);
569569

570570
return _wstat64(wpath, buf);

contrib/win32/win32compat/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ utf16_to_utf8(const wchar_t* utf16) {
140140
WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, needed, NULL, NULL) == 0)
141141
return NULL;
142142
return utf8;
143-
}
143+
}

contrib/win32/win32compat/w32fd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <errno.h>
3737
#include <time.h>
3838
#include <assert.h>
39+
#include <direct.h>
3940

4041
/* internal table that stores the fd to w32_io mapping*/
4142
struct w32fd_table {
@@ -438,11 +439,14 @@ int w32_chdir(const char *dirname_utf8) {
438439

439440
char *w32_getcwd(char *buffer, int maxlen) {
440441
wchar_t wdirname[MAX_PATH];
442+
char* putf8 = NULL;
441443

442-
wchar_t *wpwd = _wgetcwd(wdirname, MAX_PATH);
444+
wchar_t *wpwd = _wgetcwd(&wdirname[0], MAX_PATH);
443445

444-
if (buffer = utf16_to_utf8(wpwd))
446+
if ((putf8 = utf16_to_utf8(&wdirname[0])) == NULL)
445447
fatal("failed to convert input arguments");
448+
strcpy(buffer, putf8);
449+
free(putf8);
446450

447451
return buffer;
448452
}

sftp.c

Lines changed: 159 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,38 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd,
655655
free(tmp);
656656

657657
resume |= global_aflag;
658-
if (!quiet && resume)
658+
if (!quiet && resume)
659+
#ifdef WINDOWS
660+
{
661+
printf("Resuming ");
662+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
663+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
664+
printf(" to ");
665+
free(wtmp);
666+
wtmp = utf8_to_utf16(abs_dst);
667+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
668+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
669+
free(wtmp);
670+
}
671+
#else
659672
printf("Resuming %s to %s\n", g.gl_pathv[i], abs_dst);
660-
else if (!quiet && !resume)
661-
printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst);
673+
#endif
674+
else if (!quiet && !resume)
675+
#ifdef WINDOWS
676+
{
677+
printf("Fetching ");
678+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
679+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
680+
printf(" to ");
681+
free(wtmp);
682+
wtmp = utf8_to_utf16(abs_dst);
683+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
684+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
685+
free(wtmp);
686+
}
687+
#else
688+
printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst);
689+
#endif
662690
if (pathname_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) {
663691
if (download_dir(conn, g.gl_pathv[i], abs_dst, NULL,
664692
pflag || global_pflag, 1, resume,
@@ -745,12 +773,40 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd,
745773
}
746774
free(tmp);
747775

748-
resume |= global_aflag;
776+
resume |= global_aflag;
749777
if (!quiet && resume)
778+
#ifdef WINDOWS
779+
{
780+
printf("Resuming upload of ");
781+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
782+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
783+
printf(" to ");
784+
free(wtmp);
785+
wtmp = utf8_to_utf16(abs_dst);
786+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
787+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
788+
free(wtmp);
789+
}
790+
#else
750791
printf("Resuming upload of %s to %s\n", g.gl_pathv[i],
751792
abs_dst);
793+
#endif
752794
else if (!quiet && !resume)
795+
#ifdef WINDOWS
796+
{
797+
printf("Uploading ");
798+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
799+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
800+
printf(" to ");
801+
free(wtmp);
802+
wtmp = utf8_to_utf16(abs_dst);
803+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
804+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
805+
free(wtmp);
806+
}
807+
#else
753808
printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst);
809+
#endif
754810
if (pathname_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) {
755811
if (upload_dir(conn, g.gl_pathv[i], abs_dst,
756812
pflag || global_pflag, 1, resume,
@@ -857,8 +913,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
857913
wchar_t* wtmp = utf8_to_utf16(lname);
858914
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
859915
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
860-
861-
free(tmp);
916+
free(wtmp);
862917
#else
863918
printf("%s\n", lname);
864919
#endif
@@ -969,11 +1024,26 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
9691024
}
9701025
lname = ls_file(fname, g.gl_statv[i], 1,
9711026
(lflag & LS_SI_UNITS));
972-
printf("%s\n", lname);
973-
free(lname);
1027+
#ifdef WINDOWS
1028+
wchar_t* wtmp = utf8_to_utf16(lname);
1029+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1030+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1031+
free(wtmp);
1032+
#else
1033+
printf("%s\n", lname);
1034+
#endif
1035+
free(lname);
9741036
} else {
975-
printf("%-*s", colspace, fname);
976-
if (c >= columns) {
1037+
#ifdef WINDOWS
1038+
wchar_t* wtmp = utf8_to_utf16(fname);
1039+
// TODO: Deal with the sizing wprintf_s(L"%-*s", colspace, wtmp);
1040+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1041+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L" ", 1, 0, 0);
1042+
free(wtmp);
1043+
#else
1044+
printf("%-*s", colspace, fname);
1045+
#endif
1046+
if (c >= columns) {
9771047
printf("\n");
9781048
c = 1;
9791049
} else
@@ -1500,8 +1570,18 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
15001570
path1 = make_absolute(path1, *pwd);
15011571
remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
15021572
for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1503-
if (!quiet)
1504-
printf("Removing %s\n", g.gl_pathv[i]);
1573+
if (!quiet)
1574+
#ifdef WINDOWS
1575+
{
1576+
printf("Removing ");
1577+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
1578+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1579+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1580+
free(wtmp);
1581+
}
1582+
#else
1583+
printf("Removing %s\n", g.gl_pathv[i]);
1584+
#endif
15051585
err = do_rm(conn, g.gl_pathv[i]);
15061586
if (err != 0 && err_abort)
15071587
break;
@@ -1601,7 +1681,17 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
16011681
remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
16021682
for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
16031683
if (!quiet)
1604-
printf("Changing mode on %s\n", g.gl_pathv[i]);
1684+
#ifdef WINDOWS
1685+
{
1686+
printf("Changing mode on ");
1687+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
1688+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1689+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1690+
free(wtmp);
1691+
}
1692+
#else
1693+
printf("Changing mode on %s\n", g.gl_pathv[i]);
1694+
#endif
16051695
err = do_setstat(conn, g.gl_pathv[i], &a);
16061696
if (err != 0 && err_abort)
16071697
break;
@@ -1631,13 +1721,33 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
16311721
aa->flags &= SSH2_FILEXFER_ATTR_UIDGID;
16321722
if (cmdnum == I_CHOWN) {
16331723
if (!quiet)
1634-
printf("Changing owner on %s\n",
1635-
g.gl_pathv[i]);
1724+
#ifdef WINDOWS
1725+
{
1726+
printf("Changing owner on ");
1727+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
1728+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1729+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1730+
free(wtmp);
1731+
}
1732+
#else
1733+
printf("Changing owner on %s\n",
1734+
g.gl_pathv[i]);
1735+
#endif
16361736
aa->uid = n_arg;
16371737
} else {
16381738
if (!quiet)
1639-
printf("Changing group on %s\n",
1640-
g.gl_pathv[i]);
1739+
#ifdef WINDOWS
1740+
{
1741+
printf("Changing group on ");
1742+
wchar_t* wtmp = utf8_to_utf16(g.gl_pathv[i]);
1743+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1744+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1745+
free(wtmp);
1746+
}
1747+
#else
1748+
printf("Changing group on %s\n",
1749+
g.gl_pathv[i]);
1750+
#endif
16411751
aa->gid = n_arg;
16421752
}
16431753
err = do_setstat(conn, g.gl_pathv[i], aa);
@@ -1646,18 +1756,35 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
16461756
}
16471757
break;
16481758
case I_PWD:
1759+
#ifdef WINDOWS
16491760
printf("Remote working directory: ");
1650-
wchar_t* wtmp = utf8_to_utf16(*pwd);
1651-
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1652-
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1761+
{
1762+
wchar_t* wtmp = utf8_to_utf16(*pwd);
1763+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1764+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1765+
free(wtmp);
1766+
}
1767+
#else
1768+
printf("Remote working directory: %s\n", *pwd);
1769+
#endif
16531770
break;
16541771
case I_LPWD:
16551772
if (!getcwd(path_buf, sizeof(path_buf))) {
16561773
error("Couldn't get local cwd: %s", strerror(errno));
16571774
err = -1;
16581775
break;
16591776
}
1660-
printf("Local working directory: %s\n", path_buf);
1777+
#ifdef WINDOWS
1778+
printf("Local working directory: ");
1779+
{
1780+
wchar_t* wtmp = utf8_to_utf16(path_buf);
1781+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1782+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
1783+
free(wtmp);
1784+
}
1785+
#else
1786+
printf("Local working directory: %s\n", path_buf);
1787+
#endif
16611788
break;
16621789
case I_QUIT:
16631790
/* Processed below */
@@ -2110,7 +2237,17 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
21102237

21112238
if (remote_is_dir(conn, dir) && file2 == NULL) {
21122239
if (!quiet)
2113-
printf("Changing to: %s\n", dir);
2240+
#ifdef WINDOWS
2241+
{
2242+
printf("Changing to: ");
2243+
wchar_t* wtmp = utf8_to_utf16(dir);
2244+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
2245+
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
2246+
free(wtmp);
2247+
}
2248+
#else
2249+
printf("Changing to: %s\n", dir);
2250+
#endif
21142251
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
21152252
if (parse_dispatch_command(conn, cmd,
21162253
&remote_path, 1) != 0) {

0 commit comments

Comments
 (0)