windows: use WCHAR consistently

This commit is contained in:
Bert Belder 2012-08-13 22:19:03 +02:00
parent aa69f34d53
commit 7c3ba514e7
9 changed files with 100 additions and 101 deletions

View File

@ -369,7 +369,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
#define UV_PIPE_PRIVATE_FIELDS \ #define UV_PIPE_PRIVATE_FIELDS \
HANDLE handle; \ HANDLE handle; \
wchar_t* name; \ WCHAR* name; \
union { \ union { \
struct { uv_pipe_server_fields }; \ struct { uv_pipe_server_fields }; \
struct { uv_pipe_connection_fields }; \ struct { uv_pipe_connection_fields }; \
@ -451,8 +451,8 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
#define UV_GETADDRINFO_PRIVATE_FIELDS \ #define UV_GETADDRINFO_PRIVATE_FIELDS \
uv_getaddrinfo_cb getaddrinfo_cb; \ uv_getaddrinfo_cb getaddrinfo_cb; \
void* alloc; \ void* alloc; \
wchar_t* node; \ WCHAR* node; \
wchar_t* service; \ WCHAR* service; \
struct addrinfoW* hints; \ struct addrinfoW* hints; \
struct addrinfoW* res; \ struct addrinfoW* res; \
int retcode; int retcode;
@ -502,15 +502,14 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
HANDLE dir_handle; \ HANDLE dir_handle; \
int req_pending; \ int req_pending; \
uv_fs_event_cb cb; \ uv_fs_event_cb cb; \
wchar_t* filew; \ WCHAR* filew; \
wchar_t* short_filew; \ WCHAR* short_filew; \
wchar_t* dirw; \ WCHAR* dirw; \
char* buffer; char* buffer;
#define UV_SIGNAL_PRIVATE_FIELDS \ #define UV_SIGNAL_PRIVATE_FIELDS \
/* empty */ /* empty */
int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, int uv_utf16_to_utf8(const WCHAR* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size); char* utf8Buffer, size_t utf8Size);int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer,
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer,
size_t utf16Size); size_t utf16Size);

View File

