Win32: non-ASCII directory names support in ngx_getcwd().

This makes it possible to start nginx without a prefix explicitly set
in a directory with non-ASCII characters in it.
This commit is contained in:
Maxim Dounin 2023-02-23 20:49:44 +03:00
parent 3861363449
commit 4408a67ee7
2 changed files with 39 additions and 1 deletions

View File

@ -429,6 +429,40 @@ ngx_realpath(u_char *path, u_char *resolved)
}
size_t
ngx_getcwd(u_char *buf, size_t size)
{
u_char *p;
size_t n;
u_short utf16[NGX_MAX_PATH];
n = GetCurrentDirectoryW(NGX_MAX_PATH, utf16);
if (n == 0) {
return 0;
}
if (n > NGX_MAX_PATH) {
ngx_set_errno(ERROR_INSUFFICIENT_BUFFER);
return 0;
}
p = ngx_utf16_to_utf8(buf, utf16, &size, NULL);
if (p == NULL) {
return 0;
}
if (p != buf) {
ngx_free(p);
ngx_set_errno(ERROR_INSUFFICIENT_BUFFER);
return 0;
}
return size - 1;
}
ngx_int_t
ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir)
{

View File

@ -178,8 +178,12 @@ void ngx_close_file_mapping(ngx_file_mapping_t *fm);
u_char *ngx_realpath(u_char *path, u_char *resolved);
#define ngx_realpath_n ""
#define ngx_getcwd(buf, size) GetCurrentDirectory(size, (char *) buf)
size_t ngx_getcwd(u_char *buf, size_t size);
#define ngx_getcwd_n "GetCurrentDirectory()"
#define ngx_path_separator(c) ((c) == '/' || (c) == '\\')
#define NGX_HAVE_MAX_PATH 1