[nginx] Win32: non-ASCII directory names support in ngx_getcwd().
Sergey Kandaurov
pluknet at nginx.com
Fri Feb 24 10:32:53 UTC 2023
details: https://hg.nginx.org/nginx/rev/8ea2e052feb4
branches:
changeset: 8132:8ea2e052feb4
user: Maxim Dounin <mdounin at mdounin.ru>
date: Thu Feb 23 20:49:44 2023 +0300
description:
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.
diffstat:
src/os/win32/ngx_files.c | 34 ++++++++++++++++++++++++++++++++++
src/os/win32/ngx_files.h | 6 +++++-
2 files changed, 39 insertions(+), 1 deletions(-)
diffs (61 lines):
diff -r 751f79bd802c -r 8ea2e052feb4 src/os/win32/ngx_files.c
--- a/src/os/win32/ngx_files.c Thu Feb 23 20:49:41 2023 +0300
+++ b/src/os/win32/ngx_files.c Thu Feb 23 20:49:44 2023 +0300
@@ -429,6 +429,40 @@ ngx_realpath(u_char *path, u_char *resol
}
+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)
{
diff -r 751f79bd802c -r 8ea2e052feb4 src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h Thu Feb 23 20:49:41 2023 +0300
+++ b/src/os/win32/ngx_files.h Thu Feb 23 20:49:44 2023 +0300
@@ -178,8 +178,12 @@ void ngx_close_file_mapping(ngx_file_map
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
More information about the nginx-devel
mailing list