Skip to content

Commit 4676c9f

Browse files
committed
Unicode enabled on gethostname
1 parent 12db568 commit 4676c9f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

contrib/win32/win32compat/misc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ w32_fopen_utf8(const char *path, const char *mode) {
119119
return f;
120120
}
121121

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-
128122

129123
wchar_t*
130124
utf8_to_utf16(const char *utf8) {

contrib/win32/win32compat/socketio.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <errno.h>
3535
#include "w32fd.h"
3636
#include <stddef.h>
37+
#include "inc\utf.h"
3738

3839
#define INTERNAL_SEND_BUFFER_SIZE 70*1024 //70KB
3940

@@ -978,4 +979,24 @@ socketio_on_select(struct w32_io* pio, BOOL rd) {
978979
}
979980
}
980981

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;
9811002
}

0 commit comments

Comments
 (0)