Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: use WCHAR consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Aug 13, 2012
1 parent aa69f34 commit 7c3ba51
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 101 deletions.
17 changes: 8 additions & 9 deletions include/uv-private/uv-win.h
Expand Up @@ -369,7 +369,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define UV_PIPE_PRIVATE_FIELDS \
HANDLE handle; \
wchar_t* name; \
WCHAR* name; \
union { \
struct { uv_pipe_server_fields }; \
struct { uv_pipe_connection_fields }; \
Expand Down Expand Up @@ -451,8 +451,8 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
#define UV_GETADDRINFO_PRIVATE_FIELDS \
uv_getaddrinfo_cb getaddrinfo_cb; \
void* alloc; \
wchar_t* node; \
wchar_t* service; \
WCHAR* node; \
WCHAR* service; \
struct addrinfoW* hints; \
struct addrinfoW* res; \
int retcode;
Expand Down Expand Up @@ -502,15 +502,14 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
HANDLE dir_handle; \
int req_pending; \
uv_fs_event_cb cb; \
wchar_t* filew; \
wchar_t* short_filew; \
wchar_t* dirw; \
WCHAR* filew; \
WCHAR* short_filew; \
WCHAR* dirw; \
char* buffer;

#define UV_SIGNAL_PRIVATE_FIELDS \
/* empty */

int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer,
int uv_utf16_to_utf8(const WCHAR* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size);int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer,
size_t utf16Size);
2 changes: 1 addition & 1 deletion src/win/dl.c
Expand Up @@ -26,7 +26,7 @@ static int uv__dlerror(uv_lib_t* lib, int errorno);


