|
22 | 22 | #include "php_ini.h"
|
23 | 23 | #include "ext/standard/info.h"
|
24 | 24 | #include "ext/standard/file.h"
|
| 25 | +#include "ext/standard/scanf.h" |
25 | 26 | #include "ext/standard/php_string.h"
|
26 | 27 | #include "zend_compile.h"
|
27 | 28 | #include "zend_exceptions.h"
|
@@ -2658,23 +2659,30 @@ PHP_METHOD(SplFileObject, fpassthru)
|
2658 | 2659 | /* {{{ Implements a mostly ANSI compatible fscanf() */
|
2659 | 2660 | PHP_METHOD(SplFileObject, fscanf)
|
2660 | 2661 | {
|
| 2662 | + int result, num_varargs = 0; |
| 2663 | + zend_string *format_str; |
| 2664 | + zval *varargs= NULL; |
2661 | 2665 | spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
|
2662 |
| - zend_function *func_ptr; |
2663 | 2666 |
|
2664 |
| - if(!intern->u.file.stream) { |
2665 |
| - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); |
| 2667 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S*", &format_str, &varargs, &num_varargs) == FAILURE) { |
2666 | 2668 | RETURN_THROWS();
|
2667 | 2669 | }
|
2668 | 2670 |
|
2669 |
| - spl_filesystem_file_free_line(intern); |
2670 |
| - intern->u.file.current_line_num++; |
| 2671 | + if (!intern->u.file.stream) { |
| 2672 | + zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); |
| 2673 | + RETURN_THROWS(); |
| 2674 | + } |
2671 | 2675 |
|
2672 |
| - func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "fscanf", sizeof("fscanf") - 1); |
2673 |
| - if (func_ptr == NULL) { |
2674 |
| - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Internal error, function fscanf() not found. Please report"); |
| 2676 | + /* Get next line */ |
| 2677 | + if (spl_filesystem_file_read(intern, 0) == FAILURE) { |
2675 | 2678 | RETURN_THROWS();
|
2676 |
| - } |
2677 |
| - spl_filesystem_file_call(intern, func_ptr, ZEND_NUM_ARGS(), return_value); |
| 2679 | + } |
| 2680 | + |
| 2681 | + result = php_sscanf_internal(intern->u.file.current_line, ZSTR_VAL(format_str), num_varargs, varargs, 0, return_value); |
| 2682 | + |
| 2683 | + if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { |
| 2684 | + WRONG_PARAM_COUNT; |
| 2685 | + } |
2678 | 2686 | }
|
2679 | 2687 | /* }}} */
|
2680 | 2688 |
|
@@ -2763,7 +2771,7 @@ PHP_METHOD(SplFileObject, fstat)
|
2763 | 2771 | RETURN_THROWS();
|
2764 | 2772 | }
|
2765 | 2773 |
|
2766 |
| - zend_call_known_function(func_ptr, NULL, NULL, return_value, 0, NULL, NULL); |
| 2774 | + zend_call_known_function(func_ptr, NULL, NULL, return_value, 0, NULL, NULL); |
2767 | 2775 | }
|
2768 | 2776 | /* }}} */
|
2769 | 2777 |
|
|
0 commit comments