@@ -402,7 +402,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
402
402
return FAILURE ;
403
403
}
404
404
php_stream_seek (dba -> fp , pos_start , SEEK_SET );
405
- if (! php_stream_copy_to_stream_ex (dba -> fp , fp , pos_end - pos_start , NULL )) {
405
+ if (SUCCESS != php_stream_copy_to_stream_ex (dba -> fp , fp , pos_end - pos_start , NULL )) {
406
406
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Could not copy group [%zu - %zu] to temporary stream" , pos_start , pos_end );
407
407
return FAILURE ;
408
408
}
@@ -413,7 +413,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
413
413
/* {{{ inifile_filter
414
414
* copy from to dba while ignoring key name (group must equal)
415
415
*/
416
- static int inifile_filter (inifile * dba , inifile * from , const key_type * key TSRMLS_DC )
416
+ static int inifile_filter (inifile * dba , inifile * from , const key_type * key , zend_bool * found TSRMLS_DC )
417
417
{
418
418
size_t pos_start = 0 , pos_next = 0 , pos_curr ;
419
419
int ret = SUCCESS ;
@@ -424,10 +424,13 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
424
424
while (inifile_read (from , & ln TSRMLS_CC )) {
425
425
switch (inifile_key_cmp (& ln .key , key TSRMLS_CC )) {
426
426
case 0 :
427
+ if (found ) {
428
+ * found = (zend_bool ) 1 ;
429
+ }
427
430
pos_curr = php_stream_tell (from -> fp );
428
431
if (pos_start != pos_next ) {
429
432
php_stream_seek (from -> fp , pos_start , SEEK_SET );
430
- if (! php_stream_copy_to_stream_ex (from -> fp , dba -> fp , pos_next - pos_start , NULL )) {
433
+ if (SUCCESS != php_stream_copy_to_stream_ex (from -> fp , dba -> fp , pos_next - pos_start , NULL )) {
431
434
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Could not copy [%zu - %zu] from temporary stream" , pos_next , pos_start );
432
435
ret = FAILURE ;
433
436
}
@@ -446,7 +449,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
446
449
}
447
450
if (pos_start != pos_next ) {
448
451
php_stream_seek (from -> fp , pos_start , SEEK_SET );
449
- if (! php_stream_copy_to_stream_ex (from -> fp , dba -> fp , pos_next - pos_start , NULL )) {
452
+ if (SUCCESS != php_stream_copy_to_stream_ex (from -> fp , dba -> fp , pos_next - pos_start , NULL )) {
450
453
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Could not copy [%zu - %zu] from temporary stream" , pos_next , pos_start );
451
454
ret = FAILURE ;
452
455
}
@@ -458,7 +461,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
458
461
459
462
/* {{{ inifile_delete_replace_append
460
463
*/
461
- static int inifile_delete_replace_append (inifile * dba , const key_type * key , const val_type * value , int append TSRMLS_DC )
464
+ static int inifile_delete_replace_append (inifile * dba , const key_type * key , const val_type * value , int append , zend_bool * found TSRMLS_DC )
462
465
{
463
466
size_t pos_grp_start = 0 , pos_grp_next ;
464
467
inifile * ini_tmp = NULL ;
@@ -497,7 +500,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
497
500
php_stream_seek (dba -> fp , 0 , SEEK_END );
498
501
if (pos_grp_next != (size_t )php_stream_tell (dba -> fp )) {
499
502
php_stream_seek (dba -> fp , pos_grp_next , SEEK_SET );
500
- if (! php_stream_copy_to_stream_ex (dba -> fp , fp_tmp , PHP_STREAM_COPY_ALL , NULL )) {
503
+ if (SUCCESS != php_stream_copy_to_stream_ex (dba -> fp , fp_tmp , PHP_STREAM_COPY_ALL , NULL )) {
501
504
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Could not copy remainder to temporary stream" );
502
505
ret = FAILURE ;
503
506
}
@@ -516,7 +519,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
516
519
if (key -> name && strlen (key -> name )) {
517
520
/* 6 */
518
521
if (!append && ini_tmp ) {
519
- ret = inifile_filter (dba , ini_tmp , key TSRMLS_CC );
522
+ ret = inifile_filter (dba , ini_tmp , key , found TSRMLS_CC );
520
523
}
521
524
522
525
/* 7 */
@@ -538,7 +541,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
538
541
if (fp_tmp && php_stream_tell (fp_tmp )) {
539
542
php_stream_seek (fp_tmp , 0 , SEEK_SET );
540
543
php_stream_seek (dba -> fp , 0 , SEEK_END );
541
- if (! php_stream_copy_to_stream_ex (fp_tmp , dba -> fp , PHP_STREAM_COPY_ALL , NULL )) {
544
+ if (SUCCESS != php_stream_copy_to_stream_ex (fp_tmp , dba -> fp , PHP_STREAM_COPY_ALL , NULL )) {
542
545
php_error_docref (NULL TSRMLS_CC , E_RECOVERABLE_ERROR , "Could not copy from temporary stream - ini file truncated" );
543
546
ret = FAILURE ;
544
547
}
@@ -563,23 +566,39 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
563
566
*/
564
567
int inifile_delete (inifile * dba , const key_type * key TSRMLS_DC )
565
568
{
566
- return inifile_delete_replace_append (dba , key , NULL , 0 TSRMLS_CC );
569
+ return inifile_delete_replace_append (dba , key , NULL , 0 , NULL TSRMLS_CC );
570
+ }
571
+ /* }}} */
572
+
573
+ /* {{{ inifile_delete_ex
574
+ */
575
+ int inifile_delete_ex (inifile * dba , const key_type * key , zend_bool * found TSRMLS_DC )
576
+ {
577
+ return inifile_delete_replace_append (dba , key , NULL , 0 , found TSRMLS_CC );
567
578
}
568
579
/* }}} */
569
580
570
581
/* {{{ inifile_relace
571
582
*/
572
583
int inifile_replace (inifile * dba , const key_type * key , const val_type * value TSRMLS_DC )
573
584
{
574
- return inifile_delete_replace_append (dba , key , value , 0 TSRMLS_CC );
585
+ return inifile_delete_replace_append (dba , key , value , 0 , NULL TSRMLS_CC );
586
+ }
587
+ /* }}} */
588
+
589
+ /* {{{ inifile_replace_ex
590
+ */
591
+ int inifile_replace_ex (inifile * dba , const key_type * key , const val_type * value , zend_bool * found TSRMLS_DC )
592
+ {
593
+ return inifile_delete_replace_append (dba , key , value , 0 , found TSRMLS_CC );
575
594
}
576
595
/* }}} */
577
596
578
597
/* {{{ inifile_append
579
598
*/
580
599
int inifile_append (inifile * dba , const key_type * key , const val_type * value TSRMLS_DC )
581
600
{
582
- return inifile_delete_replace_append (dba , key , value , 1 TSRMLS_CC );
601
+ return inifile_delete_replace_append (dba , key , value , 1 , NULL TSRMLS_CC );
583
602
}
584
603
/* }}} */
585
604
0 commit comments