int uv_dlopen(const char* filename, uv_lib_t* lib) {
wchar_t filename_w[32768];
WCHAR filename_w[32768];

lib->handle = NULL;
lib->errmsg = NULL;
Expand Down
34 changes: 17 additions & 17 deletions src/win/fs-event.c
Expand Up @@ -88,15 +88,15 @@ static void uv_fs_event_queue_readdirchanges(uv_loop_t* loop,
}


static int uv_split_path(const wchar_t* filename, wchar_t** dir,
wchar_t** file) {
static int uv_split_path(const WCHAR* filename, WCHAR** dir,
WCHAR** file) {
int len = wcslen(filename);
int i = len;
while (i > 0 && filename[--i] != '\\' && filename[i] != '/');

if (i == 0) {
if (dir) {
*dir = (wchar_t*)malloc((MAX_PATH + 1) * sizeof(wchar_t));
*dir = (WCHAR*)malloc((MAX_PATH + 1) * sizeof(WCHAR));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
Expand All @@ -111,15 +111,15 @@ static int uv_split_path(const wchar_t* filename, wchar_t** dir,
*file = wcsdup(filename);
} else {
if (dir) {
*dir = (wchar_t*)malloc((i + 1) * sizeof(wchar_t));
*dir = (WCHAR*)malloc((i + 1) * sizeof(WCHAR));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
wcsncpy(*dir, filename, i);
(*dir)[i] = L'\0';
}

*file = (wchar_t*)malloc((len - i) * sizeof(wchar_t));
*file = (WCHAR*)malloc((len - i) * sizeof(WCHAR));
if (!*file) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
Expand All @@ -135,23 +135,23 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
const char* filename, uv_fs_event_cb cb, int flags) {
int name_size, is_path_dir;
DWORD attr, last_error;
wchar_t* dir = NULL, *dir_to_watch, *filenamew = NULL;
wchar_t short_path[MAX_PATH];
WCHAR* dir = NULL, *dir_to_watch, *filenamew = NULL;
WCHAR short_path[MAX_PATH];

/* We don't support any flags yet. */
assert(!flags);

uv_fs_event_init_handle(loop, handle, filename, cb);

/* Convert name to UTF16. */
name_size = uv_utf8_to_utf16(filename, NULL, 0) * sizeof(wchar_t);
filenamew = (wchar_t*)malloc(name_size);
name_size = uv_utf8_to_utf16(filename, NULL, 0) * sizeof(WCHAR);
filenamew = (WCHAR*)malloc(name_size);
if (!filenamew) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

if (!uv_utf8_to_utf16(filename, filenamew,
name_size / sizeof(wchar_t))) {
name_size / sizeof(WCHAR))) {
uv__set_sys_error(loop, GetLastError());
return -1;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
FILE_NOTIFY_INFORMATION* file_info;
int sizew, size, result;
char* filename = NULL;
wchar_t* filenamew, *long_filenamew = NULL;
WCHAR* filenamew, *long_filenamew = NULL;
DWORD offset = 0;

assert(req->type == UV_FS_EVENT_REQ);
Expand Down Expand Up @@ -321,9 +321,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
*/
if (handle->dirw ||
_wcsnicmp(handle->filew, file_info->FileName,
file_info->FileNameLength / sizeof(wchar_t)) == 0 ||
file_info->FileNameLength / sizeof(WCHAR)) == 0 ||
_wcsnicmp(handle->short_filew, file_info->FileName,
file_info->FileNameLength / sizeof(wchar_t)) == 0) {
file_info->FileNameLength / sizeof(WCHAR)) == 0) {

if (handle->dirw) {
/*
Expand All @@ -335,9 +335,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
file_info->Action != FILE_ACTION_RENAMED_OLD_NAME) {
/* Construct a full path to the file. */
size = wcslen(handle->dirw) +
file_info->FileNameLength / sizeof(wchar_t) + 2;
file_info->FileNameLength / sizeof(WCHAR) + 2;

filenamew = (wchar_t*)malloc(size * sizeof(wchar_t));
filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
if (!filenamew) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
Expand All @@ -351,7 +351,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
size = GetLongPathNameW(filenamew, NULL, 0);

if (size) {
long_filenamew = (wchar_t*)malloc(size * sizeof(wchar_t));
long_filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
if (!long_filenamew) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
Expand Down Expand Up @@ -386,7 +386,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
*/
if (!long_filenamew) {
filenamew = file_info->FileName;
sizew = file_info->FileNameLength / sizeof(wchar_t);
sizew = file_info->FileNameLength / sizeof(WCHAR);
}
} else {
/* Removed or renamed callbacks don't provide filename. */
Expand Down
22 changes: 11 additions & 11 deletions src/win/getaddrinfo.c
Expand Up @@ -37,13 +37,13 @@
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
wchar_t* ai_canonname;
WCHAR* ai_canonname;
struct sockaddr* ai_addr;
struct addrinfoW* ai_next;
} ADDRINFOW, *PADDRINFOW;

DECLSPEC_IMPORT int WSAAPI GetAddrInfoW(const wchar_t* node,
const wchar_t* service,
DECLSPEC_IMPORT int WSAAPI GetAddrInfoW(const WCHAR* node,
const WCHAR* service,
const ADDRINFOW* hints,
PADDRINFOW* result);

Expand Down Expand Up @@ -271,7 +271,7 @@ int uv_getaddrinfo(uv_loop_t* loop,

/* calculate required memory size for all input values */
if (node != NULL) {
nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(wchar_t));
nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
uv__set_sys_error(loop, GetLastError());
goto error;
Expand All @@ -280,7 +280,7 @@ int uv_getaddrinfo(uv_loop_t* loop,

if (service != NULL) {
servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) *
sizeof(wchar_t));
sizeof(WCHAR));
if (servicesize == 0) {
uv__set_sys_error(loop, GetLastError());
goto error;
Expand All @@ -303,10 +303,10 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* convert node string to UTF16 into allocated memory and save pointer in */
/* the reques. */
if (node != NULL) {
req->node = (wchar_t*)alloc_ptr;
req->node = (WCHAR*)alloc_ptr;
if (uv_utf8_to_utf16(node,
(wchar_t*) alloc_ptr,
nodesize / sizeof(wchar_t)) == 0) {
(WCHAR*) alloc_ptr,
nodesize / sizeof(WCHAR)) == 0) {
uv__set_sys_error(loop, GetLastError());
goto error;
}
Expand All @@ -318,10 +318,10 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* convert service string to UTF16 into allocated memory and save pointer */
/* in the req. */
if (service != NULL) {
req->service = (wchar_t*)alloc_ptr;
req->service = (WCHAR*)alloc_ptr;
if (uv_utf8_to_utf16(service,
(wchar_t*) alloc_ptr,
servicesize / sizeof(wchar_t)) == 0) {
(WCHAR*) alloc_ptr,
servicesize / sizeof(WCHAR)) == 0) {
uv__set_sys_error(loop, GetLastError());
goto error;
}
Expand Down
12 changes: 6 additions & 6 deletions src/win/pipe.c
Expand Up @@ -430,13 +430,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
}

/* Convert name to UTF16. */
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(wchar_t);
handle->name = (wchar_t*)malloc(nameSize);
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(WCHAR);
handle->name = (WCHAR*)malloc(nameSize);
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(wchar_t))) {
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
uv__set_sys_error(loop, GetLastError());
return -1;
}
Expand Down Expand Up @@ -542,13 +542,13 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
req->cb = cb;

/* Convert name to UTF16. */
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(wchar_t);
handle->name = (wchar_t*)malloc(nameSize);
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(WCHAR);
handle->name = (WCHAR*)malloc(nameSize);
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(wchar_t))) {
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
errorno = GetLastError();
goto error;
}
Expand Down

0 comments on commit 7c3ba51

Please sign in to comment.