Skip to content

Commit 2447272

Browse files
committed
Initial WIN32_FIXME changes.
1 parent 1f42832 commit 2447272

File tree

13 files changed

+366
-415
lines changed

13 files changed

+366
-415
lines changed

contrib/win32/openssh/config.h.vs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@
15811581
#define _CRT_SECURE_NO_DEPRECATE 1
15821582
#define _CRT_NONSTDC_NO_DEPRECATE 1
15831583
#define WIN32_FIXME 1
1584+
#define WINDOWS 1
15841585

15851586
/* Define if you must implement a startup_needs function for your platform */
15861587
#define HAVE_STARTUP_NEEDS 1
@@ -1631,6 +1632,9 @@
16311632
#define HAVE_STRNCASECMP 1
16321633
#endif
16331634

1635+
/* Define to 1 if you have the locale.h header. */
1636+
#define HAVE_LOCALE_H 1
1637+
16341638
#define HAVE_STRUCT_IN6_ADDR 1
16351639
#define HAVE_STRUCT_SOCKADDR_IN6 1
16361640
#define HAVE_STRUCT_TIMEVAL 1

contrib/win32/openssh/paths.targets

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
<OpenSSH-Src-Path>$(SolutionDir)..\..\..\</OpenSSH-Src-Path>
55
<OpenSSH-Bin-Path>$(SolutionDir)..\..\..\bin\</OpenSSH-Bin-Path>
66
<OpenSSH-Lib-Path>$(SolutionDir)lib\</OpenSSH-Lib-Path>
7-
<OpenSSL-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\</OpenSSL-Path>
8-
<OpenSSL-Win32-Release-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\Win32\Release\</OpenSSL-Win32-Release-Path>
9-
<OpenSSL-Win32-Debug-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\Win32\Debug\</OpenSSL-Win32-Debug-Path>
10-
<OpenSSL-x64-Release-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\x64\Release\</OpenSSL-x64-Release-Path>
11-
<OpenSSL-x64-Debug-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\x64\Debug\</OpenSSL-x64-Debug-Path>
7+
<OpenSSL-Path>g:\openssl-1.0.2h-x64\OpenSSLInstallx64_vs2015-debug\</OpenSSL-Path>
8+
<OpenSSL-Win32-Release-Path>g:\openssl-1.0.2h-x86\OpenSSLInstallx86_vs2015\</OpenSSL-Win32-Release-Path>
9+
<OpenSSL-Win32-Debug-Path>g:\openssl-1.0.2h-x86\OpenSSLInstallx86_vs2015-debug\</OpenSSL-Win32-Debug-Path>
10+
<OpenSSL-x64-Release-Path>g:\openssl-1.0.2h-x64\OpenSSLInstallx64_vs2015\</OpenSSL-x64-Release-Path>
11+
<OpenSSL-x64-Debug-Path>g:\openssl-1.0.2h-x64\OpenSSLInstallx64_vs2015-debug\</OpenSSL-x64-Debug-Path>
12+
<OpenSSL-x86-ARM-Release-Path>g:\openssl-1.0.2h-arm-x86\OpenSSLInstallx86_vs2015\</OpenSSL-x86-ARM-Release-Path>
13+
<OpenSSL-x86-ARM-Debug-Path>g:\openssl-1.0.2h-arm-x86\OpenSSLInstallx86_vs2015\</OpenSSL-x86-ARM-Debug-Path>
1214
</PropertyGroup>
1315
</Project>

contrib/win32/win32compat/inc/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define open w32_open
2525
#define read w32_read
2626
#define write w32_write
27+
#define writev w32_writev
2728
//#define isatty w32_isatty
2829
#define close w32_close
2930
#define dup w32_dup

contrib/win32/win32compat/inc/w32posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int w32_pipe(int *pfds);
4444
int w32_open(const char *pathname, int flags, ...);
4545
int w32_read(int fd, void *dst, size_t max);
4646
int w32_write(int fd, const void *buf, unsigned int max);
47+
int w32_writev(int fd, const struct iovec *iov, int iovcnt);
4748
int w32_fstat(int fd, struct w32_stat *buf);
4849
int w32_stat(const char *path, struct w32_stat *buf);
4950
long w32_lseek( int fd, long offset, int origin);
@@ -117,7 +118,6 @@ int sw_add_child(HANDLE child, DWORD pid);
117118
#define allocate_sfd(a, b) w32_allocate_fd_for_handle((a, b))
118119
//#define WSHELPwopen(a, b) w32_open((a, b))
119120

