Skip to content

Commit 148a84f

Browse files
committed
Add UV::S_IFDIR + UV::S_IFREG constants
These constants allow differentiation between regular files (S_IFREG) and directories (S_IFDIR) when used for bitwise AND operations against the "mode" value returned from uv_fs_stat/fstat/lstat(). Example: uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function($r){ uv_fs_fstat(uv_default_loop(), $r, function($result, $da){ echo "is directory: ", ($da['mode'] & UV::S_IFDIR ? 'yes' : 'no'), "\n"; echo "if file: ", ($da['mode'] & UV::S_IFREG ? 'yes' : 'no'), "\n"; }); }); uv_run();
1 parent 75fd2ff commit 148a84f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

php_uv.h

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ typedef struct {
220220
#define PHP_UV_LIST_INSERT(type, handle) zend_list_insert(type, handle)
221221
#endif
222222

223+
224+
/* File/directory stat mode constants*/
225+
#ifdef PHP_WIN32
226+
#define S_IFDIR _S_IFDIR
227+
#define S_IFREG _S_IFREG
228+
#else
229+
#ifndef S_IFDIR
230+
#define S_IFDIR 0040000
231+
#endif
232+
#ifndef S_IFREG
233+
#define S_IFREG 0100000
234+
#endif
235+
#endif
236+
223237
/* TODO: remove these macro when libuv provides uv_inet_ntop & uv_inet_pton */
224238
#ifdef PHP_WIN32
225239
# include "libuv/src/ares/inet_net_pton.h"

uv.c

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ static int php_uv_class_init(TSRMLS_D)
5151
zend_declare_class_constant_long(uv_class_entry, "O_TRUNC", sizeof("O_TRUNC")-1, O_TRUNC TSRMLS_CC);
5252
zend_declare_class_constant_long(uv_class_entry, "O_APPEND", sizeof("O_APPEND")-1, O_APPEND TSRMLS_CC);
5353

54+
zend_declare_class_constant_long(uv_class_entry, "S_IFDIR", sizeof("S_IFDIR")-1, S_IFDIR TSRMLS_CC);
55+
zend_declare_class_constant_long(uv_class_entry, "S_IFREG", sizeof("S_IFREG")-1, S_IFREG TSRMLS_CC);
56+
5457
#ifndef PHP_WIN32
5558
zend_declare_class_constant_long(uv_class_entry, "O_NOCTTY", sizeof("O_NOCTTY")-1, O_NOCTTY TSRMLS_CC);
5659

0 commit comments

Comments
 (0)