Skip to content

Commit b7d80ed

Browse files
committed
SFTP issues.
1 parent 9291dde commit b7d80ed

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

contrib/win32/win32compat/fileio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,13 @@ 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];
563+
wchar_t* wtmp = NULL;
563564

564-
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH) == 0) {
565-
errno = EFAULT;
566-
debug("WideCharToMultiByte failed - ERROR:%d", GetLastError());
567-
return GetLastError();
568-
}
565+
if ((wtmp = utf8_to_utf16(path)) == NULL)
566+
fatal("failed to covert input arguments");
567+
strcpy(wpath, wtmp);
568+
free(wtmp);
569569

570570
return _wstat64(wpath, buf);
571571
}

contrib/win32/win32compat/w32fd.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,10 @@ int w32_chdir(const char *dirname_utf8) {
438438

439439
char *w32_getcwd(char *buffer, int maxlen) {
440440
wchar_t wdirname[MAX_PATH];
441-
int needed;
442441

443442
wchar_t *wpwd = _wgetcwd(wdirname, MAX_PATH);
444443

445-
if ((needed = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wdirname, -1, NULL, 0, NULL, NULL)) == 0 ||
446-
(needed > MAX_PATH) ||
447-
(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wdirname, -1, buffer, needed, NULL, NULL) != needed))
444+
if (buffer = utf16_to_utf8(wpwd))
448445
fatal("failed to convert input arguments");
449446

450447
return buffer;

sftp.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef void EditLine;
7676

7777
#ifdef WIN32_VS
7878
#include "win32_dirent.h"
79+
extern int ScreenX;
7980
#endif
8081

8182
/* File to read commands from */
@@ -816,7 +817,8 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
816817
m += strlen(tmp);
817818
free(tmp);
818819
#ifdef WINDOWS
819-
width = ConSetScreenX();
820+
ConSetScreenX();
821+
width = ScreenX ;
820822
#else
821823
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
822824
width = ws.ws_col;
@@ -853,12 +855,33 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
853855
attrib_to_stat(&d[n]->a, &sb);
854856
lname = ls_file(fname, &sb, 1,
855857
(lflag & LS_SI_UNITS));
856-
printf("%s\n", lname);
858+
#ifdef WINDOWS
859+
wchar_t* wtmp = utf8_to_utf16(lname);
860+
wprintf_s(L"%ls\n", wtmp);
861+
free(tmp);
862+
#else
863+
printf("%s\n", lname);
864+
#endif
857865
free(lname);
858-
} else
859-
printf("%s\n", d[n]->longname);
860-
} else {
861-
printf("%-*s", colspace, fname);
866+
}
867+
else {
868+
#ifdef WINDOWS
869+
wchar_t* wtmp = utf8_to_utf16(d[n]->longname);
870+
wprintf_s(L"%ls\n", wtmp);
871+
free(wtmp);
872+
#else
873+
printf("%s\n", d[n]->longname);
874+
#endif
875+
}
876+
}
877+
else {
878+
#ifdef WINDOWS
879+
wchar_t* wtmp = utf8_to_utf16(fname);
880+
wprintf_s(L"%-*ls", colspace, wtmp);
881+
free(wtmp);
882+
#else
883+
printf("%-*s", colspace, fname);
884+
#endif
862885
if (c >= columns) {
863886
printf("\n");
864887
c = 1;
@@ -918,7 +941,8 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
918941
}
919942

920943
#ifdef WINDOWS
921-
width = ConSetScreenX();
944+
ConSetScreenX();
945+
width = ScreenX;
922946
#else
923947
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
924948
width = ws.ws_col;
@@ -2128,11 +2152,11 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
21282152
break;
21292153
}
21302154
else {
2131-
int needed;
2132-
if ((needed = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wcmd, -1, NULL, 0, NULL, NULL)) == 0 ||
2133-
(needed > MAX_COMMAND_LINE) ||
2134-
(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wcmd, -1, cmd, needed, NULL, NULL) != needed))
2155+
char *pcmd = NULL;
2156+
if ((pcmd = utf16_to_utf8(wcmd)) == NULL)
21352157
fatal("failed to convert input arguments");
2158+
strcpy(cmd, pcmd);
2159+
free(pcmd);
21362160
}
21372161
}
21382162
else {

win32_dirent.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct dirent *readdir(void *avp)
7373
struct dirent *pdirentry;
7474
struct _wfinddata_t c_file;
7575
DIR *dirp = (DIR *)avp;
76+
char *tmp = NULL;
7677

7778
for (;;) {
7879
if ( _wfindnext( dirp->hFile, &c_file ) == 0 ) {
@@ -82,10 +83,11 @@ struct dirent *readdir(void *avp)
8283
}
8384
pdirentry = (struct dirent *) malloc( sizeof(struct dirent) );
8485

85-
if ((needed = WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, NULL, 0, NULL, NULL)) == 0 ||
86-
(pdirentry->d_name = malloc(needed)) == NULL ||
87-
WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, pdirentry->d_name, needed, NULL, NULL) != needed)
86+
if ((tmp = utf16_to_utf8(pdirentry->d_name)) == NULL)
8887
fatal("failed to covert input arguments");
88+
strcpy(c_file.name[0], tmp);
89+
free(tmp);
90+
tmp = NULL;
8991

9092
pdirentry->d_ino = 1; // a fictious one like UNIX to say it is nonzero
9193
return pdirentry ;

0 commit comments

Comments
 (0)