@@ -209,7 +209,7 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, size_
209
209
return intern -> path ? ZSTR_VAL (intern -> path ) : NULL ;
210
210
} /* }}} */
211
211
212
- static inline int spl_filesystem_object_get_file_name (spl_filesystem_object * intern ) /* {{{ */
212
+ static inline zend_result spl_filesystem_object_get_file_name (spl_filesystem_object * intern ) /* {{{ */
213
213
{
214
214
if (intern -> file_name ) {
215
215
/* already known */
@@ -248,7 +248,8 @@ static inline int spl_filesystem_object_get_file_name(spl_filesystem_object *int
248
248
return SUCCESS ;
249
249
} /* }}} */
250
250
251
- static int spl_filesystem_dir_read (spl_filesystem_object * intern ) /* {{{ */
251
+ /* TODO Make void or have callers check return value */
252
+ static bool spl_filesystem_dir_read (spl_filesystem_object * intern ) /* {{{ */
252
253
{
253
254
if (intern -> file_name ) {
254
255
/* invalidate */
@@ -266,7 +267,7 @@ static int spl_filesystem_dir_read(spl_filesystem_object *intern) /* {{{ */
266
267
267
268
#define IS_SLASH_AT (zs , pos ) (IS_SLASH(zs[pos]))
268
269
269
- static inline int spl_filesystem_is_dot (const char * d_name ) /* {{{ */
270
+ static inline bool spl_filesystem_is_dot (const char * d_name ) /* {{{ */
270
271
{
271
272
return !strcmp (d_name , "." ) || !strcmp (d_name , ".." );
272
273
}
@@ -277,7 +278,7 @@ static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
277
278
* Can emit an E_WARNING as it reports errors from php_stream_opendir() */
278
279
static void spl_filesystem_dir_open (spl_filesystem_object * intern , zend_string * path )
279
280
{
280
- int skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
281
+ bool skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
281
282
282
283
intern -> type = SPL_FS_DIR ;
283
284
intern -> u .dir .dirp = php_stream_opendir (ZSTR_VAL (path ), REPORT_ERRORS , FG (default_context ));
@@ -375,7 +376,6 @@ static zend_object *spl_filesystem_object_clone(zend_object *old_object)
375
376
zend_object * new_object ;
376
377
spl_filesystem_object * intern ;
377
378
spl_filesystem_object * source ;
378
- int index , skip_dots ;
379
379
380
380
source = spl_filesystem_from_obj (old_object );
381
381
new_object = spl_filesystem_object_new_ex (old_object -> ce );
@@ -392,17 +392,19 @@ static zend_object *spl_filesystem_object_clone(zend_object *old_object)
392
392
intern -> file_name = zend_string_copy (source -> file_name );
393
393
}
394
394
break ;
395
- case SPL_FS_DIR :
395
+ case SPL_FS_DIR : {
396
396
spl_filesystem_dir_open (intern , source -> path );
397
397
/* read until we hit the position in which we were before */
398
- skip_dots = SPL_HAS_FLAG (source -> flags , SPL_FILE_DIR_SKIPDOTS );
399
- for (index = 0 ; index < source -> u .dir .index ; ++ index ) {
398
+ bool skip_dots = SPL_HAS_FLAG (source -> flags , SPL_FILE_DIR_SKIPDOTS );
399
+ int index ;
400
+ for (index = 0 ; index < source -> u .dir .index ; ++ index ) {
400
401
do {
401
402
spl_filesystem_dir_read (intern );
402
403
} while (skip_dots && spl_filesystem_is_dot (intern -> u .dir .entry .d_name ));
403
404
}
404
405
intern -> u .dir .index = index ;
405
406
break ;
407
+ }
406
408
case SPL_FS_FILE :
407
409
ZEND_UNREACHABLE ();
408
410
}
@@ -503,7 +505,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
503
505
intern = spl_filesystem_from_obj (spl_filesystem_object_new_ex (ce ));
504
506
RETVAL_OBJ (& intern -> std );
505
507
506
- if (spl_filesystem_object_get_file_name (source ) != SUCCESS ) {
508
+ if (spl_filesystem_object_get_file_name (source ) == FAILURE ) {
507
509
return NULL ;
508
510
}
509
511
@@ -540,7 +542,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
540
542
intern = spl_filesystem_from_obj (spl_filesystem_object_new_ex (ce ));
541
543
RETVAL_OBJ (& intern -> std );
542
544
543
- if (spl_filesystem_object_get_file_name (source ) != SUCCESS ) {
545
+ if (spl_filesystem_object_get_file_name (source ) == FAILURE ) {
544
546
return NULL ;
545
547
}
546
548
@@ -584,7 +586,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
584
586
return NULL ;
585
587
} /* }}} */
586
588
587
- static int spl_filesystem_is_invalid_or_dot (const char * d_name ) /* {{{ */
589
+ static bool spl_filesystem_is_invalid_or_dot (const char * d_name ) /* {{{ */
588
590
{
589
591
return d_name [0 ] == '\0' || spl_filesystem_is_dot (d_name );
590
592
}
@@ -709,7 +711,7 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
709
711
{
710
712
spl_filesystem_object * intern ;
711
713
zend_string * path ;
712
- int parsed ;
714
+ zend_result parsed ;
713
715
zend_long flags = (ctor_flags & ~DIT_CTOR_FLAGS );
714
716
zend_error_handling error_handling ;
715
717
@@ -809,7 +811,7 @@ PHP_METHOD(DirectoryIterator, current)
809
811
PHP_METHOD (DirectoryIterator , next )
810
812
{
811
813
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
812
- int skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
814
+ bool skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
813
815
814
816
if (zend_parse_parameters_none () == FAILURE ) {
815
817
RETURN_THROWS ();
@@ -845,7 +847,7 @@ PHP_METHOD(DirectoryIterator, seek)
845
847
}
846
848
847
849
while (intern -> u .dir .index < pos ) {
848
- int valid = 0 ;
850
+ bool valid = 0 ;
849
851
zend_call_method_with_0_params (Z_OBJ_P (ZEND_THIS ), Z_OBJCE_P (ZEND_THIS ), & intern -> u .dir .func_valid , "valid" , & retval );
850
852
valid = zend_is_true (& retval );
851
853
zval_ptr_dtor (& retval );
@@ -1048,7 +1050,7 @@ PHP_METHOD(DirectoryIterator, getBasename)
1048
1050
CHECK_DIRECTORY_ITERATOR_IS_INITIALIZED (intern );
1049
1051
fname = php_basename (intern -> u .dir .entry .d_name , strlen (intern -> u .dir .entry .d_name ), suffix , slen );
1050
1052
1051
- RETVAL_STR (fname );
1053
+ RETURN_STR (fname );
1052
1054
}
1053
1055
/* }}} */
1054
1056
@@ -1082,7 +1084,7 @@ PHP_METHOD(FilesystemIterator, key)
1082
1084
if (SPL_FILE_DIR_KEY (intern , SPL_FILE_DIR_KEY_AS_FILENAME )) {
1083
1085
RETURN_STRING (intern -> u .dir .entry .d_name );
1084
1086
} else {
1085
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1087
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1086
1088
RETURN_THROWS ();
1087
1089
}
1088
1090
RETURN_STR_COPY (intern -> file_name );
@@ -1100,12 +1102,12 @@ PHP_METHOD(FilesystemIterator, current)
1100
1102
}
1101
1103
1102
1104
if (SPL_FILE_DIR_CURRENT (intern , SPL_FILE_DIR_CURRENT_AS_PATHNAME )) {
1103
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1105
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1104
1106
RETURN_THROWS ();
1105
1107
}
1106
1108
RETURN_STR_COPY (intern -> file_name );
1107
1109
} else if (SPL_FILE_DIR_CURRENT (intern , SPL_FILE_DIR_CURRENT_AS_FILEINFO )) {
1108
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1110
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1109
1111
RETURN_THROWS ();
1110
1112
}
1111
1113
spl_filesystem_object_create_type (0 , intern , SPL_FS_INFO , NULL , return_value );
@@ -1129,7 +1131,7 @@ PHP_METHOD(DirectoryIterator, isDot)
1129
1131
}
1130
1132
/* }}} */
1131
1133
1132
- /* {{{ Cronstructs a new SplFileInfo from a path. */
1134
+ /* {{{ Constructs a new SplFileInfo from a path. */
1133
1135
/* When the constructor gets called the object is already created
1134
1136
by the engine, so we must only call 'additional' initializations.
1135
1137
*/
@@ -1159,7 +1161,7 @@ PHP_METHOD(SplFileInfo, func_name) \
1159
1161
if (zend_parse_parameters_none() == FAILURE) { \
1160
1162
RETURN_THROWS(); \
1161
1163
} \
1162
- if (spl_filesystem_object_get_file_name(intern) != SUCCESS ) { \
1164
+ if (spl_filesystem_object_get_file_name(intern) == FAILURE ) { \
1163
1165
RETURN_THROWS(); \
1164
1166
} \
1165
1167
zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);\
@@ -1240,7 +1242,7 @@ PHP_METHOD(SplFileInfo, getLinkTarget)
1240
1242
}
1241
1243
1242
1244
if (intern -> file_name == NULL ) {
1243
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1245
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1244
1246
RETURN_THROWS ();
1245
1247
}
1246
1248
}
@@ -1287,7 +1289,7 @@ PHP_METHOD(SplFileInfo, getRealPath)
1287
1289
}
1288
1290
1289
1291
if (intern -> type == SPL_FS_DIR && !intern -> file_name && intern -> u .dir .entry .d_name [0 ]) {
1290
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1292
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1291
1293
RETURN_THROWS ();
1292
1294
}
1293
1295
}
@@ -1302,12 +1304,12 @@ PHP_METHOD(SplFileInfo, getRealPath)
1302
1304
if (filename && VCWD_REALPATH (filename , buff )) {
1303
1305
#ifdef ZTS
1304
1306
if (VCWD_ACCESS (buff , F_OK )) {
1305
- RETVAL_FALSE ;
1307
+ RETURN_FALSE ;
1306
1308
} else
1307
1309
#endif
1308
- RETVAL_STRING (buff );
1310
+ RETURN_STRING (buff );
1309
1311
} else {
1310
- RETVAL_FALSE ;
1312
+ RETURN_FALSE ;
1311
1313
}
1312
1314
}
1313
1315
/* }}} */
@@ -1388,7 +1390,7 @@ PHP_METHOD(SplFileInfo, getPathInfo)
1388
1390
PHP_METHOD (SplFileInfo , __debugInfo )
1389
1391
{
1390
1392
if (zend_parse_parameters_none () == FAILURE ) {
1391
- return ;
1393
+ RETURN_THROWS () ;
1392
1394
}
1393
1395
1394
1396
RETURN_ARR (spl_filesystem_object_get_debug_info (Z_OBJ_P (ZEND_THIS )));
@@ -1401,7 +1403,7 @@ PHP_METHOD(SplFileInfo, _bad_state_ex)
1401
1403
}
1402
1404
/* }}} */
1403
1405
1404
- /* {{{ Cronstructs a new dir iterator from a path. */
1406
+ /* {{{ Constructs a new dir iterator from a path. */
1405
1407
PHP_METHOD (FilesystemIterator , __construct )
1406
1408
{
1407
1409
spl_filesystem_object_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , DIT_CTOR_FLAGS | SPL_FILE_DIR_SKIPDOTS );
@@ -1412,7 +1414,7 @@ PHP_METHOD(FilesystemIterator, __construct)
1412
1414
PHP_METHOD (FilesystemIterator , rewind )
1413
1415
{
1414
1416
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
1415
- int skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
1417
+ bool skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
1416
1418
1417
1419
if (zend_parse_parameters_none () == FAILURE ) {
1418
1420
RETURN_THROWS ();
@@ -1468,7 +1470,7 @@ PHP_METHOD(RecursiveDirectoryIterator, hasChildren)
1468
1470
if (spl_filesystem_is_invalid_or_dot (intern -> u .dir .entry .d_name )) {
1469
1471
RETURN_FALSE ;
1470
1472
} else {
1471
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1473
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1472
1474
RETURN_THROWS ();
1473
1475
}
1474
1476
php_stat (intern -> file_name , FS_LPERMS , return_value );
@@ -1499,7 +1501,7 @@ PHP_METHOD(RecursiveDirectoryIterator, getChildren)
1499
1501
RETURN_THROWS ();
1500
1502
}
1501
1503
1502
- if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1504
+ if (spl_filesystem_object_get_file_name (intern ) == FAILURE ) {
1503
1505
RETURN_THROWS ();
1504
1506
}
1505
1507
@@ -1720,15 +1722,15 @@ static zval *spl_filesystem_tree_it_current_data(zend_object_iterator *iter)
1720
1722
1721
1723
if (SPL_FILE_DIR_CURRENT (object , SPL_FILE_DIR_CURRENT_AS_PATHNAME )) {
1722
1724
if (Z_ISUNDEF (iterator -> current )) {
1723
- if (spl_filesystem_object_get_file_name (object ) != SUCCESS ) {
1725
+ if (spl_filesystem_object_get_file_name (object ) == FAILURE ) {
1724
1726
return NULL ;
1725
1727
}
1726
1728
ZVAL_STR_COPY (& iterator -> current , object -> file_name );
1727
1729
}
1728
1730
return & iterator -> current ;
1729
1731
} else if (SPL_FILE_DIR_CURRENT (object , SPL_FILE_DIR_CURRENT_AS_FILEINFO )) {
1730
1732
if (Z_ISUNDEF (iterator -> current )) {
1731
- if (spl_filesystem_object_get_file_name (object ) != SUCCESS ) {
1733
+ if (spl_filesystem_object_get_file_name (object ) == FAILURE ) {
1732
1734
return NULL ;
1733
1735
}
1734
1736
spl_filesystem_object_create_type (0 , object , SPL_FS_INFO , NULL , & iterator -> current );
@@ -1748,7 +1750,7 @@ static void spl_filesystem_tree_it_current_key(zend_object_iterator *iter, zval
1748
1750
if (SPL_FILE_DIR_KEY (object , SPL_FILE_DIR_KEY_AS_FILENAME )) {
1749
1751
ZVAL_STRING (key , object -> u .dir .entry .d_name );
1750
1752
} else {
1751
- if (spl_filesystem_object_get_file_name (object ) != SUCCESS ) {
1753
+ if (spl_filesystem_object_get_file_name (object ) == FAILURE ) {
1752
1754
return ;
1753
1755
}
1754
1756
ZVAL_STR_COPY (key , object -> file_name );
@@ -1860,7 +1862,7 @@ static int spl_filesystem_object_cast(zend_object *readobj, zval *writeobj, int
1860
1862
}
1861
1863
/* }}} */
1862
1864
1863
- static int spl_filesystem_file_read (spl_filesystem_object * intern , int silent ) /* {{{ */
1865
+ static zend_result spl_filesystem_file_read (spl_filesystem_object * intern , bool silent ) /* {{{ */
1864
1866
{
1865
1867
char * buf ;
1866
1868
size_t line_len = 0 ;
@@ -1909,10 +1911,10 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent) /
1909
1911
return SUCCESS ;
1910
1912
} /* }}} */
1911
1913
1912
- static int spl_filesystem_file_read_csv (spl_filesystem_object * intern , char delimiter , char enclosure , int escape , zval * return_value ) /* {{{ */
1914
+ static zend_result spl_filesystem_file_read_csv (spl_filesystem_object * intern , char delimiter , char enclosure , int escape , zval * return_value ) /* {{{ */
1913
1915
{
1914
1916
do {
1915
- int ret = spl_filesystem_file_read (intern , 1 );
1917
+ zend_result ret = spl_filesystem_file_read (intern , 1 );
1916
1918
if (ret != SUCCESS ) {
1917
1919
return ret ;
1918
1920
}
@@ -1934,7 +1936,7 @@ static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char deli
1934
1936
}
1935
1937
/* }}} */
1936
1938
1937
- static int spl_filesystem_file_read_line_ex (zval * this_ptr , spl_filesystem_object * intern , int silent ) /* {{{ */
1939
+ static zend_result spl_filesystem_file_read_line_ex (zval * this_ptr , spl_filesystem_object * intern , int silent ) /* {{{ */
1938
1940
{
1939
1941
zval retval ;
1940
1942
@@ -1977,7 +1979,7 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje
1977
1979
}
1978
1980
} /* }}} */
1979
1981
1980
- static int spl_filesystem_file_is_empty_line (spl_filesystem_object * intern ) /* {{{ */
1982
+ static bool spl_filesystem_file_is_empty_line (spl_filesystem_object * intern ) /* {{{ */
1981
1983
{
1982
1984
if (intern -> u .file .current_line ) {
1983
1985
return intern -> u .file .current_line_len == 0 ;
@@ -2016,9 +2018,9 @@ static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern) /* {
2016
2018
}
2017
2019
/* }}} */
2018
2020
2019
- static int spl_filesystem_file_read_line (zval * this_ptr , spl_filesystem_object * intern , int silent ) /* {{{ */
2021
+ static zend_result spl_filesystem_file_read_line (zval * this_ptr , spl_filesystem_object * intern , int silent ) /* {{{ */
2020
2022
{
2021
- int ret = spl_filesystem_file_read_line_ex (this_ptr , intern , silent );
2023
+ zend_result ret = spl_filesystem_file_read_line_ex (this_ptr , intern , silent );
2022
2024
2023
2025
while (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_SKIP_EMPTY ) && ret == SUCCESS && spl_filesystem_file_is_empty_line (intern )) {
2024
2026
spl_filesystem_file_free_line (intern );
@@ -2160,12 +2162,11 @@ PHP_METHOD(SplFileObject, valid)
2160
2162
2161
2163
if (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_AHEAD )) {
2162
2164
RETURN_BOOL (intern -> u .file .current_line || !Z_ISUNDEF (intern -> u .file .current_zval ));
2163
- } else {
2164
- if (!intern -> u .file .stream ) {
2165
- RETURN_FALSE ;
2166
- }
2167
- RETVAL_BOOL (!php_stream_eof (intern -> u .file .stream ));
2168
2165
}
2166
+ if (!intern -> u .file .stream ) {
2167
+ RETURN_FALSE ;
2168
+ }
2169
+ RETURN_BOOL (!php_stream_eof (intern -> u .file .stream ));
2169
2170
} /* }}} */
2170
2171
2171
2172
/* {{{ Return next line from file */
@@ -2568,16 +2569,15 @@ PHP_METHOD(SplFileObject, fgetc)
2568
2569
result = php_stream_getc (intern -> u .file .stream );
2569
2570
2570
2571
if (result == EOF ) {
2571
- RETVAL_FALSE ;
2572
- } else {
2573
- if (result == '\n' ) {
2574
- intern -> u .file .current_line_num ++ ;
2575
- }
2576
- buf [0 ] = result ;
2577
- buf [1 ] = '\0' ;
2578
-
2579
- RETURN_STRINGL (buf , 1 );
2572
+ RETURN_FALSE ;
2573
+ }
2574
+ if (result == '\n' ) {
2575
+ intern -> u .file .current_line_num ++ ;
2580
2576
}
2577
+ buf [0 ] = result ;
2578
+ buf [1 ] = '\0' ;
2579
+
2580
+ RETURN_STRINGL (buf , 1 );
2581
2581
} /* }}} */
2582
2582
2583
2583
/* {{{ Output all remaining data from a file pointer */
@@ -2734,11 +2734,9 @@ PHP_METHOD(SplFileObject, seek)
2734
2734
return ;
2735
2735
}
2736
2736
}
2737
- if (line_pos > 0 ) {
2738
- if (!SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_AHEAD )) {
2737
+ if (line_pos > 0 && !SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_AHEAD )) {
2739
2738
intern -> u .file .current_line_num ++ ;
2740
- spl_filesystem_file_free_line (intern );
2741
- }
2739
+ spl_filesystem_file_free_line (intern );
2742
2740
}
2743
2741
} /* }}} */
2744
2742
0 commit comments