120-
121121
/* TODO - These defs need to revisited and positioned appropriately */
122122
#define environ _environ
123123

contrib/win32/win32compat/shell-host.c

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@
5050
#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
5151
#endif
5252

53+
HINSTANCE hUserLibrary;
54+
HINSTANCE hKernelLibrary;
55+
56+
// kernel32.dll
57+
typedef BOOL(WINAPI * fSetCurrentConsoleFontEx)(
58+
_In_ HANDLE hConsoleOutput,
59+
_In_ BOOL bMaximumWindow,
60+
_In_ PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
61+
fSetCurrentConsoleFontEx fnSetCurrentConsoleFontEx = NULL;
62+
63+
// user32.dll
64+
typedef HWINEVENTHOOK (WINAPI * fSetWinEventHook)(
65+
_In_ UINT eventMin,
66+
_In_ UINT eventMax,
67+
_In_ HMODULE hmodWinEventProc,
68+
_In_ WINEVENTPROC lpfnWinEventProc,
69+
_In_ DWORD idProcess,
70+
_In_ DWORD idThread,
71+
_In_ UINT dwflags
72+
);
73+
fSetWinEventHook fnSetWinEventHook = NULL;
74+
75+
typedef BOOL (WINAPI * fUnhookWinEvent)(
76+
_In_ HWINEVENTHOOK hWinEventHook
77+
);
78+
fUnhookWinEvent fnUnhookWinEvent = NULL;
79+
5380
typedef struct consoleEvent {
5481
DWORD event;
5582
HWND hwnd;
@@ -66,6 +93,7 @@ BOOL bRet = FALSE;
6693
BOOL bNoScrollRegion = FALSE;
6794
BOOL bStartup = TRUE;
6895
BOOL bAnsi = FALSE;
96+
BOOL bHookEvents = FALSE;
6997

7098
HANDLE child_out = INVALID_HANDLE_VALUE;
7199
HANDLE child_in = INVALID_HANDLE_VALUE;
@@ -389,7 +417,8 @@ void SizeWindow(HANDLE hInput) {
389417
matchingFont.FontWeight = FW_NORMAL;
390418
wcscpy(matchingFont.FaceName, L"Consolas");
391419

392-
bSuccess = SetCurrentConsoleFontEx(child_out, FALSE, &matchingFont);
420+
if(fnSetCurrentConsoleFontEx != NULL)
421+
bSuccess = fnSetCurrentConsoleFontEx(child_out, FALSE, &matchingFont);
393422

394423
// This information is the live screen
395424
ZeroMemory(&consoleInfo, sizeof(consoleInfo));
@@ -1058,6 +1087,22 @@ int wmain(int ac, wchar_t **av) {
10581087
DWORD dwStatus;
10591088
HANDLE hEventHook = NULL;
10601089

1090+
HINSTANCE hUserLibrary;
1091+
HINSTANCE hKernelLibrary;
1092+
1093+
hKernelLibrary = LoadLibrary(L"kernel32.dll");
1094+
if (hKernelLibrary != NULL)
1095+
{
1096+
fnSetCurrentConsoleFontEx = (fSetCurrentConsoleFontEx)GetProcAddress(hKernelLibrary, "SetCurrentConsoleFontEx");
1097+
}
1098+
1099+
hUserLibrary = LoadLibrary(L"user32.dll");
1100+
if (hUserLibrary != NULL)
1101+
{
1102+
fnSetWinEventHook = (fSetWinEventHook)GetProcAddress(hUserLibrary, "SetWinEventHook");
1103+
fnUnhookWinEvent = (fUnhookWinEvent)GetProcAddress(hUserLibrary, "UnhookWinEvent");
1104+
}
1105+
10611106
pipe_in = GetStdHandle(STD_INPUT_HANDLE);
10621107
pipe_out = GetStdHandle(STD_OUTPUT_HANDLE);
10631108
pipe_err = GetStdHandle(STD_ERROR_HANDLE);
@@ -1094,15 +1139,22 @@ int wmain(int ac, wchar_t **av) {
10941139

10951140
InitializeCriticalSection(&criticalSection);
10961141

1097-
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
1098-
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
1142+
if(fnSetWinEventHook != NULL)
1143+
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
1144+
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
10991145

11001146
memset(&si, 0, sizeof(STARTUPINFO));
11011147
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
11021148

11031149
// Copy our parent buffer sizes
11041150
si.cb = sizeof(STARTUPINFO);
11051151
si.dwFlags = 0;
1152+
if (fnSetWinEventHook == NULL) {
1153+
si.hStdInput = INVALID_HANDLE_VALUE;
1154+
si.hStdOutput = pipe_out;
1155+
si.hStdError = pipe_err;
1156+
si.dwFlags = STARTF_USESTDHANDLES;
1157+
}
11061158

11071159
/* disable inheritance on pipe_in*/
11081160
GOTO_CLEANUP_ON_FALSE(SetHandleInformation(pipe_in, HANDLE_FLAG_INHERIT, 0));
@@ -1163,8 +1215,13 @@ int wmain(int ac, wchar_t **av) {
11631215
WaitForSingleObject(monitor_thread, INFINITE);
11641216
if (ux_thread != INVALID_HANDLE_VALUE)
11651217
TerminateThread(ux_thread, S_OK);
1166-
if (hEventHook)
1167-
UnhookWinEvent(hEventHook);
1218+
if (hEventHook && fnUnhookWinEvent != NULL)
1219+
fnUnhookWinEvent(hEventHook);
1220+
1221+
if (hKernelLibrary != NULL)
1222+
FreeLibrary(hKernelLibrary);
1223+
if (hUserLibrary != NULL)
1224+
FreeLibrary(hUserLibrary);
11681225

11691226
FreeConsole();
11701227

contrib/win32/win32compat/w32fd.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,23 @@ w32_write(int fd, const void *buf, unsigned int max) {
382382
return fileio_write(fd_table.w32_ios[fd], buf, max);
383383
}
384384

385+
int w32_writev(int fd, const struct iovec *iov, int iovcnt) {
386+
int written = 0;
387+
int i = 0;
388+
389+
CHECK_FD(fd);
390+
391+
for (i = 0; i < iovcnt; i++) {
392+
int ret = write(fd, iov[i].iov_base, iov[i].iov_len);
393+
394+
if (ret > 0) {
395+
written += ret;
396+
}
397+
}
398+
399+
return written;
400+
}
401+
385402
int
386403
w32_fstat(int fd, struct w32_stat *buf) {
387404
CHECK_FD(fd);

misc.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,34 @@ char *
436436
colon(char *cp)
437437
{
438438
int flag = 0;
439+
int len = 0;
439440

440441
if (*cp == ':') /* Leading colon is part of file name. */
441442
return NULL;
443+
444+
#ifdef WINDOWS
445+
for (; *cp; ++cp) {
446+
len++;
447+
448+
if (*cp == '[')
449+
flag = 1;
450+
451+
if (flag && *cp != ']')
452+
continue;
453+
454+
if (*cp == ']')
455+
flag = 0;
456+
457+
if (*cp == ':') {
458+
if (len != 2) { // avoid x: format for drive letter in Windows
459+
return (cp);
460+
}
461+
}
462+
// if ( (*cp == '/') || (*cp == '\\') )
463+
// return (0);
464+
}
465+
return NULL;
466+
#else
442467
if (*cp == '[')
443468
flag = 1;
444469

@@ -452,7 +477,8 @@ colon(char *cp)
452477
if (*cp == '/')
453478
return NULL;
454479
}
455-
return NULL;
480+
return NULL;
481+
#endif
456482
}
457483

458484
/* function to assist building execv() arguments */

progressmeter.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,16 @@ static const char unit[] = " KMGT";
8181
static int
8282
can_output(void)
8383
{
84-
#ifndef WIN32_FIXME//R
85-
return (getpgrp() == tcgetpgrp(STDOUT_FILENO));
84+
#ifndef WINDOWS
85+
return (getpgrp() == tcgetpgrp(STDOUT_FILENO));
8686
#else
87-
return 1;
87+
DWORD dwProcessId = -1;
88+
if (GetWindowThreadProcessId(GetStdHandle(STD_OUTPUT_HANDLE), &dwProcessId)) {
89+
return(GetCurrentProcess() == dwProcessId);
90+
}
91+
else {
92+
return -1;
93+
}
8894
#endif
8995
}
9096

@@ -298,7 +304,7 @@ sig_winch(int sig)
298304
static void
299305
setscreensize(void)
300306
{
301-
#ifndef WIN32_FIXME//N
307+
#ifndef WINDOWS
302308
struct winsize winsize;
303309

304310
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 &&
@@ -310,6 +316,7 @@ setscreensize(void)
310316
} else
311317
win_size = DEFAULT_WINSIZE;
312318
win_size += 1; /* trailing \0 */
319+
#else
320+
win_size = ConScreenSizeX() + 1;
313321
#endif
314-
win_size = DEFAULT_WINSIZE + 1;
315322
}

0 commit comments

Comments
 (0)