File tree Expand file tree Collapse file tree 2 files changed +23
-15
lines changed
contrib/win32/win32compat Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 32
32
#include <ws2tcpip.h>
33
33
#include <mswsock.h>
34
34
#include <errno.h>
35
+ #include <VersionHelpers.h>
35
36
#include "w32fd.h"
36
37
#include <stddef.h>
37
38
#include "inc\utf .h "
@@ -985,20 +986,26 @@ int
985
986
w32_gethostname (char * name_utf8 , size_t len ) {
986
987
wchar_t name_utf16 [256 ];
987
988
char * tmp_name_utf8 = NULL ;
988
- if (GetHostNameW (name_utf16 , 256 ) == SOCKET_ERROR ) {
989
- errno = errno_from_WSALastError ();
990
- return -1 ;
991
- }
992
989
993
- if ((tmp_name_utf8 = utf16_to_utf8 (name_utf16 )) == NULL ||
994
- strlen (tmp_name_utf8 ) >= len ) {
995
- errno = EFAULT ; //??
996
- return -1 ;
990
+ if (IsWindows8OrGreater ()) {
991
+ /* TODO - GetHostNameW not present in Win7, do GetProcAddr on Win8+*/
992
+ // if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) {
993
+ // errno = errno_from_WSALastError();
994
+ // return -1;
995
+ // }
996
+
997
+ // if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL ||
998
+ // strlen(tmp_name_utf8) >= len) {
999
+ // errno = EFAULT; //??
1000
+ // return -1;
1001
+ // }
1002
+
1003
+ // memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1);
1004
+ // free(tmp_name_utf8);
1005
+ // return 0;
997
1006
}
998
-
999
- memcpy (name_utf8 , tmp_name_utf8 , strlen (tmp_name_utf8 ) + 1 );
1000
- free (tmp_name_utf8 );
1001
- return 0 ;
1007
+ else
1008
+ return gethostname (name_utf8 , len );
1002
1009
}
1003
1010
1004
1011
void
Original file line number Diff line number Diff line change @@ -1895,9 +1895,10 @@ main(int ac, char **av)
1895
1895
{
1896
1896
do
1897
1897
{
1898
- SERVICE_TABLE_ENTRY DispatchTable [] =
1898
+ int wmain (int , wchar_t * * );
1899
+ SERVICE_TABLE_ENTRYW DispatchTable [] =
1899
1900
{
1900
- {SVCNAME , (LPSERVICE_MAIN_FUNCTION ) main },
1901
+ {L"SSHD" , (LPSERVICE_MAIN_FUNCTIONW ) wmain },
1901
1902
{NULL , NULL }
1902
1903
};
1903
1904
@@ -1920,7 +1921,7 @@ main(int ac, char **av)
1920
1921
* for any other reason, bail out.
1921
1922
*/
1922
1923
1923
- if (!StartServiceCtrlDispatcher (DispatchTable ))
1924
+ if (!StartServiceCtrlDispatcherW (DispatchTable ))
1924
1925
{
1925
1926
if (GetLastError () == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT )
1926
1927
{
You can’t perform that action at this time.
0 commit comments