44
44
#include "ext/standard/basic_functions.h"
45
45
#include "ext/standard/php_filestat.h"
46
46
47
+ #define SPL_HAS_FLAG (flags , test_flag ) ((flags & test_flag) ? 1 : 0)
48
+
47
49
/* declare the class handlers */
48
50
static zend_object_handlers spl_filesystem_object_handlers ;
49
51
@@ -185,7 +187,7 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in
185
187
{
186
188
zstr path ;
187
189
zend_uchar path_type ;
188
- char slash = intern -> flags & SPL_FILE_DIR_UNIXPATHS ? '/' : DEFAULT_SLASH ;
190
+ char slash = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
189
191
190
192
if (!intern -> file_name .v ) {
191
193
switch (intern -> type ) {
@@ -228,7 +230,7 @@ static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
228
230
static void spl_filesystem_dir_open (spl_filesystem_object * intern , zend_uchar type , zstr path , int path_len TSRMLS_DC )
229
231
{
230
232
int options = REPORT_ERRORS ;
231
- int skip_dots = intern -> flags & SPL_FILE_DIR_SKIPDOTS ;
233
+ int skip_dots = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_SKIPDOTS ) ;
232
234
233
235
#if HELLY_0
234
236
if (php_stream_is (intern -> u .dir .dirp , & php_glob_stream_ops )) {
@@ -322,7 +324,7 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC)
322
324
old_object = zend_objects_get_address (zobject TSRMLS_CC );
323
325
source = (spl_filesystem_object * )old_object ;
324
326
325
- skip_dots = source -> flags & SPL_FILE_DIR_SKIPDOTS ;
327
+ skip_dots = SPL_HAS_FLAG ( source -> flags , SPL_FILE_DIR_SKIPDOTS ) ;
326
328
327
329
new_obj_val = spl_filesystem_object_new_ex (old_object -> ce , & intern TSRMLS_CC );
328
330
new_object = & intern -> std ;
@@ -666,7 +668,7 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T
666
668
667
669
UChar u_glob [sizeof ("glob://" )];
668
670
669
- void spl_filesystem_object_construct (INTERNAL_FUNCTION_PARAMETERS , int ctor_flags ) /* {{{ */
671
+ void spl_filesystem_object_construct (INTERNAL_FUNCTION_PARAMETERS , long ctor_flags ) /* {{{ */
670
672
{
671
673
spl_filesystem_object * intern ;
672
674
zstr path ;
@@ -677,19 +679,19 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, int ctor_flag
677
679
678
680
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC );
679
681
680
- if (ctor_flags & DIT_CTOR_FLAGS ) {
682
+ if (SPL_HAS_FLAG ( ctor_flags , DIT_CTOR_FLAGS ) ) {
681
683
flags = SPL_FILE_DIR_KEY_AS_PATHNAME |SPL_FILE_DIR_CURRENT_AS_FILEINFO ;
682
684
parsed = zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "t|l" , & path , & len , & path_type , & flags );
683
685
} else {
684
686
flags = SPL_FILE_DIR_KEY_AS_PATHNAME |SPL_FILE_DIR_CURRENT_AS_SELF ;
685
687
parsed = zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "t" , & path , & len , & path_type );
686
688
}
687
689
688
- if (ctor_flags & SPL_FILE_DIR_SKIPDOTS ) {
690
+ if (SPL_HAS_FLAG ( ctor_flags , SPL_FILE_DIR_SKIPDOTS ) ) {
689
691
flags |= SPL_FILE_DIR_SKIPDOTS ;
690
692
}
691
693
692
- if (ctor_flags & SPL_FILE_DIR_UNIXPATHS ) {
694
+ if (SPL_HAS_FLAG ( ctor_flags , SPL_FILE_DIR_UNIXPATHS ) ) {
693
695
flags |= SPL_FILE_DIR_UNIXPATHS ;
694
696
}
695
697
@@ -706,7 +708,7 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, int ctor_flag
706
708
intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
707
709
intern -> flags = flags ;
708
710
709
- if ((ctor_flags & DIT_CTOR_GLOB ) && (
711
+ if (SPL_HAS_FLAG (ctor_flags , DIT_CTOR_GLOB ) && (
710
712
(path_type == IS_STRING && strstr (path .s , "glob://" ) != path .s ) ||
711
713
(path_type == IS_UNICODE && u_strstr (path .u , u_glob ) != path .u )
712
714
)) {
@@ -771,7 +773,7 @@ SPL_METHOD(DirectoryIterator, current)
771
773
SPL_METHOD (DirectoryIterator , next )
772
774
{
773
775
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
774
- int skip_dots = intern -> flags & SPL_FILE_DIR_SKIPDOTS ;
776
+ int skip_dots = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_SKIPDOTS ) ;
775
777
776
778
intern -> u .dir .index ++ ;
777
779
do {
@@ -1388,7 +1390,7 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren)
1388
1390
zval zpath , zflags ;
1389
1391
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1390
1392
spl_filesystem_object * subdir ;
1391
- char slash = intern -> flags & SPL_FILE_DIR_UNIXPATHS ? '/' : DEFAULT_SLASH ;
1393
+ char slash = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
1392
1394
1393
1395
spl_filesystem_object_get_file_name (intern TSRMLS_CC );
1394
1396
@@ -1439,7 +1441,7 @@ SPL_METHOD(RecursiveDirectoryIterator, getSubPathname)
1439
1441
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1440
1442
zstr sub_name ;
1441
1443
int sub_len ;
1442
- char slash = intern -> flags & SPL_FILE_DIR_UNIXPATHS ? '/' : DEFAULT_SLASH ;
1444
+ char slash = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
1443
1445
1444
1446
if (intern -> u .dir .sub_path .v ) {
1445
1447
sub_len = zspprintf (intern -> u .dir .sub_path_type , & sub_name , 0 , "%R%c%s" , intern -> u .dir .sub_path_type , intern -> u .dir .sub_path , slash , intern -> u .dir .entry .d_name );
@@ -1912,7 +1914,7 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS
1912
1914
intern -> u .file .current_line = estrdup ("" );
1913
1915
intern -> u .file .current_line_len = 0 ;
1914
1916
} else {
1915
- if (intern -> flags & SPL_FILE_OBJECT_DROP_NEW_LINE ) {
1917
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_DROP_NEW_LINE ) ) {
1916
1918
line_len = strcspn (buf , "\r\n" );
1917
1919
buf [line_len ] = '\0' ;
1918
1920
}
@@ -1988,7 +1990,7 @@ static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char deli
1988
1990
1989
1991
do {
1990
1992
ret = spl_filesystem_file_read (intern , 1 TSRMLS_CC );
1991
- } while (ret == SUCCESS && !intern -> u .file .current_line_len && (intern -> flags & SPL_FILE_OBJECT_SKIP_EMPTY ));
1993
+ } while (ret == SUCCESS && !intern -> u .file .current_line_len && SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_SKIP_EMPTY ));
1992
1994
1993
1995
if (ret == SUCCESS ) {
1994
1996
size_t buf_len = intern -> u .file .current_line_len ;
@@ -2017,14 +2019,14 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje
2017
2019
zval * retval = NULL ;
2018
2020
2019
2021
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
2020
- if (intern -> flags & SPL_FILE_OBJECT_READ_CSV || intern -> u .file .func_getCurr -> common .scope != spl_ce_SplFileObject ) {
2022
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_CSV ) || intern -> u .file .func_getCurr -> common .scope != spl_ce_SplFileObject ) {
2021
2023
if (php_stream_eof (intern -> u .file .stream )) {
2022
2024
if (!silent ) {
2023
2025
zend_throw_exception_ex (spl_ce_RuntimeException , 0 TSRMLS_CC , "Cannot read from file %s" , intern -> file_name );
2024
2026
}
2025
2027
return FAILURE ;
2026
2028
}
2027
- if (intern -> flags & SPL_FILE_OBJECT_READ_CSV ) {
2029
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_CSV ) ) {
2028
2030
return spl_filesystem_file_read_csv (intern , intern -> u .file .delimiter , intern -> u .file .enclosure , intern -> u .file .escape , NULL TSRMLS_CC );
2029
2031
} else {
2030
2032
zend_call_method_with_0_params (& this_ptr , Z_OBJCE_P (getThis ()), & intern -> u .file .func_getCurr , "getCurrentLine" , & retval );
@@ -2061,7 +2063,7 @@ static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRML
2061
2063
case IS_UNICODE :
2062
2064
return Z_STRLEN_P (intern -> u .file .current_zval ) == 0 ;
2063
2065
case IS_ARRAY :
2064
- if ((intern -> flags & SPL_FILE_OBJECT_READ_CSV )
2066
+ if (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_CSV )
2065
2067
&& zend_hash_num_elements (Z_ARRVAL_P (intern -> u .file .current_zval )) == 1 ) {
2066
2068
zval * * first = Z_ARRVAL_P (intern -> u .file .current_zval )-> pListHead -> pData ;
2067
2069
@@ -2084,7 +2086,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object
2084
2086
{
2085
2087
int ret = spl_filesystem_file_read_line_ex (this_ptr , intern , silent TSRMLS_CC );
2086
2088
2087
- while ((intern -> flags & SPL_FILE_OBJECT_SKIP_EMPTY ) && ret == SUCCESS && spl_filesystem_file_is_empty_line (intern TSRMLS_CC )) {
2089
+ while (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_SKIP_EMPTY ) && ret == SUCCESS && spl_filesystem_file_is_empty_line (intern TSRMLS_CC )) {
2088
2090
spl_filesystem_file_free_line (intern TSRMLS_CC );
2089
2091
ret = spl_filesystem_file_read_line_ex (this_ptr , intern , silent TSRMLS_CC );
2090
2092
}
@@ -2101,7 +2103,7 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
2101
2103
spl_filesystem_file_free_line (intern TSRMLS_CC );
2102
2104
intern -> u .file .current_line_num = 0 ;
2103
2105
}
2104
- if (intern -> flags & SPL_FILE_OBJECT_READ_AHEAD ) {
2106
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2105
2107
spl_filesystem_file_read_line (this_ptr , intern , 1 TSRMLS_CC );
2106
2108
}
2107
2109
} /* }}} */
@@ -2226,7 +2228,7 @@ SPL_METHOD(SplFileObject, valid)
2226
2228
{
2227
2229
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
2228
2230
2229
- if (intern -> flags & SPL_FILE_OBJECT_READ_AHEAD ) {
2231
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2230
2232
RETURN_BOOL (intern -> u .file .current_line || intern -> u .file .current_zval );
2231
2233
} else {
2232
2234
RETVAL_BOOL (!php_stream_eof (intern -> u .file .stream ));
@@ -2254,7 +2256,7 @@ SPL_METHOD(SplFileObject, current)
2254
2256
if (!intern -> u .file .current_line && !intern -> u .file .current_zval ) {
2255
2257
spl_filesystem_file_read_line (getThis (), intern , 1 TSRMLS_CC );
2256
2258
}
2257
- if (intern -> u .file .current_line && (!(intern -> flags & SPL_FILE_OBJECT_READ_CSV ) || !intern -> u .file .current_zval )) {
2259
+ if (intern -> u .file .current_line && (!SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_CSV ) || !intern -> u .file .current_zval )) {
2258
2260
RETURN_RT_STRINGL (intern -> u .file .current_line , intern -> u .file .current_line_len , ZSTR_DUPLICATE );
2259
2261
} else if (intern -> u .file .current_zval ) {
2260
2262
RETURN_ZVAL (intern -> u .file .current_zval , 1 , 0 );
@@ -2282,7 +2284,7 @@ SPL_METHOD(SplFileObject, next)
2282
2284
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
2283
2285
2284
2286
spl_filesystem_file_free_line (intern TSRMLS_CC );
2285
- if (intern -> flags & SPL_FILE_OBJECT_READ_AHEAD ) {
2287
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2286
2288
spl_filesystem_file_read_line (getThis (), intern , 1 TSRMLS_CC );
2287
2289
}
2288
2290
intern -> u .file .current_line_num ++ ;
0 commit comments