*) autoconfigure struct dirent capabilities
*) move src/os/.../ngx_types.h's content into src/os/.../ngx_files.h and
delete src/os/.../ngx_types.h
diff --git a/auto/sources b/auto/sources
index 66859ae..5d1ec75 100644
--- a/auto/sources
+++ b/auto/sources
@@ -131,7 +131,6 @@
UNIX_DEPS="$CORE_DEPS $EVENT_DEPS \
src/os/unix/ngx_time.h \
- src/os/unix/ngx_types.h \
src/os/unix/ngx_errno.h \
src/os/unix/ngx_alloc.h \
src/os/unix/ngx_files.h \
@@ -208,7 +207,6 @@
WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \
src/os/win32/ngx_win32_config.h \
src/os/win32/ngx_time.h \
- src/os/win32/ngx_types.h \
src/os/win32/ngx_errno.h \
src/os/win32/ngx_alloc.h \
src/os/win32/ngx_files.h \
diff --git a/auto/unix b/auto/unix
index 7c02ecc..245d4f7 100755
--- a/auto/unix
+++ b/auto/unix
@@ -229,3 +229,23 @@
ngx_feature_libs=
ngx_feature_test="struct tm tm; tm.tm_gmtoff = 0"
. auto/feature
+
+
+ngx_feature="struct dirent.d_namlen"
+ngx_feature_name="NGX_HAVE_D_NAMLEN"
+ngx_feature_run=no
+ngx_feature_incs="#include <dirent.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="struct dirent dir; dir.d_namlen = 0"
+. auto/feature
+
+
+ngx_feature="struct dirent.d_type"
+ngx_feature_name="NGX_HAVE_D_TYPE"
+ngx_feature_run=no
+ngx_feature_incs="#include <dirent.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="struct dirent dir; dir.d_type = DT_REG"
+. auto/feature
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 24ffc3d..d5f18b8 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -40,11 +40,11 @@
#include <ngx_rbtree.h>
#include <ngx_time.h>
#include <ngx_socket.h>
-#include <ngx_types.h>
+#include <ngx_string.h>
+#include <ngx_files.h>
#include <ngx_shmem.h>
#include <ngx_process.h>
#include <ngx_user.h>
-#include <ngx_string.h>
#include <ngx_parse.h>
#include <ngx_log.h>
#include <ngx_alloc.h>
@@ -55,7 +55,6 @@
#include <ngx_list.h>
#include <ngx_hash.h>
#include <ngx_file.h>
-#include <ngx_files.h>
#include <ngx_crc.h>
#include <ngx_crc32.h>
#if (NGX_PCRE)
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index 8d27338..ab86146 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -249,12 +249,33 @@
}
dir->valid_info = 0;
+#if (NGX_HAVE_D_TYPE)
+ dir->valid_type = 1;
+#else
+ dir->valid_type = 0;
+#endif
return NGX_OK;
}
ngx_int_t
+ngx_read_dir(ngx_dir_t *dir)
+{
+ dir->de = readdir(dir->dir);
+
+ if (dir->de) {
+#if (NGX_HAVE_D_TYPE)
+ dir->type = dir->de->d_type;
+#endif
+ return NGX_OK;
+ }
+
+ return NGX_ERROR;
+}
+
+
+ngx_int_t
ngx_open_glob(ngx_glob_t *gl)
{
int n;
diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h
index 9cf4f22..9988bcc 100644
--- a/src/os/unix/ngx_files.h
+++ b/src/os/unix/ngx_files.h
@@ -12,6 +12,31 @@
#include <ngx_core.h>
+typedef int ngx_fd_t;
+typedef struct stat ngx_file_info_t;
+typedef ino_t ngx_file_uniq_t;
+
+
+typedef struct {
+ DIR *dir;
+ struct dirent *de;
+ struct stat info;
+
+ unsigned type:8;
+ unsigned valid_info:1;
+ unsigned valid_type:1;
+} ngx_dir_t;
+
+
+typedef struct {
+ size_t n;
+ glob_t pglob;
+ u_char *pattern;
+ ngx_log_t *log;
+ ngx_uint_t test;
+} ngx_glob_t;
+
+
#define NGX_INVALID_FILE -1
#define NGX_FILE_ERROR -1
@@ -135,8 +160,7 @@
#define ngx_close_dir_n "closedir()"
-#define ngx_read_dir(d) \
- (((d)->de = readdir((d)->dir)) ? NGX_OK : NGX_ERROR)
+ngx_int_t ngx_read_dir(ngx_dir_t *dir);
#define ngx_read_dir_n "readdir()"
@@ -152,7 +176,7 @@
#define ngx_de_name(dir) ((u_char *) (dir)->de->d_name)
-#if (NGX_FREEBSD)
+#if (NGX_HAVE_D_NAMLEN)
#define ngx_de_namelen(dir) (dir)->de->d_namlen
#else
#define ngx_de_namelen(dir) ngx_strlen((dir)->de->d_name)
@@ -161,23 +185,26 @@
#define ngx_de_info_n "stat()"
#define ngx_de_link_info(name, dir) lstat((const char *) name, &(dir)->info)
#define ngx_de_link_info_n "lstat()"
+
+#if (NGX_HAVE_D_TYPE)
+
+#define ngx_de_is_dir(dir) ((dir)->type == DT_DIR)
+#define ngx_de_is_file(dir) ((dir)->type == DT_REG)
+#define ngx_de_is_link(dir) ((dir)->type == DT_LINK)
+
+#else
+
#define ngx_de_is_dir(dir) (S_ISDIR((dir)->info.st_mode))
#define ngx_de_is_file(dir) (S_ISREG((dir)->info.st_mode))
#define ngx_de_is_link(dir) (S_ISLNK((dir)->info.st_mode))
+
+#endif
+
#define ngx_de_access(dir) (((dir)->info.st_mode) & 0777)
#define ngx_de_size(dir) (dir)->info.st_size
#define ngx_de_mtime(dir) (dir)->info.st_mtime
-typedef struct {
- size_t n;
- glob_t pglob;
- u_char *pattern;
- ngx_log_t *log;
- ngx_uint_t test;
-} ngx_glob_t;
-
-
ngx_int_t ngx_open_glob(ngx_glob_t *gl);
#define ngx_open_glob_n "glob()"
ngx_int_t ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name);
diff --git a/src/os/unix/ngx_types.h b/src/os/unix/ngx_types.h
deleted file mode 100644
index 870c414..0000000
--- a/src/os/unix/ngx_types.h
+++ /dev/null
@@ -1,27 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- */
-
-
-#ifndef _NGX_TYPES_H_INCLUDED_
-#define _NGX_TYPES_H_INCLUDED_
-
-
-#include <ngx_config.h>
-
-
-typedef int ngx_fd_t;
-typedef struct stat ngx_file_info_t;
-typedef ino_t ngx_file_uniq_t;
-
-typedef struct {
- DIR *dir;
- struct dirent *de;
- struct stat info;
-
- ngx_uint_t valid_info:1; /* unsigned valid_info:1; */
-} ngx_dir_t;
-
-
-#endif /* _NGX_TYPES_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 2d89890..20b5286 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -330,6 +330,7 @@
}
dir->valid_info = 1;
+ dir->valid_type = 1;
dir->ready = 1;
return NGX_OK;
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index d6a5e37..9f4f681 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -12,6 +12,36 @@
#include <ngx_core.h>
+typedef HANDLE ngx_fd_t;
+typedef BY_HANDLE_FILE_INFORMATION ngx_file_info_t;
+typedef uint64_t ngx_file_uniq_t;
+
+typedef struct {
+ HANDLE dir;
+ WIN32_FIND_DATA finddata;
+
+ unsigned valid_info:1;
+ unsigned valid_type:1;
+ unsigned ready:1;
+} ngx_dir_t;
+
+
+typedef struct {
+ HANDLE dir;
+ WIN32_FIND_DATA finddata;
+
+ unsigned ready:1;
+ unsigned test:1;
+ unsigned no_match:1;
+
+ u_char *pattern;
+ ngx_str_t name;
+ size_t last;
+ ngx_log_t *log;
+} ngx_glob_t;
+
+
+
/* INVALID_FILE_ATTRIBUTES is specified but not defined at least in MSVC6SP2 */
#ifndef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES 0xffffffff
@@ -184,20 +214,6 @@
| (dir)->finddata.ftLastWriteTime.dwLowDateTime) \
- 116444736000000000) / 10000000)
-typedef struct {
- HANDLE dir;
- WIN32_FIND_DATA finddata;
-
- unsigned ready:1;
- unsigned test:1;
- unsigned no_match:1;
-
- u_char *pattern;
- ngx_str_t name;
- size_t last;
- ngx_log_t *log;
-} ngx_glob_t;
-
ngx_int_t ngx_open_glob(ngx_glob_t *gl);
#define ngx_open_glob_n "FindFirstFile()"
diff --git a/src/os/win32/ngx_types.h b/src/os/win32/ngx_types.h
deleted file mode 100644
index 009ccc9..0000000
--- a/src/os/win32/ngx_types.h
+++ /dev/null
@@ -1,28 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- */
-
-
-#ifndef _NGX_TYPES_H_INCLUDED_
-#define _NGX_TYPES_H_INCLUDED_
-
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-
-
-typedef HANDLE ngx_fd_t;
-typedef BY_HANDLE_FILE_INFORMATION ngx_file_info_t;
-typedef uint64_t ngx_file_uniq_t;
-
-typedef struct {
- HANDLE dir;
- WIN32_FIND_DATA finddata;
-
- unsigned valid_info:1;
- unsigned ready:1;
-} ngx_dir_t;
-
-
-#endif /* _NGX_TYPES_H_INCLUDED_ */