Skip to content

Commit f5c9367

Browse files
committed
Fix input formatting and add a directive.
1 parent 78306c9 commit f5c9367

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

contrib/win32/win32compat/inc/sys/stat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define lstat w32_stat
3131
#define mkdir w32_mkdir
3232
#define chdir w32_chdir
33+
#define getcwd w32_getcwd
3334

3435
struct w32_stat {
3536
dev_t st_dev; /* ID of device containing file */

contrib/win32/win32compat/inc/w32posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int w32_isatty(int fd);
5353
FILE* w32_fdopen(int fd, const char *mode);
5454
int w32_mkdir(const char *pathname, unsigned short mode);
5555
int w32_chdir(const char *dirname);
56+
char *w32_getcwd(char *buffer, int maxlen);
5657

5758
/*common i/o*/
5859
#define fcntl(a,b,...) w32_fcntl((a), (b), __VA_ARGS__)

contrib/win32/win32compat/w32fd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,19 @@ int w32_chdir(const char *dirname) {
437437
return 0;
438438
}
439439

440+
char *w32_getcwd(char *buffer, int maxlen) {
441+
wchar_t wdirname[MAX_PATH];
442+
int needed;
443+
444+
wchar_t *wpwd = _wgetcwd(wdirname, MAX_PATH);
445+
446+
if ((needed = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wdirname, -1, NULL, 0, NULL, NULL)) == 0 ||
447+
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wdirname, -1, buffer, needed, NULL, NULL) != needed)
448+
fatal("failed to covert input arguments");
449+
450+
return buffer;
451+
}
452+
440453
int
441454
w32_isatty(int fd) {
442455
struct w32_io* pio;

sftp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,8 +2357,10 @@ main(int argc, char **argv)
23572357
addargs(&args, "\"-oClearAllForwardings yes\"");
23582358

23592359
ll = SYSLOG_LEVEL_INFO;
2360-
infile = stdin;
2361-
_setmode(_fileno(infile), O_U16TEXT);
2360+
#ifdef WINDOWS
2361+
_setmode(_fileno(stdin), O_U16TEXT);
2362+
#endif
2363+
infile = stdin;
23622364

23632365
while ((ch = getopt(argc, argv,
23642366
"1246afhpqrvCc:D:i:l:o:s:S:b:B:F:P:R:")) != -1) {

0 commit comments

Comments
 (0)