File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed
contrib/win32/win32compat Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -119,12 +119,6 @@ w32_fopen_utf8(const char *path, const char *mode) {
119
119
return f ;
120
120
}
121
121
122
- /*TODO implement Unicode host name support in Windows*/
123
- int
124
- w32_gethostname (char * name , size_t len ) {
125
- return gethostname (name , len );
126
- }
127
-
128
122
129
123
wchar_t *
130
124
utf8_to_utf16 (const char * utf8 ) {
Original file line number Diff line number Diff line change 34
34
#include <errno.h>
35
35
#include "w32fd.h"
36
36
#include <stddef.h>
37
+ #include "inc\utf .h "
37
38
38
39
#define INTERNAL_SEND_BUFFER_SIZE 70*1024 //70KB
39
40
@@ -978,4 +979,24 @@ socketio_on_select(struct w32_io* pio, BOOL rd) {
978
979
}
979
980
}
980
981
982
+ }
983
+
984
+ int
985
+ w32_gethostname (char * name_utf8 , size_t len ) {
986
+ wchar_t name_utf16 [256 ];
987
+ char * tmp_name_utf8 = NULL ;
988
+ if (GetHostNameW (name_utf16 , 256 ) == SOCKET_ERROR ) {
989
+ errno = errno_from_WSALastError ();
990
+ return -1 ;
991
+ }
992
+
993
+ if ((tmp_name_utf8 = utf16_to_utf8 (name_utf16 )) == NULL ||
994
+ strlen (tmp_name_utf8 ) >= len ) {
995
+ errno = EFAULT ; //??
996
+ return -1 ;
997
+ }
998
+
999
+ memcpy (name_utf8 , tmp_name_utf8 , strlen (tmp_name_utf8 ) + 1 );
1000
+ free (tmp_name_utf8 );
1001
+ return 0 ;
981
1002
}
You can’t perform that action at this time.
0 commit comments