summaryrefslogtreecommitdiff
path: root/ext/standard/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r--ext/standard/file.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 536cdfb269..75197463a1 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -647,10 +647,8 @@ PHP_FUNCTION(file_put_contents)
if (zend_hash_num_elements(Z_ARRVAL_P(data))) {
int bytes_written;
zval *tmp;
- HashPosition pos;
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(data), &pos);
- while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(data), &pos)) != NULL) {
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), tmp) {
if (Z_TYPE_P(tmp) != IS_STRING) {
SEPARATE_ZVAL(tmp);
convert_to_string(tmp);
@@ -668,8 +666,7 @@ PHP_FUNCTION(file_put_contents)
break;
}
}
- zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos);
- }
+ } ZEND_HASH_FOREACH_END();
}
break;
@@ -1084,10 +1081,11 @@ PHPAPI PHP_FUNCTION(fgetss)
size_t actual_len, retval_len;
char *buf = NULL, *retval;
php_stream *stream;
+ zend_string *allowed = NULL;
char *allowed_tags=NULL;
int allowed_tags_len=0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ls", &fd, &bytes, &allowed_tags, &allowed_tags_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lS", &fd, &bytes, &allowed) == FAILURE) {
RETURN_FALSE;
}
@@ -1112,8 +1110,24 @@ PHPAPI PHP_FUNCTION(fgetss)
RETURN_FALSE;
}
+ if (allowed != NULL) {
+// TODO: reimplement to avoid reallocation ???
+ if (IS_INTERNED(allowed)) {
+ allowed_tags = estrndup(allowed->val, allowed->len);
+ allowed_tags_len = allowed->len;
+ } else {
+ allowed_tags = allowed->val;
+ allowed_tags_len = allowed->len;
+ }
+ }
+
retval_len = php_strip_tags(retval, actual_len, &stream->fgetss_state, allowed_tags, allowed_tags_len);
+// TODO: reimplement to avoid reallocation ???
+ if (allowed && IS_INTERNED(allowed)) {
+ efree(allowed_tags);
+ }
+
// TODO: avoid reallocation ???
RETVAL_STRINGL(retval, retval_len);
efree(retval);
@@ -1865,11 +1879,9 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
int count, i = 0, ret;
zval *field_tmp = NULL, field;
smart_str csvline = {0};
- HashPosition pos;
count = zend_hash_num_elements(Z_ARRVAL_P(fields));
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(fields), &pos);
- while ((field_tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), &pos)) != NULL) {
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(fields), field_tmp) {
ZVAL_COPY_VALUE(&field, field_tmp);
if (Z_TYPE(field) != IS_STRING) {
@@ -1910,12 +1922,10 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
if (++i != count) {
smart_str_appendl(&csvline, &delimiter, 1);
}
- zend_hash_move_forward_ex(Z_ARRVAL_P(fields), &pos);
-
if (Z_TYPE_P(field_tmp) != IS_STRING) {
zval_dtor(&field);
}
- }
+ } ZEND_HASH_FOREACH_END();
smart_str_appendc(&csvline, '\n');
smart_str_0(&csvline);