diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2018-12-24 21:07:05 +0300 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2018-12-24 21:07:05 +0300 |
commit | aa741f87273f2137d9a52080593c5fe6f1d1b0ea (patch) | |
tree | 910786fc8f33014c148afcce1246214d3f1317e2 /src/os | |
parent | 499bb2655ee16e4659d571b413b1ea54fd19dcd1 (diff) |
Win32: removed NGX_DIR_MASK concept.
Previous interface of ngx_open_dir() assumed that passed directory name
has a room for NGX_DIR_MASK at the end (NGX_DIR_MASK_LEN bytes). While all
direct users of ngx_dir_open() followed this interface, this also implied
similar requirements for indirect uses - in particular, via ngx_walk_tree().
Currently none of ngx_walk_tree() uses provides appropriate space, and
fixing this does not look like a right way to go. Instead, ngx_dir_open()
interface was changed to not require any additional space and use
appropriate allocations instead.
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/unix/ngx_files.h | 3 | ||||
-rw-r--r-- | src/os/win32/ngx_files.c | 21 | ||||
-rw-r--r-- | src/os/win32/ngx_files.h | 3 |
3 files changed, 18 insertions, 9 deletions
diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h index 07872b138..383e38e65 100644 --- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -213,9 +213,6 @@ void ngx_close_file_mapping(ngx_file_mapping_t *fm); #endif -#define NGX_DIR_MASK_LEN 0 - - ngx_int_t ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir); #define ngx_open_dir_n "opendir()" diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c index 55d7f7696..0b131b58a 100644 --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -427,16 +427,31 @@ ngx_realpath(u_char *path, u_char *resolved) ngx_int_t ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) { - ngx_cpystrn(name->data + name->len, NGX_DIR_MASK, NGX_DIR_MASK_LEN + 1); + u_char *pattern, *p; + ngx_err_t err; + + pattern = malloc(name->len + 3); + if (pattern == NULL) { + return NGX_ERROR; + } - dir->dir = FindFirstFile((const char *) name->data, &dir->finddata); + p = ngx_cpymem(pattern, name->data, name->len); - name->data[name->len] = '\0'; + *p++ = '/'; + *p++ = '*'; + *p = '\0'; + + dir->dir = FindFirstFile((const char *) pattern, &dir->finddata); if (dir->dir == INVALID_HANDLE_VALUE) { + err = ngx_errno; + ngx_free(pattern); + ngx_set_errno(err); return NGX_ERROR; } + ngx_free(pattern); + dir->valid_info = 1; dir->ready = 1; diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h index 895daeab4..6eb720e78 100644 --- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -181,9 +181,6 @@ u_char *ngx_realpath(u_char *path, u_char *resolved); #define NGX_HAVE_MAX_PATH 1 #define NGX_MAX_PATH MAX_PATH -#define NGX_DIR_MASK (u_char *) "/*" -#define NGX_DIR_MASK_LEN 2 - ngx_int_t ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir); #define ngx_open_dir_n "FindFirstFile()" |