Fix crash in w32_dirent, minor spelling in scp.
This commit is contained in:
parent
91b30b64fb
commit
5bd9d2aace
4
scp.c
4
scp.c
|
@ -834,7 +834,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
||||||
|
|
||||||
// Create a pair of pipes for communicating with ssh
|
// Create a pair of pipes for communicating with ssh
|
||||||
// which we will spawn
|
// which we will spawn
|
||||||
// Do the plunmbing so that child ssh process to be spawned has its
|
// Do the plumbing so that child ssh process to be spawned has its
|
||||||
// standard input from the pout[0] and its standard output going to
|
// standard input from the pout[0] and its standard output going to
|
||||||
// pin[1]
|
// pin[1]
|
||||||
|
|
||||||
|
@ -1006,7 +1006,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This functions executes a command simlar to do_cmd(), but expects the
|
* This functions executes a command similar to do_cmd(), but expects the
|
||||||
* input and output descriptors to be setup by a previous call to do_cmd().
|
* input and output descriptors to be setup by a previous call to do_cmd().
|
||||||
* This way the input and output of two commands can be connected.
|
* This way the input and output of two commands can be connected.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <utf.h>
|
||||||
|
|
||||||
#include "win32_dirent.h"
|
#include "win32_dirent.h"
|
||||||
|
|
||||||
|
@ -18,13 +19,16 @@ DIR * opendir(char *name)
|
||||||
intptr_t hFile;
|
intptr_t hFile;
|
||||||
DIR *pdir;
|
DIR *pdir;
|
||||||
wchar_t searchstr[MAX_PATH];
|
wchar_t searchstr[MAX_PATH];
|
||||||
wchar_t wname[MAX_PATH];
|
wchar_t* wname = NULL;
|
||||||
int needed;
|
int needed;
|
||||||
|
char *tmp = NULL;
|
||||||
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, MAX_PATH);
|
if ((wname = utf8_to_utf16(name)) == NULL)
|
||||||
|
fatal("failed to covert input arguments");
|
||||||
|
|
||||||
// add *.* for Windows _findfirst() search pattern
|
// add *.* for Windows _findfirst() search pattern
|
||||||
swprintf_s(searchstr, MAX_PATH, L"%s\\*.*", wname);
|
swprintf_s(searchstr, MAX_PATH, L"%s\\*.*", wname);
|
||||||
|
free(wname);
|
||||||
|
|
||||||
if ((hFile = _wfindfirst(searchstr, &c_file)) == -1L) {
|
if ((hFile = _wfindfirst(searchstr, &c_file)) == -1L) {
|
||||||
if (1) // verbose
|
if (1) // verbose
|
||||||
|
@ -40,11 +44,12 @@ DIR * opendir(char *name)
|
||||||
pdir->c_file.time_create = c_file.time_create;
|
pdir->c_file.time_create = c_file.time_create;
|
||||||
pdir->c_file.time_write = c_file.time_write;
|
pdir->c_file.time_write = c_file.time_write;
|
||||||
|
|
||||||
if ((needed = WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, NULL, 0, NULL, NULL)) == 0 ||
|
if ((tmp = utf16_to_utf8(&(c_file.name))) == NULL)
|
||||||
WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, pdir->c_file.name, needed, NULL, NULL) != needed)
|
|
||||||
fatal("failed to covert input arguments");
|
fatal("failed to covert input arguments");
|
||||||
|
|
||||||
|
strcpy_s(pdir->c_file.name, MAX_PATH, tmp);
|
||||||
strcpy_s(pdir->initName, sizeof(pdir->initName), pdir->c_file.name);
|
strcpy_s(pdir->initName, sizeof(pdir->initName), pdir->c_file.name);
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
return pdir ;
|
return pdir ;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +74,6 @@ int closedir(DIR *dirp)
|
||||||
by a later readdir call on the same DIR stream. */
|
by a later readdir call on the same DIR stream. */
|
||||||
struct dirent *readdir(void *avp)
|
struct dirent *readdir(void *avp)
|
||||||
{
|
{
|
||||||
int needed;
|
|
||||||
struct dirent *pdirentry;
|
struct dirent *pdirentry;
|
||||||
struct _wfinddata_t c_file;
|
struct _wfinddata_t c_file;
|
||||||
DIR *dirp = (DIR *)avp;
|
DIR *dirp = (DIR *)avp;
|
||||||
|
@ -83,10 +87,9 @@ struct dirent *readdir(void *avp)
|
||||||
}
|
}
|
||||||
pdirentry = (struct dirent *) malloc( sizeof(struct dirent) );
|
pdirentry = (struct dirent *) malloc( sizeof(struct dirent) );
|
||||||
|
|
||||||
if ((tmp = utf16_to_utf8(pdirentry->d_name)) == NULL)
|
if ((tmp = utf16_to_utf8(&(c_file.name))) == NULL)
|
||||||
fatal("failed to covert input arguments");
|
fatal("failed to covert input arguments");
|
||||||
strcpy(c_file.name[0], tmp);
|
pdirentry->d_name= tmp;
|
||||||
free(tmp);
|
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
|
|
||||||
pdirentry->d_ino = 1; // a fictious one like UNIX to say it is nonzero
|
pdirentry->d_ino = 1; // a fictious one like UNIX to say it is nonzero
|
||||||
|
|
Loading…
Reference in New Issue