@ -26,7 +26,7 @@ static int uv__dlerror(uv_lib_t* lib, int errorno);
int uv_dlopen(const char* filename, uv_lib_t* lib) { int uv_dlopen(const char* filename, uv_lib_t* lib) {
wchar_t filename_w[32768]; WCHAR filename_w[32768];
lib->handle = NULL; lib->handle = NULL;
lib->errmsg = NULL; lib->errmsg = NULL;

View File

@ -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, static int uv_split_path(const WCHAR* filename, WCHAR** dir,
wchar_t** file) { WCHAR** file) {
int len = wcslen(filename); int len = wcslen(filename);
int i = len; int i = len;
while (i > 0 && filename[--i] != '\\' && filename[i] != '/'); while (i > 0 && filename[--i] != '\\' && filename[i] != '/');
if (i == 0) { if (i == 0) {
if (dir) { if (dir) {
*dir = (wchar_t*)malloc((MAX_PATH + 1) * sizeof(wchar_t)); *dir = (WCHAR*)malloc((MAX_PATH + 1) * sizeof(WCHAR));
if (!*dir) { if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
@ -111,7 +111,7 @@ static int uv_split_path(const wchar_t* filename, wchar_t** dir,
*file = wcsdup(filename); *file = wcsdup(filename);
} else { } else {
if (dir) { if (dir) {
*dir = (wchar_t*)malloc((i + 1) * sizeof(wchar_t)); *dir = (WCHAR*)malloc((i + 1) * sizeof(WCHAR));
if (!*dir) { if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
@ -119,7 +119,7 @@ static int uv_split_path(const wchar_t* filename, wchar_t** dir,
(*dir)[i] = L'\0'; (*dir)[i] = L'\0';
} }
*file = (wchar_t*)malloc((len - i) * sizeof(wchar_t)); *file = (WCHAR*)malloc((len - i) * sizeof(WCHAR));
if (!*file) { if (!*file) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
@ -135,8 +135,8 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
const char* filename, uv_fs_event_cb cb, int flags) { const char* filename, uv_fs_event_cb cb, int flags) {
int name_size, is_path_dir; int name_size, is_path_dir;
DWORD attr, last_error; DWORD attr, last_error;
wchar_t* dir = NULL, *dir_to_watch, *filenamew = NULL; WCHAR* dir = NULL, *dir_to_watch, *filenamew = NULL;
wchar_t short_path[MAX_PATH]; WCHAR short_path[MAX_PATH];
/* We don't support any flags yet. */ /* We don't support any flags yet. */
assert(!flags); assert(!flags);
@ -144,14 +144,14 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
uv_fs_event_init_handle(loop, handle, filename, cb); uv_fs_event_init_handle(loop, handle, filename, cb);
/* Convert name to UTF16. */ /* Convert name to UTF16. */
name_size = uv_utf8_to_utf16(filename, NULL, 0) * sizeof(wchar_t); name_size = uv_utf8_to_utf16(filename, NULL, 0) * sizeof(WCHAR);
filenamew = (wchar_t*)malloc(name_size); filenamew = (WCHAR*)malloc(name_size);
if (!filenamew) { if (!filenamew) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
if (!uv_utf8_to_utf16(filename, filenamew, if (!uv_utf8_to_utf16(filename, filenamew,
name_size / sizeof(wchar_t))) { name_size / sizeof(WCHAR))) {
uv__set_sys_error(loop, GetLastError()); uv__set_sys_error(loop, GetLastError());
return -1; return -1;
} }
@ -292,7 +292,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
FILE_NOTIFY_INFORMATION* file_info; FILE_NOTIFY_INFORMATION* file_info;
int sizew, size, result; int sizew, size, result;
char* filename = NULL; char* filename = NULL;
wchar_t* filenamew, *long_filenamew = NULL; WCHAR* filenamew, *long_filenamew = NULL;
DWORD offset = 0; DWORD offset = 0;
assert(req->type == UV_FS_EVENT_REQ); assert(req->type == UV_FS_EVENT_REQ);
@ -321,9 +321,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
*/ */
if (handle->dirw || if (handle->dirw ||
_wcsnicmp(handle->filew, file_info->FileName, _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, _wcsnicmp(handle->short_filew, file_info->FileName,
file_info->FileNameLength / sizeof(wchar_t)) == 0) { file_info->FileNameLength / sizeof(WCHAR)) == 0) {
if (handle->dirw) { if (handle->dirw) {
/* /*
@ -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) { file_info->Action != FILE_ACTION_RENAMED_OLD_NAME) {
/* Construct a full path to the file. */ /* Construct a full path to the file. */
size = wcslen(handle->dirw) + 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) { if (!filenamew) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
@ -351,7 +351,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
size = GetLongPathNameW(filenamew, NULL, 0); size = GetLongPathNameW(filenamew, NULL, 0);
if (size) { if (size) {
long_filenamew = (wchar_t*)malloc(size * sizeof(wchar_t)); long_filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
if (!long_filenamew) { if (!long_filenamew) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
@ -386,7 +386,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
*/ */
if (!long_filenamew) { if (!long_filenamew) {
filenamew = file_info->FileName; filenamew = file_info->FileName;
sizew = file_info->FileNameLength / sizeof(wchar_t); sizew = file_info->FileNameLength / sizeof(WCHAR);
} }
} else { } else {
/* Removed or renamed callbacks don't provide filename. */ /* Removed or renamed callbacks don't provide filename. */

View File

@ -37,13 +37,13 @@
int ai_socktype; int ai_socktype;
int ai_protocol; int ai_protocol;
size_t ai_addrlen; size_t ai_addrlen;
wchar_t* ai_canonname; WCHAR* ai_canonname;
struct sockaddr* ai_addr; struct sockaddr* ai_addr;
struct addrinfoW* ai_next; struct addrinfoW* ai_next;
} ADDRINFOW, *PADDRINFOW; } ADDRINFOW, *PADDRINFOW;
DECLSPEC_IMPORT int WSAAPI GetAddrInfoW(const wchar_t* node, DECLSPEC_IMPORT int WSAAPI GetAddrInfoW(const WCHAR* node,
const wchar_t* service, const WCHAR* service,
const ADDRINFOW* hints, const ADDRINFOW* hints,
PADDRINFOW* result); PADDRINFOW* result);
@ -271,7 +271,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* calculate required memory size for all input values */ /* calculate required memory size for all input values */
if (node != NULL) { 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) { if (nodesize == 0) {
uv__set_sys_error(loop, GetLastError()); uv__set_sys_error(loop, GetLastError());
goto error; goto error;
@ -280,7 +280,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (service != NULL) { if (service != NULL) {
servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) * servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) *
sizeof(wchar_t)); sizeof(WCHAR));
if (servicesize == 0) { if (servicesize == 0) {
uv__set_sys_error(loop, GetLastError()); uv__set_sys_error(loop, GetLastError());
goto error; goto error;
@ -303,10 +303,10 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* convert node string to UTF16 into allocated memory and save pointer in */ /* convert node string to UTF16 into allocated memory and save pointer in */
/* the reques. */ /* the reques. */
if (node != NULL) { if (node != NULL) {
req->node = (wchar_t*)alloc_ptr; req->node = (WCHAR*)alloc_ptr;
if (uv_utf8_to_utf16(node, if (uv_utf8_to_utf16(node,
(wchar_t*) alloc_ptr, (WCHAR*) alloc_ptr,
nodesize / sizeof(wchar_t)) == 0) { nodesize / sizeof(WCHAR)) == 0) {
uv__set_sys_error(loop, GetLastError()); uv__set_sys_error(loop, GetLastError());
goto error; goto error;
} }
@ -318,10 +318,10 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* convert service string to UTF16 into allocated memory and save pointer */ /* convert service string to UTF16 into allocated memory and save pointer */
/* in the req. */ /* in the req. */
if (service != NULL) { if (service != NULL) {
req->service = (wchar_t*)alloc_ptr; req->service = (WCHAR*)alloc_ptr;
if (uv_utf8_to_utf16(service, if (uv_utf8_to_utf16(service,
(wchar_t*) alloc_ptr, (WCHAR*) alloc_ptr,
servicesize / sizeof(wchar_t)) == 0) { servicesize / sizeof(WCHAR)) == 0) {
uv__set_sys_error(loop, GetLastError()); uv__set_sys_error(loop, GetLastError());
goto error; goto error;
} }

View File

@ -430,13 +430,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
} }
/* Convert name to UTF16. */ /* Convert name to UTF16. */
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(wchar_t); nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(WCHAR);
handle->name = (wchar_t*)malloc(nameSize); handle->name = (WCHAR*)malloc(nameSize);
if (!handle->name) { if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); 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()); uv__set_sys_error(loop, GetLastError());
return -1; return -1;
} }
@ -542,13 +542,13 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
req->cb = cb; req->cb = cb;
/* Convert name to UTF16. */ /* Convert name to UTF16. */
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(wchar_t); nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(WCHAR);
handle->name = (wchar_t*)malloc(nameSize); handle->name = (WCHAR*)malloc(nameSize);
if (!handle->name) { if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); 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(); errorno = GetLastError();
goto error; goto error;
} }

View File

@ -36,7 +36,7 @@
typedef struct env_var { typedef struct env_var {
const char* narrow; const char* narrow;
const wchar_t* wide; const WCHAR* wide;
int len; /* including null or '=' */ int len; /* including null or '=' */
int supplied; int supplied;
int value_len; int value_len;
@ -101,15 +101,15 @@ static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) {
/* /*
* Helper function for search_path * Helper function for search_path
*/ */
static wchar_t* search_path_join_test(const wchar_t* dir, static WCHAR* search_path_join_test(const WCHAR* dir,
int dir_len, int dir_len,
const wchar_t* name, const WCHAR* name,
int name_len, int name_len,
const wchar_t* ext, const WCHAR* ext,
int ext_len, int ext_len,
const wchar_t* cwd, const WCHAR* cwd,
int cwd_len) { int cwd_len) {
wchar_t *result, *result_pos; WCHAR *result, *result_pos;
DWORD attrs; DWORD attrs;
if (dir_len >= 1 && (dir[0] == L'/' || dir[0] == L'\\')) { if (dir_len >= 1 && (dir[0] == L'/' || dir[0] == L'\\')) {
@ -135,7 +135,7 @@ static wchar_t* search_path_join_test(const wchar_t* dir,
} }
/* Allocate buffer for output */ /* Allocate buffer for output */
result = result_pos = (wchar_t*)malloc(sizeof(wchar_t) * result = result_pos = (WCHAR*)malloc(sizeof(WCHAR) *
(cwd_len + 1 + dir_len + 1 + name_len + 1 + ext_len + 1)); (cwd_len + 1 + dir_len + 1 + name_len + 1 + ext_len + 1));
/* Copy cwd */ /* Copy cwd */
@ -192,14 +192,14 @@ static wchar_t* search_path_join_test(const wchar_t* dir,
/* /*
* Helper function for search_path * Helper function for search_path
*/ */
static wchar_t* path_search_walk_ext(const wchar_t *dir, static WCHAR* path_search_walk_ext(const WCHAR *dir,
int dir_len, int dir_len,
const wchar_t *name, const WCHAR *name,
int name_len, int name_len,
wchar_t *cwd, WCHAR *cwd,
int cwd_len, int cwd_len,
int name_has_ext) { int name_has_ext) {
wchar_t* result; WCHAR* result;
/* If the name itself has a nonempty extension, try this extension first */ /* If the name itself has a nonempty extension, try this extension first */
if (name_has_ext) { if (name_has_ext) {
@ -273,14 +273,14 @@ static wchar_t* path_search_walk_ext(const wchar_t *dir,
* *
* TODO: correctly interpret UNC paths * TODO: correctly interpret UNC paths
*/ */
static wchar_t* search_path(const wchar_t *file, static WCHAR* search_path(const WCHAR *file,
wchar_t *cwd, WCHAR *cwd,
const wchar_t *path) { const WCHAR *path) {
int file_has_dir; int file_has_dir;
wchar_t* result = NULL; WCHAR* result = NULL;
wchar_t *file_name_start; WCHAR *file_name_start;
wchar_t *dot; WCHAR *dot;
const wchar_t *dir_start, *dir_end, *dir_path; const WCHAR *dir_start, *dir_end, *dir_path;
int dir_len; int dir_len;
int name_has_ext; int name_has_ext;
@ -297,7 +297,7 @@ static wchar_t* search_path(const wchar_t *file,
/* Find the start of the filename so we can split the directory from the */ /* Find the start of the filename so we can split the directory from the */
/* name. */ /* name. */
for (file_name_start = (wchar_t*)file + file_len; for (file_name_start = (WCHAR*)file + file_len;
file_name_start > file file_name_start > file
&& file_name_start[-1] != L'\\' && file_name_start[-1] != L'\\'
&& file_name_start[-1] != L'/' && file_name_start[-1] != L'/'
@ -379,10 +379,10 @@ static wchar_t* search_path(const wchar_t *file,
* Quotes command line arguments * Quotes command line arguments
* Returns a pointer to the end (next char to be written) of the buffer * Returns a pointer to the end (next char to be written) of the buffer
*/ */
wchar_t* quote_cmd_arg(const wchar_t *source, wchar_t *target) { WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target) {
int len = wcslen(source), int len = wcslen(source),
i, quote_hit; i, quote_hit;
wchar_t* start; WCHAR* start;
/* /*
* Check if the string must be quoted; * Check if the string must be quoted;
@ -571,11 +571,11 @@ static void check_required_vars_contains_var(env_var_t* required, int size,
* these get defined if the input environment block does not contain any * these get defined if the input environment block does not contain any
* values for them. * values for them.
*/ */
wchar_t* make_program_env(char** env_block) { WCHAR* make_program_env(char** env_block) {
wchar_t* dst; WCHAR* dst;
wchar_t* ptr; WCHAR* ptr;
char** env; char** env;
int env_len = 1 * sizeof(wchar_t); /* room for closing null */ int env_len = 1 * sizeof(WCHAR); /* room for closing null */
int len; int len;
int i; int i;
DWORD var_size; DWORD var_size;
@ -590,18 +590,18 @@ wchar_t* make_program_env(char** env_block) {
check_required_vars_contains_var(required_vars, check_required_vars_contains_var(required_vars,
ARRAY_SIZE(required_vars), ARRAY_SIZE(required_vars),
*env); *env);
env_len += (uv_utf8_to_utf16(*env, NULL, 0) * sizeof(wchar_t)); env_len += (uv_utf8_to_utf16(*env, NULL, 0) * sizeof(WCHAR));
} }
for (i = 0; i < ARRAY_SIZE(required_vars); ++i) { for (i = 0; i < ARRAY_SIZE(required_vars); ++i) {
if (!required_vars[i].supplied) { if (!required_vars[i].supplied) {
env_len += required_vars[i].len * sizeof(wchar_t); env_len += required_vars[i].len * sizeof(WCHAR);
var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0); var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0);
if (var_size == 0) { if (var_size == 0) {
uv_fatal_error(GetLastError(), "GetEnvironmentVariableW"); uv_fatal_error(GetLastError(), "GetEnvironmentVariableW");
} }
required_vars[i].value_len = (int)var_size; required_vars[i].value_len = (int)var_size;
env_len += (int)var_size * sizeof(wchar_t); env_len += (int)var_size * sizeof(WCHAR);
} }
} }
@ -738,9 +738,9 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
uv_process_options_t options) { uv_process_options_t options) {
int i; int i;
uv_err_t err = uv_ok_; uv_err_t err = uv_ok_;
wchar_t* path = NULL; WCHAR* path = NULL;
BOOL result; BOOL result;
wchar_t* application_path = NULL, *application = NULL, *arguments = NULL, WCHAR* application_path = NULL, *application = NULL, *arguments = NULL,
*env = NULL, *cwd = NULL; *env = NULL, *cwd = NULL;
STARTUPINFOW startup; STARTUPINFOW startup;
PROCESS_INFORMATION info; PROCESS_INFORMATION info;

View File

@ -74,7 +74,7 @@ void uv__util_init() {
} }
int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, int uv_utf16_to_utf8(const WCHAR* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size) { char* utf8Buffer, size_t utf8Size) {
return WideCharToMultiByte(CP_UTF8, return WideCharToMultiByte(CP_UTF8,
0, 0,
@ -87,7 +87,7 @@ int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
} }
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer,
size_t utf16Size) { size_t utf16Size) {
return MultiByteToWideChar(CP_UTF8, return MultiByteToWideChar(CP_UTF8,
0, 0,
@ -113,7 +113,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
utf16_buffer_len = (int) *size_ptr; utf16_buffer_len = (int) *size_ptr;
} }
utf16_buffer = (wchar_t*) malloc(sizeof(WCHAR) * utf16_buffer_len); utf16_buffer = (WCHAR*) malloc(sizeof(WCHAR) * utf16_buffer_len);
if (!utf16_buffer) { if (!utf16_buffer) {
return -1; return -1;
} }
@ -340,7 +340,7 @@ char** uv_setup_args(int argc, char** argv) {
uv_err_t uv_set_process_title(const char* title) { uv_err_t uv_set_process_title(const char* title) {
uv_err_t err; uv_err_t err;
int length; int length;
wchar_t* title_w = NULL; WCHAR* title_w = NULL;
uv__once_init(); uv__once_init();
@ -352,7 +352,7 @@ uv_err_t uv_set_process_title(const char* title) {
} }
/* Convert to wide-char string */ /* Convert to wide-char string */
title_w = (wchar_t*)malloc(sizeof(wchar_t) * length); title_w = (WCHAR*)malloc(sizeof(WCHAR) * length);
if (!title_w) { if (!title_w) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
} }
@ -387,7 +387,7 @@ done:
static int uv__get_process_title() { static int uv__get_process_title() {
wchar_t title_w[MAX_TITLE_LENGTH]; WCHAR title_w[MAX_TITLE_LENGTH];
int length; int length;
if (!GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR))) { if (!GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR))) {

View File

@ -103,8 +103,8 @@ int process_start(char *name, char *part, process_info_t *p) {
goto error; goto error;
if (part) { if (part) {
if (_snwprintf((wchar_t*)args, if (_snwprintf((WCHAR*)args,
sizeof(args) / sizeof(wchar_t), sizeof(args) / sizeof(WCHAR),
L"\"%s\" %S %S", L"\"%s\" %S %S",
image, image,
name, name,
@ -112,8 +112,8 @@ int process_start(char *name, char *part, process_info_t *p) {
goto error; goto error;
} }
} else { } else {
if (_snwprintf((wchar_t*)args, if (_snwprintf((WCHAR*)args,
sizeof(args) / sizeof(wchar_t), sizeof(args) / sizeof(WCHAR),
L"\"%s\" %S", L"\"%s\" %S",
image, image,
name) < 0) { name) < 0) {

View File

@ -590,10 +590,10 @@ TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) {
uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr); uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr);
WCHAR* quote_cmd_arg(const wchar_t *source, wchar_t *target); WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target);
TEST_IMPL(argument_escaping) { TEST_IMPL(argument_escaping) {
const wchar_t* test_str[] = { const WCHAR* test_str[] = {
L"HelloWorld", L"HelloWorld",
L"Hello World", L"Hello World",
L"Hello\"World", L"Hello\"World",
@ -605,9 +605,9 @@ TEST_IMPL(argument_escaping) {
L"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"" L"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\""
}; };
const int count = sizeof(test_str) / sizeof(*test_str); const int count = sizeof(test_str) / sizeof(*test_str);
wchar_t** test_output; WCHAR** test_output;
wchar_t* command_line; WCHAR* command_line;
wchar_t** cracked; WCHAR** cracked;
size_t total_size = 0; size_t total_size = 0;
int i; int i;
int num_args; int num_args;
@ -619,18 +619,18 @@ TEST_IMPL(argument_escaping) {
"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"", "c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"",
NULL NULL
}; };
wchar_t* verbatim_output; WCHAR* verbatim_output;
wchar_t* non_verbatim_output; WCHAR* non_verbatim_output;
test_output = calloc(count, sizeof(wchar_t*)); test_output = calloc(count, sizeof(WCHAR*));
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
test_output[i] = calloc(2 * (wcslen(test_str[i]) + 2), sizeof(wchar_t)); test_output[i] = calloc(2 * (wcslen(test_str[i]) + 2), sizeof(WCHAR));
quote_cmd_arg(test_str[i], test_output[i]); quote_cmd_arg(test_str[i], test_output[i]);
wprintf(L"input : %s\n", test_str[i]); wprintf(L"input : %s\n", test_str[i]);
wprintf(L"output: %s\n", test_output[i]); wprintf(L"output: %s\n", test_output[i]);
total_size += wcslen(test_output[i]) + 1; total_size += wcslen(test_output[i]) + 1;
} }
command_line = calloc(total_size + 1, sizeof(wchar_t)); command_line = calloc(total_size + 1, sizeof(WCHAR));
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
wcscat(command_line, test_output[i]); wcscat(command_line, test_output[i]);
wcscat(command_line, L" "); wcscat(command_line, L" ");
@ -667,7 +667,7 @@ TEST_IMPL(argument_escaping) {
return 0; return 0;
} }
wchar_t* make_program_env(char** env_block); WCHAR* make_program_env(char** env_block);
TEST_IMPL(environment_creation) { TEST_IMPL(environment_creation) {
int i; int i;
@ -680,22 +680,22 @@ TEST_IMPL(environment_creation) {
NULL NULL
}; };
wchar_t expected[512]; WCHAR expected[512];
wchar_t* ptr = expected; WCHAR* ptr = expected;
wchar_t* result; WCHAR* result;
wchar_t* str; WCHAR* str;
for (i = 0; i < sizeof(environment) / sizeof(environment[0]) - 1; i++) { for (i = 0; i < sizeof(environment) / sizeof(environment[0]) - 1; i++) {
ptr += uv_utf8_to_utf16(environment[i], ptr, expected + sizeof(expected) - ptr); ptr += uv_utf8_to_utf16(environment[i], ptr, expected + sizeof(expected) - ptr);
} }
memcpy(ptr, L"SYSTEMROOT=", sizeof(L"SYSTEMROOT=")); memcpy(ptr, L"SYSTEMROOT=", sizeof(L"SYSTEMROOT="));
ptr += sizeof(L"SYSTEMROOT=")/sizeof(wchar_t) - 1; ptr += sizeof(L"SYSTEMROOT=")/sizeof(WCHAR) - 1;
ptr += GetEnvironmentVariableW(L"SYSTEMROOT", ptr, expected + sizeof(expected) - ptr); ptr += GetEnvironmentVariableW(L"SYSTEMROOT", ptr, expected + sizeof(expected) - ptr);
++ptr; ++ptr;
memcpy(ptr, L"SYSTEMDRIVE=", sizeof(L"SYSTEMDRIVE=")); memcpy(ptr, L"SYSTEMDRIVE=", sizeof(L"SYSTEMDRIVE="));
ptr += sizeof(L"SYSTEMDRIVE=")/sizeof(wchar_t) - 1; ptr += sizeof(L"SYSTEMDRIVE=")/sizeof(WCHAR) - 1;
ptr += GetEnvironmentVariableW(L"SYSTEMDRIVE", ptr, expected + sizeof(expected) - ptr); ptr += GetEnvironmentVariableW(L"SYSTEMDRIVE", ptr, expected + sizeof(expected) - ptr);
++ptr; ++ptr;
*ptr = '\0'; *ptr = '\0';