SFTP issues.

This commit is contained in:
Ray Hayes 2016-10-21 11:43:09 -07:00
parent 9291dde274
commit b7d80edae3
4 changed files with 47 additions and 24 deletions

View File

@ -559,13 +559,13 @@ fileio_fstat(struct w32_io* pio, struct _stat64 *buf) {
int
fileio_stat(const char *path, struct _stat64 *buf) {
wchar_t wpath[MAX_PATH];
wchar_t* wpath[MAX_PATH];
wchar_t* wtmp = NULL;
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH) == 0) {
errno = EFAULT;
debug("WideCharToMultiByte failed - ERROR:%d", GetLastError());
return GetLastError();
}
if ((wtmp = utf8_to_utf16(path)) == NULL)
fatal("failed to covert input arguments");
strcpy(wpath, wtmp);
free(wtmp);
return _wstat64(wpath, buf);
}

View File

@ -438,13 +438,10 @@ int w32_chdir(const char *dirname_utf8) {
char *w32_getcwd(char *buffer, int maxlen) {
wchar_t wdirname[MAX_PATH];
int needed;
wchar_t *wpwd = _wgetcwd(wdirname, MAX_PATH);
if ((needed = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wdirname, -1, NULL, 0, NULL, NULL)) == 0 ||
(needed > MAX_PATH) ||
(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wdirname, -1, buffer, needed, NULL, NULL) != needed))
if (buffer = utf16_to_utf8(wpwd))
fatal("failed to convert input arguments");
return buffer;

46
sftp.c
View File

@ -76,6 +76,7 @@ typedef void EditLine;
#ifdef WIN32_VS
#include "win32_dirent.h"
extern int ScreenX;
#endif
/* File to read commands from */
@ -816,7 +817,8 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
m += strlen(tmp);
free(tmp);
#ifdef WINDOWS
width = ConSetScreenX();
ConSetScreenX();
width = ScreenX ;
#else
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
width = ws.ws_col;
@ -853,12 +855,33 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
attrib_to_stat(&d[n]->a, &sb);
lname = ls_file(fname, &sb, 1,
(lflag & LS_SI_UNITS));
printf("%s\n", lname);
#ifdef WINDOWS
wchar_t* wtmp = utf8_to_utf16(lname);
wprintf_s(L"%ls\n", wtmp);
free(tmp);
#else
printf("%s\n", lname);
#endif
free(lname);
} else
printf("%s\n", d[n]->longname);
} else {
printf("%-*s", colspace, fname);
}
else {
#ifdef WINDOWS
wchar_t* wtmp = utf8_to_utf16(d[n]->longname);
wprintf_s(L"%ls\n", wtmp);
free(wtmp);
#else
printf("%s\n", d[n]->longname);
#endif
}
}
else {
#ifdef WINDOWS
wchar_t* wtmp = utf8_to_utf16(fname);
wprintf_s(L"%-*ls", colspace, wtmp);
free(wtmp);
#else
printf("%-*s", colspace, fname);
#endif
if (c >= columns) {
printf("\n");
c = 1;
@ -918,7 +941,8 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
}
#ifdef WINDOWS
width = ConSetScreenX();
ConSetScreenX();
width = ScreenX;
#else
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
width = ws.ws_col;
@ -2128,11 +2152,11 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
break;
}
else {
int needed;
if ((needed = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wcmd, -1, NULL, 0, NULL, NULL)) == 0 ||
(needed > MAX_COMMAND_LINE) ||
(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wcmd, -1, cmd, needed, NULL, NULL) != needed))
char *pcmd = NULL;
if ((pcmd = utf16_to_utf8(wcmd)) == NULL)
fatal("failed to convert input arguments");
strcpy(cmd, pcmd);
free(pcmd);
}
}
else {

View File

@ -73,6 +73,7 @@ struct dirent *readdir(void *avp)
struct dirent *pdirentry;
struct _wfinddata_t c_file;
DIR *dirp = (DIR *)avp;
char *tmp = NULL;
for (;;) {
if ( _wfindnext( dirp->hFile, &c_file ) == 0 ) {
@ -82,10 +83,11 @@ struct dirent *readdir(void *avp)
}
pdirentry = (struct dirent *) malloc( sizeof(struct dirent) );
if ((needed = WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, NULL, 0, NULL, NULL)) == 0 ||
(pdirentry->d_name = malloc(needed)) == NULL ||
WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, pdirentry->d_name, needed, NULL, NULL) != needed)
if ((tmp = utf16_to_utf8(pdirentry->d_name)) == NULL)
fatal("failed to covert input arguments");
strcpy(c_file.name[0], tmp);
free(tmp);
tmp = NULL;
pdirentry->d_ino = 1; // a fictious one like UNIX to say it is nonzero
return pdirentry ;