diff options
author | Bob Weinand <bobwei9@hotmail.com> | 2014-02-06 09:38:50 +0100 |
---|---|---|
committer | Bob Weinand <bobwei9@hotmail.com> | 2014-02-06 09:38:50 +0100 |
commit | 45d2df5f119d17804ccf6068cbe1132e118579b2 (patch) | |
tree | e3014245763e4290de480fad0b1142728314b965 /ext/dba/libinifile/inifile.c | |
parent | b33060af82c648bb3971de9d8fe67e52781cbd7a (diff) | |
parent | e5ded6e843fc43dde4b6c65405a1d3e2ae026eb4 (diff) | |
download | php-git-45d2df5f119d17804ccf6068cbe1132e118579b2.tar.gz |
Merge branch 'datibbaw/pow-operator' into PHP-5.6broken-5.6-20140206
Diffstat (limited to 'ext/dba/libinifile/inifile.c')
-rw-r--r-- | ext/dba/libinifile/inifile.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c index 8c771beba4..218037ebe3 100644 --- a/ext/dba/libinifile/inifile.c +++ b/ext/dba/libinifile/inifile.c @@ -402,7 +402,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi return FAILURE; } php_stream_seek(dba->fp, pos_start, SEEK_SET); - if (!php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy group [%zu - %zu] to temporary stream", pos_start, pos_end); return FAILURE; } @@ -413,7 +413,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi /* {{{ inifile_filter * copy from to dba while ignoring key name (group must equal) */ -static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRMLS_DC) +static int inifile_filter(inifile *dba, inifile *from, const key_type *key, zend_bool *found TSRMLS_DC) { size_t pos_start = 0, pos_next = 0, pos_curr; int ret = SUCCESS; @@ -424,10 +424,13 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML while(inifile_read(from, &ln TSRMLS_CC)) { switch(inifile_key_cmp(&ln.key, key TSRMLS_CC)) { case 0: + if (found) { + *found = (zend_bool) 1; + } pos_curr = php_stream_tell(from->fp); if (pos_start != pos_next) { php_stream_seek(from->fp, pos_start, SEEK_SET); - if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); ret = FAILURE; } @@ -446,7 +449,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML } if (pos_start != pos_next) { php_stream_seek(from->fp, pos_start, SEEK_SET); - if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); ret = FAILURE; } @@ -458,7 +461,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML /* {{{ inifile_delete_replace_append */ -static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append TSRMLS_DC) +static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append, zend_bool *found TSRMLS_DC) { size_t pos_grp_start=0, pos_grp_next; inifile *ini_tmp = NULL; @@ -497,7 +500,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons php_stream_seek(dba->fp, 0, SEEK_END); if (pos_grp_next != (size_t)php_stream_tell(dba->fp)) { php_stream_seek(dba->fp, pos_grp_next, SEEK_SET); - if (!php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy remainder to temporary stream"); ret = FAILURE; } @@ -516,7 +519,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons if (key->name && strlen(key->name)) { /* 6 */ if (!append && ini_tmp) { - ret = inifile_filter(dba, ini_tmp, key TSRMLS_CC); + ret = inifile_filter(dba, ini_tmp, key, found TSRMLS_CC); } /* 7 */ @@ -538,7 +541,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons if (fp_tmp && php_stream_tell(fp_tmp)) { php_stream_seek(fp_tmp, 0, SEEK_SET); php_stream_seek(dba->fp, 0, SEEK_END); - if (!php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) { php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Could not copy from temporary stream - ini file truncated"); ret = FAILURE; } @@ -563,7 +566,15 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons */ int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC) { - return inifile_delete_replace_append(dba, key, NULL, 0 TSRMLS_CC); + return inifile_delete_replace_append(dba, key, NULL, 0, NULL TSRMLS_CC); +} +/* }}} */ + +/* {{{ inifile_delete_ex + */ +int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found TSRMLS_DC) +{ + return inifile_delete_replace_append(dba, key, NULL, 0, found TSRMLS_CC); } /* }}} */ @@ -571,7 +582,15 @@ int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC) */ int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC) { - return inifile_delete_replace_append(dba, key, value, 0 TSRMLS_CC); + return inifile_delete_replace_append(dba, key, value, 0, NULL TSRMLS_CC); +} +/* }}} */ + +/* {{{ inifile_replace_ex + */ +int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *value, zend_bool *found TSRMLS_DC) +{ + return inifile_delete_replace_append(dba, key, value, 0, found TSRMLS_CC); } /* }}} */ @@ -579,7 +598,7 @@ int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSR */ int inifile_append(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC) { - return inifile_delete_replace_append(dba, key, value, 1 TSRMLS_CC); + return inifile_delete_replace_append(dba, key, value, 1, NULL TSRMLS_CC); } /* }}} */ |