|
|
@ -47,7 +47,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
static char *process_title; |
|
|
|
|
|
|
|
static uv_once_t uv_process_title_init_guard_ = UV_ONCE_INIT; |
|
|
|
static CRITICAL_SECTION process_title_lock; |
|
|
|
|
|
|
|
int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, |
|
|
|
char* utf8Buffer, size_t utf8Size) { |
|
|
@ -263,11 +264,18 @@ char** uv_setup_args(int argc, char** argv) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void uv_process_title_init(void) { |
|
|
|
InitializeCriticalSection(&process_title_lock); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uv_err_t uv_set_process_title(const char* title) { |
|
|
|
uv_err_t err; |
|
|
|
int length; |
|
|
|
wchar_t* title_w = NULL; |
|
|
|
|
|
|
|
uv_once(&uv_process_title_init_guard_, uv_process_title_init); |
|
|
|
|
|
|
|
/* Find out how big the buffer for the wide-char title must be */ |
|
|
|
length = uv_utf8_to_utf16(title, NULL, 0); |
|
|
|
if (!length) { |
|
|
@ -297,8 +305,10 @@ uv_err_t uv_set_process_title(const char* title) { |
|
|
|
goto done; |
|
|
|
} |
|
|
|
|
|
|
|
EnterCriticalSection(&process_title_lock); |
|
|
|
free(process_title); |
|
|
|
process_title = strdup(title); |
|
|
|
LeaveCriticalSection(&process_title_lock); |
|
|
|
|
|
|
|
err = uv_ok_; |
|
|
|
|
|
|
@ -339,6 +349,9 @@ static int uv__get_process_title() { |
|
|
|
|
|
|
|
|
|
|
|
uv_err_t uv_get_process_title(char* buffer, size_t size) { |
|
|
|
uv_once(&uv_process_title_init_guard_, uv_process_title_init); |
|
|
|
|
|
|
|
EnterCriticalSection(&process_title_lock); |
|
|
|
/*
|
|
|
|
* If the process_title was never read before nor explicitly set, |
|
|
|
* we must query it with getConsoleTitleW |
|
|
@ -349,6 +362,7 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) { |
|
|
|
|
|
|
|
assert(process_title); |
|
|
|
strncpy(buffer, process_title, size); |
|
|
|
LeaveCriticalSection(&process_title_lock); |
|
|
|
|
|
|
|
return uv_ok_; |
|
|
|
} |
|
|
|