diff options
| author | Felipe Pena <felipe@php.net> | 2008-08-12 19:38:54 +0000 |
|---|---|---|
| committer | Felipe Pena <felipe@php.net> | 2008-08-12 19:38:54 +0000 |
| commit | 318efa7f107bd033275e39c115b2606f883e2d08 (patch) | |
| tree | ac7075450ba62e870716aace5d7a3e46cc6f856a | |
| parent | cf7384aa4015de9dd21a958146933bbf1f13f0a9 (diff) | |
| download | php-git-318efa7f107bd033275e39c115b2606f883e2d08.tar.gz | |
- New parameter parsing API (for fscanf)
| -rw-r--r-- | ext/standard/file.c | 44 | ||||
| -rw-r--r-- | ext/standard/tests/file/fscanf.phpt | 8 | ||||
| -rw-r--r-- | ext/standard/tests/file/fscanf_error.phpt | 7 |
3 files changed, 25 insertions, 34 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index 6ad1b6c02e..617afb62b3 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1168,30 +1168,18 @@ PHPAPI PHP_FUNCTION(fgetss) Implements a mostly ANSI compatible fscanf() */ PHP_FUNCTION(fscanf) { - int result; - zval **file_handle, **format_string; + int result, format_len, type, argc = 0; + zval ***args = NULL; + zval *file_handle; + char *buf, *format; size_t len; - int type; - char *buf; void *what; - - zval ***args; - int argCount; - - argCount = ZEND_NUM_ARGS(); - if (argCount < 2) { - WRONG_PARAM_COUNT; - } - args = (zval ***)safe_emalloc(argCount, sizeof(zval **), 0); - if (zend_get_parameters_array_ex(argCount, args) == FAILURE) { - efree( args ); - WRONG_PARAM_COUNT; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs*", &file_handle, &format, &format_len, &args, &argc) == FAILURE) { + return; } - file_handle = args[0]; - format_string = args[1]; - - what = zend_fetch_resource(file_handle TSRMLS_CC, -1, "File-Handle", &type, 2, php_file_le_stream(), php_file_le_pstream()); + what = zend_fetch_resource(&file_handle TSRMLS_CC, -1, "File-Handle", &type, 2, php_file_le_stream(), php_file_le_pstream()); /* * we can't do a ZEND_VERIFY_RESOURCE(what), otherwise we end up @@ -1199,26 +1187,30 @@ PHP_FUNCTION(fscanf) * if the code behind ZEND_VERIFY_RESOURCE changed. - cc */ if (!what) { - efree(args); + if (args) { + efree(args); + } RETURN_FALSE; } buf = php_stream_get_line((php_stream *) what, NULL, 0, &len); if (buf == NULL) { - efree(args); + if (args) { + efree(args); + } RETURN_FALSE; } - convert_to_string_ex(format_string); - result = php_sscanf_internal(buf, Z_STRVAL_PP(format_string), argCount, args, 2, &return_value TSRMLS_CC); + result = php_sscanf_internal(buf, format, argc, args, 0, &return_value TSRMLS_CC); - efree(args); + if (args) { + efree(args); + } efree(buf); if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { WRONG_PARAM_COUNT; } - } /* }}} */ diff --git a/ext/standard/tests/file/fscanf.phpt b/ext/standard/tests/file/fscanf.phpt index 9e154b35f9..c37bdeb20a 100644 --- a/ext/standard/tests/file/fscanf.phpt +++ b/ext/standard/tests/file/fscanf.phpt @@ -60,14 +60,14 @@ var_dump(fscanf($fp, "%s%d", $v)); echo "Done\n"; ?> --EXPECTF-- -Warning: Wrong parameter count for fscanf() in %s on line %d +Warning: fscanf() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: Wrong parameter count for fscanf() in %s on line %d +Warning: fscanf() expects at least 2 parameters, 1 given in %s on line %d NULL -Warning: fscanf(): supplied argument is not a valid File-Handle resource in %s on line %d -bool(false) +Warning: fscanf() expects parameter 1 to be resource, array given in %s on line %d +NULL int(0) NULL int(1) diff --git a/ext/standard/tests/file/fscanf_error.phpt b/ext/standard/tests/file/fscanf_error.phpt index c57c8bc86c..f76f5baf61 100644 --- a/ext/standard/tests/file/fscanf_error.phpt +++ b/ext/standard/tests/file/fscanf_error.phpt @@ -64,13 +64,13 @@ unlink($filename); --EXPECTF-- *** Testing fscanf() for error conditions *** -Warning: Wrong parameter count for fscanf() in %s on line %d +Warning: fscanf() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: Wrong parameter count for fscanf() in %s on line %d +Warning: fscanf() expects at least 2 parameters, 1 given in %s on line %d NULL -Warning: fscanf(): %d is not a valid File-Handle resource in %s on line %d +Warning: fscanf(): 6 is not a valid File-Handle resource in %s on line %d bool(false) Warning: fscanf(): Different numbers of variable names and field specifiers in %s on line %d @@ -97,4 +97,3 @@ Warning: fscanf(): Bad scan conversion character "m" in %s on line %d NULL *** Done *** - |
