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 \
HANDLE handle; \
wchar_t* name; \
WCHAR* name; \
union { \
struct { uv_pipe_server_fields }; \
struct { uv_pipe_connection_fields }; \
@ -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;
@ -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);

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) {
wchar_t filename_w[32768];
WCHAR filename_w[32768];
lib->handle = 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,
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");
}
@ -111,7 +111,7 @@ 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");
}
@ -119,7 +119,7 @@ static int uv_split_path(const wchar_t* filename, wchar_t** dir,
(*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");
}
@ -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) {
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);
@ -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);
/* 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;
}
@ -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);
@ -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) {
/*
@ -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");
}
@ -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");
}
@ -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. */

View File

@ -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);
@ -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;
@ -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;
@ -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;
}
@ -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;
}

View File

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

View File

@ -36,7 +36,7 @@
typedef struct env_var {
const char* narrow;
const wchar_t* wide;
const WCHAR* wide;
int len; /* including null or '=' */
int supplied;
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
*/
static wchar_t* search_path_join_test(const wchar_t* dir,
static WCHAR* search_path_join_test(const WCHAR* dir,
int dir_len,
const wchar_t* name,
const WCHAR* name,
int name_len,
const wchar_t* ext,
const WCHAR* ext,
int ext_len,
const wchar_t* cwd,
const WCHAR* cwd,
int cwd_len) {
wchar_t *result, *result_pos;
WCHAR *result, *result_pos;
DWORD attrs;
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 */
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));
/* Copy cwd */
@ -192,14 +192,14 @@ static wchar_t* search_path_join_test(const wchar_t* dir,
/*
* 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,
const wchar_t *name,
const WCHAR *name,
int name_len,
wchar_t *cwd,
WCHAR *cwd,
int cwd_len,
int name_has_ext) {
wchar_t* result;
WCHAR* result;
/* If the name itself has a nonempty extension, try this extension first */
if (name_has_ext) {
@ -273,14 +273,14 @@ static wchar_t* path_search_walk_ext(const wchar_t *dir,
*
* TODO: correctly interpret UNC paths
*/
static wchar_t* search_path(const wchar_t *file,
wchar_t *cwd,
const wchar_t *path) {
static WCHAR* search_path(const WCHAR *file,
WCHAR *cwd,
const WCHAR *path) {
int file_has_dir;
wchar_t* result = NULL;
wchar_t *file_name_start;
wchar_t *dot;
const wchar_t *dir_start, *dir_end, *dir_path;
WCHAR* result = NULL;
WCHAR *file_name_start;
WCHAR *dot;
const WCHAR *dir_start, *dir_end, *dir_path;
int dir_len;
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 */
/* 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[-1] != L'\\'
&& file_name_start[-1] != L'/'
@ -379,10 +379,10 @@ static wchar_t* search_path(const wchar_t *file,
* Quotes command line arguments
* 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),
i, quote_hit;
wchar_t* start;
WCHAR* start;
/*
* 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
* values for them.
*/
wchar_t* make_program_env(char** env_block) {
wchar_t* dst;
wchar_t* ptr;
WCHAR* make_program_env(char** env_block) {
WCHAR* dst;
WCHAR* ptr;
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 i;
DWORD var_size;
@ -590,18 +590,18 @@ wchar_t* make_program_env(char** env_block) {
check_required_vars_contains_var(required_vars,
ARRAY_SIZE(required_vars),
*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) {
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);
if (var_size == 0) {
uv_fatal_error(GetLastError(), "GetEnvironmentVariableW");
}
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) {
int i;
uv_err_t err = uv_ok_;
wchar_t* path = NULL;
WCHAR* path = NULL;
BOOL result;
wchar_t* application_path = NULL, *application = NULL, *arguments = NULL,
WCHAR* application_path = NULL, *application = NULL, *arguments = NULL,
*env = NULL, *cwd = NULL;
STARTUPINFOW startup;
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) {
return WideCharToMultiByte(CP_UTF8,
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) {
return MultiByteToWideChar(CP_UTF8,
0,
@ -113,7 +113,7 @@ int uv_exepath(char* buffer, size_t* 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) {
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 err;
int length;
wchar_t* title_w = NULL;
WCHAR* title_w = NULL;
uv__once_init();
@ -352,7 +352,7 @@ uv_err_t uv_set_process_title(const char* title) {
}
/* Convert to wide-char string */
title_w = (wchar_t*)malloc(sizeof(wchar_t) * length);
title_w = (WCHAR*)malloc(sizeof(WCHAR) * length);
if (!title_w) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
@ -387,7 +387,7 @@ done:
static int uv__get_process_title() {
wchar_t title_w[MAX_TITLE_LENGTH];
WCHAR title_w[MAX_TITLE_LENGTH];
int length;
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;
if (part) {
if (_snwprintf((wchar_t*)args,
sizeof(args) / sizeof(wchar_t),
if (_snwprintf((WCHAR*)args,
sizeof(args) / sizeof(WCHAR),
L"\"%s\" %S %S",
image,
name,
@ -112,8 +112,8 @@ int process_start(char *name, char *part, process_info_t *p) {
goto error;
}
} else {
if (_snwprintf((wchar_t*)args,
sizeof(args) / sizeof(wchar_t),
if (_snwprintf((WCHAR*)args,
sizeof(args) / sizeof(WCHAR),
L"\"%s\" %S",
image,
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);
WCHAR* quote_cmd_arg(const wchar_t *source, wchar_t *target);
WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target);
TEST_IMPL(argument_escaping) {
const wchar_t* test_str[] = {
const WCHAR* test_str[] = {
L"HelloWorld",
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')\""
};
const int count = sizeof(test_str) / sizeof(*test_str);
wchar_t** test_output;
wchar_t* command_line;
wchar_t** cracked;
WCHAR** test_output;
WCHAR* command_line;
WCHAR** cracked;
size_t total_size = 0;
int i;
int num_args;
@ -619,18 +619,18 @@ TEST_IMPL(argument_escaping) {
"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"",
NULL
};
wchar_t* verbatim_output;
wchar_t* non_verbatim_output;
WCHAR* 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) {
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]);
wprintf(L"input : %s\n", test_str[i]);
wprintf(L"output: %s\n", test_output[i]);
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) {
wcscat(command_line, test_output[i]);
wcscat(command_line, L" ");
@ -667,7 +667,7 @@ TEST_IMPL(argument_escaping) {
return 0;
}
wchar_t* make_program_env(char** env_block);
WCHAR* make_program_env(char** env_block);
TEST_IMPL(environment_creation) {
int i;
@ -680,22 +680,22 @@ TEST_IMPL(environment_creation) {
NULL
};
wchar_t expected[512];
wchar_t* ptr = expected;
wchar_t* result;
wchar_t* str;
WCHAR expected[512];
WCHAR* ptr = expected;
WCHAR* result;
WCHAR* str;
for (i = 0; i < sizeof(environment) / sizeof(environment[0]) - 1; i++) {
ptr += uv_utf8_to_utf16(environment[i], ptr, expected + sizeof(expected) - ptr);
}
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;
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;
*ptr = '\0';