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
@@ -175,7 +177,7 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *
175
177
176
178
static inline void spl_filesystem_object_get_file_name (spl_filesystem_object * intern TSRMLS_DC ) /* {{{ */
177
179
{
178
- char slash = intern -> flags & SPL_FILE_DIR_UNIXPATHS ? '/' : DEFAULT_SLASH ;
180
+ char slash = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
179
181
180
182
if (!intern -> file_name ) {
181
183
switch (intern -> type ) {
@@ -215,7 +217,7 @@ static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
215
217
/* open a directory resource */
216
218
static void spl_filesystem_dir_open (spl_filesystem_object * intern , char * path TSRMLS_DC )
217
219
{
218
- int skip_dots = intern -> flags & SPL_FILE_DIR_SKIPDOTS ;
220
+ int skip_dots = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_SKIPDOTS ) ;
219
221
220
222
intern -> type = SPL_FS_DIR ;
221
223
intern -> _path_len = strlen (path );
@@ -314,7 +316,7 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC)
314
316
case SPL_FS_DIR :
315
317
spl_filesystem_dir_open (intern , source -> _path TSRMLS_CC );
316
318
/* read until we hit the position in which we were before */
317
- skip_dots = source -> flags & SPL_FILE_DIR_SKIPDOTS ;
319
+ skip_dots = SPL_HAS_FLAG ( source -> flags , SPL_FILE_DIR_SKIPDOTS ) ;
318
320
for (index = 0 ; index < source -> u .dir .index ; ++ index ) {
319
321
do {
320
322
spl_filesystem_dir_read (intern TSRMLS_CC );
@@ -600,7 +602,7 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T
600
602
#define DIT_CTOR_FLAGS 0x00000001
601
603
#define DIT_CTOR_GLOB 0x00000002
602
604
603
- void spl_filesystem_object_construct (INTERNAL_FUNCTION_PARAMETERS , int ctor_flags ) /* {{{ */
605
+ void spl_filesystem_object_construct (INTERNAL_FUNCTION_PARAMETERS , long ctor_flags ) /* {{{ */
604
606
{
605
607
spl_filesystem_object * intern ;
606
608
char * path ;
@@ -610,17 +612,17 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, int ctor_flag
610
612
611
613
zend_replace_error_handling (EH_THROW , spl_ce_UnexpectedValueException , & error_handling TSRMLS_CC );
612
614
613
- if (ctor_flags & DIT_CTOR_FLAGS ) {
615
+ if (SPL_HAS_FLAG ( ctor_flags , DIT_CTOR_FLAGS ) ) {
614
616
flags = SPL_FILE_DIR_KEY_AS_PATHNAME |SPL_FILE_DIR_CURRENT_AS_FILEINFO ;
615
617
parsed = zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s|l" , & path , & len , & flags );
616
618
} else {
617
619
flags = SPL_FILE_DIR_KEY_AS_PATHNAME |SPL_FILE_DIR_CURRENT_AS_SELF ;
618
620
parsed = zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & path , & len );
619
621
}
620
- if (ctor_flags & SPL_FILE_DIR_SKIPDOTS ) {
622
+ if (SPL_HAS_FLAG ( ctor_flags , SPL_FILE_DIR_SKIPDOTS ) ) {
621
623
flags |= SPL_FILE_DIR_SKIPDOTS ;
622
624
}
623
- if (ctor_flags & SPL_FILE_DIR_UNIXPATHS ) {
625
+ if (SPL_HAS_FLAG ( ctor_flags , SPL_FILE_DIR_UNIXPATHS ) ) {
624
626
flags |= SPL_FILE_DIR_UNIXPATHS ;
625
627
}
626
628
if (parsed == FAILURE ) {
@@ -635,7 +637,7 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, int ctor_flag
635
637
636
638
intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
637
639
intern -> flags = flags ;
638
- if ((ctor_flags & DIT_CTOR_GLOB ) && strstr (path , "glob://" ) != path ) {
640
+ if (SPL_HAS_FLAG (ctor_flags , DIT_CTOR_GLOB ) && strstr (path , "glob://" ) != path ) {
639
641
spprintf (& path , 0 , "glob://%s" , path );
640
642
spl_filesystem_dir_open (intern , path TSRMLS_CC );
641
643
efree (path );
@@ -698,7 +700,7 @@ SPL_METHOD(DirectoryIterator, current)
698
700
SPL_METHOD (DirectoryIterator , next )
699
701
{
700
702
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
701
- int skip_dots = intern -> flags & SPL_FILE_DIR_SKIPDOTS ;
703
+ int skip_dots = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_SKIPDOTS ) ;
702
704
703
705
intern -> u .dir .index ++ ;
704
706
do {
@@ -1262,7 +1264,7 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren)
1262
1264
zval zpath , zflags ;
1263
1265
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1264
1266
spl_filesystem_object * subdir ;
1265
- char slash = intern -> flags & SPL_FILE_DIR_UNIXPATHS ? '/' : DEFAULT_SLASH ;
1267
+ char slash = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
1266
1268
1267
1269
spl_filesystem_object_get_file_name (intern TSRMLS_CC );
1268
1270
@@ -1309,7 +1311,7 @@ SPL_METHOD(RecursiveDirectoryIterator, getSubPathname)
1309
1311
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1310
1312
char * sub_name ;
1311
1313
int len ;
1312
- char slash = intern -> flags & SPL_FILE_DIR_UNIXPATHS ? '/' : DEFAULT_SLASH ;
1314
+ char slash = SPL_HAS_FLAG ( intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
1313
1315
1314
1316
if (intern -> u .dir .sub_path ) {
1315
1317
len = spprintf (& sub_name , 0 , "%s%c%s" , intern -> u .dir .sub_path , slash , intern -> u .dir .entry .d_name );
@@ -1764,7 +1766,7 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS
1764
1766
intern -> u .file .current_line = estrdup ("" );
1765
1767
intern -> u .file .current_line_len = 0 ;
1766
1768
} else {
1767
- if (intern -> flags & SPL_FILE_OBJECT_DROP_NEW_LINE ) {
1769
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_DROP_NEW_LINE ) ) {
1768
1770
line_len = strcspn (buf , "\r\n" );
1769
1771
buf [line_len ] = '\0' ;
1770
1772
}
@@ -1845,7 +1847,7 @@ static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char deli
1845
1847
1846
1848
do {
1847
1849
ret = spl_filesystem_file_read (intern , 1 TSRMLS_CC );
1848
- } while (ret == SUCCESS && !intern -> u .file .current_line_len && (intern -> flags & SPL_FILE_OBJECT_SKIP_EMPTY ));
1850
+ } while (ret == SUCCESS && !intern -> u .file .current_line_len && SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_SKIP_EMPTY ));
1849
1851
1850
1852
if (ret == SUCCESS ) {
1851
1853
size_t buf_len = intern -> u .file .current_line_len ;
@@ -1874,14 +1876,14 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje
1874
1876
zval * retval = NULL ;
1875
1877
1876
1878
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
1877
- if (intern -> flags & SPL_FILE_OBJECT_READ_CSV || intern -> u .file .func_getCurr -> common .scope != spl_ce_SplFileObject ) {
1879
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_CSV ) || intern -> u .file .func_getCurr -> common .scope != spl_ce_SplFileObject ) {
1878
1880
if (php_stream_eof (intern -> u .file .stream )) {
1879
1881
if (!silent ) {
1880
1882
zend_throw_exception_ex (spl_ce_RuntimeException , 0 TSRMLS_CC , "Cannot read from file %s" , intern -> file_name );
1881
1883
}
1882
1884
return FAILURE ;
1883
1885
}
1884
- if (intern -> flags & SPL_FILE_OBJECT_READ_CSV ) {
1886
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_CSV ) ) {
1885
1887
return spl_filesystem_file_read_csv (intern , intern -> u .file .delimiter , intern -> u .file .enclosure , intern -> u .file .escape , NULL TSRMLS_CC );
1886
1888
} else {
1887
1889
zend_call_method_with_0_params (& this_ptr , Z_OBJCE_P (getThis ()), & intern -> u .file .func_getCurr , "getCurrentLine" , & retval );
@@ -1917,7 +1919,7 @@ static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRML
1917
1919
case IS_STRING :
1918
1920
return Z_STRLEN_P (intern -> u .file .current_zval ) == 0 ;
1919
1921
case IS_ARRAY :
1920
- if ((intern -> flags & SPL_FILE_OBJECT_READ_CSV )
1922
+ if (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_CSV )
1921
1923
&& zend_hash_num_elements (Z_ARRVAL_P (intern -> u .file .current_zval )) == 1 ) {
1922
1924
zval * * first = Z_ARRVAL_P (intern -> u .file .current_zval )-> pListHead -> pData ;
1923
1925
@@ -1939,7 +1941,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object
1939
1941
{
1940
1942
int ret = spl_filesystem_file_read_line_ex (this_ptr , intern , silent TSRMLS_CC );
1941
1943
1942
- while ((intern -> flags & SPL_FILE_OBJECT_SKIP_EMPTY ) && ret == SUCCESS && spl_filesystem_file_is_empty_line (intern TSRMLS_CC )) {
1944
+ while (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_SKIP_EMPTY ) && ret == SUCCESS && spl_filesystem_file_is_empty_line (intern TSRMLS_CC )) {
1943
1945
spl_filesystem_file_free_line (intern TSRMLS_CC );
1944
1946
ret = spl_filesystem_file_read_line_ex (this_ptr , intern , silent TSRMLS_CC );
1945
1947
}
@@ -1956,7 +1958,7 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
1956
1958
spl_filesystem_file_free_line (intern TSRMLS_CC );
1957
1959
intern -> u .file .current_line_num = 0 ;
1958
1960
}
1959
- if (intern -> flags & SPL_FILE_OBJECT_READ_AHEAD ) {
1961
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
1960
1962
spl_filesystem_file_read_line (this_ptr , intern , 1 TSRMLS_CC );
1961
1963
}
1962
1964
} /* }}} */
@@ -2076,7 +2078,7 @@ SPL_METHOD(SplFileObject, valid)
2076
2078
{
2077
2079
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
2078
2080
2079
- if (intern -> flags & SPL_FILE_OBJECT_READ_AHEAD ) {
2081
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2080
2082
RETURN_BOOL (intern -> u .file .current_line || intern -> u .file .current_zval );
2081
2083
} else {
2082
2084
RETVAL_BOOL (!php_stream_eof (intern -> u .file .stream ));
@@ -2104,7 +2106,7 @@ SPL_METHOD(SplFileObject, current)
2104
2106
if (!intern -> u .file .current_line && !intern -> u .file .current_zval ) {
2105
2107
spl_filesystem_file_read_line (getThis (), intern , 1 TSRMLS_CC );
2106
2108
}
2107
- if (intern -> u .file .current_line && (!(intern -> flags & SPL_FILE_OBJECT_READ_CSV ) || !intern -> u .file .current_zval )) {
2109
+ if (intern -> u .file .current_line && (!SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_CSV ) || !intern -> u .file .current_zval )) {
2108
2110
RETURN_STRINGL (intern -> u .file .current_line , intern -> u .file .current_line_len , 1 );
2109
2111
} else if (intern -> u .file .current_zval ) {
2110
2112
RETURN_ZVAL (intern -> u .file .current_zval , 1 , 0 );
@@ -2132,7 +2134,7 @@ SPL_METHOD(SplFileObject, next)
2132
2134
spl_filesystem_object * intern = (spl_filesystem_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
2133
2135
2134
2136
spl_filesystem_file_free_line (intern TSRMLS_CC );
2135
- if (intern -> flags & SPL_FILE_OBJECT_READ_AHEAD ) {
2137
+ if (SPL_HAS_FLAG ( intern -> flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2136
2138
spl_filesystem_file_read_line (getThis (), intern , 1 TSRMLS_CC );
2137
2139
}
2138
2140
intern -> u .file .current_line_num ++ ;
0 commit comments