@@ -382,7 +382,6 @@ PHP_FUNCTION(file_get_contents)
382382 zend_long offset = 0 ;
383383 zend_long maxlen ;
384384 bool maxlen_is_null = 1 ;
385- zval * zcontext = NULL ;
386385 php_stream_context * context = NULL ;
387386 zend_string * contents ;
388387
@@ -391,7 +390,7 @@ PHP_FUNCTION(file_get_contents)
391390 Z_PARAM_PATH (filename , filename_len )
392391 Z_PARAM_OPTIONAL
393392 Z_PARAM_BOOL (use_include_path )
394- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
393+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
395394 Z_PARAM_LONG (offset )
396395 Z_PARAM_LONG_OR_NULL (maxlen , maxlen_is_null )
397396 ZEND_PARSE_PARAMETERS_END ();
@@ -403,8 +402,6 @@ PHP_FUNCTION(file_get_contents)
403402 RETURN_THROWS ();
404403 }
405404
406- context = php_stream_context_from_zval (zcontext , 0 );
407-
408405 stream = php_stream_open_wrapper_ex (filename , "rb" ,
409406 (use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS ,
410407 NULL , context );
@@ -443,7 +440,6 @@ PHP_FUNCTION(file_put_contents)
443440 zval * data ;
444441 ssize_t numbytes = 0 ;
445442 zend_long flags = 0 ;
446- zval * zcontext = NULL ;
447443 php_stream_context * context = NULL ;
448444 php_stream * srcstream = NULL ;
449445 char mode [3 ] = "wb" ;
@@ -453,14 +449,16 @@ PHP_FUNCTION(file_put_contents)
453449 Z_PARAM_ZVAL (data )
454450 Z_PARAM_OPTIONAL
455451 Z_PARAM_LONG (flags )
456- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
452+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL ( context )
457453 ZEND_PARSE_PARAMETERS_END ();
458454
459455 if (Z_TYPE_P (data ) == IS_RESOURCE ) {
460456 php_stream_from_zval (srcstream , data );
461457 }
462458
463- context = php_stream_context_from_zval (zcontext , flags & PHP_FILE_NO_DEFAULT_CONTEXT );
459+ if (context == NULL ) {
460+ context = php_stream_context_get_default (flags & PHP_FILE_NO_DEFAULT_CONTEXT );
461+ }
464462
465463 if (flags & PHP_FILE_APPEND ) {
466464 mode [0 ] = 'a' ;
@@ -589,7 +587,6 @@ PHP_FUNCTION(file)
589587 bool include_new_line ;
590588 bool skip_blank_lines ;
591589 php_stream * stream ;
592- zval * zcontext = NULL ;
593590 php_stream_context * context = NULL ;
594591 zend_string * target_buf ;
595592
@@ -598,7 +595,7 @@ PHP_FUNCTION(file)
598595 Z_PARAM_PATH (filename , filename_len )
599596 Z_PARAM_OPTIONAL
600597 Z_PARAM_LONG (flags )
601- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
598+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL ( context )
602599 ZEND_PARSE_PARAMETERS_END ();
603600
604601 if ((flags & ~(PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT )) != 0 ) {
@@ -610,7 +607,9 @@ PHP_FUNCTION(file)
610607 include_new_line = !(flags & PHP_FILE_IGNORE_NEW_LINES );
611608 skip_blank_lines = flags & PHP_FILE_SKIP_EMPTY_LINES ;
612609
613- context = php_stream_context_from_zval (zcontext , flags & PHP_FILE_NO_DEFAULT_CONTEXT );
610+ if (context == NULL ) {
611+ context = php_stream_context_get_default (flags & PHP_FILE_NO_DEFAULT_CONTEXT );
612+ }
614613
615614 stream = php_stream_open_wrapper_ex (filename , "rb" , (use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS , NULL , context );
616615 if (!stream ) {
@@ -723,7 +722,6 @@ PHP_FUNCTION(fopen)
723722 char * filename , * mode ;
724723 size_t filename_len , mode_len ;
725724 bool use_include_path = 0 ;
726- zval * zcontext = NULL ;
727725 php_stream * stream ;
728726 php_stream_context * context = NULL ;
729727
@@ -732,11 +730,9 @@ PHP_FUNCTION(fopen)
732730 Z_PARAM_STRING (mode , mode_len )
733731 Z_PARAM_OPTIONAL
734732 Z_PARAM_BOOL (use_include_path )
735- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
733+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
736734 ZEND_PARSE_PARAMETERS_END ();
737735
738- context = php_stream_context_from_zval (zcontext , 0 );
739-
740736 stream = php_stream_open_wrapper_ex (filename , mode , (use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS , NULL , context );
741737
742738 if (stream == NULL) {
@@ -1078,21 +1074,18 @@ PHP_FUNCTION(mkdir)
10781074{
10791075 char * dir ;
10801076 size_t dir_len ;
1081- zval * zcontext = NULL ;
10821077 zend_long mode = 0777 ;
10831078 bool recursive = 0 ;
1084- php_stream_context * context ;
1079+ php_stream_context * context = NULL ;
10851080
10861081 ZEND_PARSE_PARAMETERS_START (1 , 4 )
10871082 Z_PARAM_PATH (dir , dir_len )
10881083 Z_PARAM_OPTIONAL
10891084 Z_PARAM_LONG (mode )
10901085 Z_PARAM_BOOL (recursive )
1091- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
1086+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
10921087 ZEND_PARSE_PARAMETERS_END ();
10931088
1094- context = php_stream_context_from_zval (zcontext , 0 );
1095-
10961089 RETURN_BOOL (php_stream_mkdir (dir , (int )mode , (recursive ? PHP_STREAM_MKDIR_RECURSIVE : 0 ) | REPORT_ERRORS , context ));
10971090}
10981091/* }}} */
@@ -1102,17 +1095,14 @@ PHP_FUNCTION(rmdir)
11021095{
11031096 char * dir ;
11041097 size_t dir_len ;
1105- zval * zcontext = NULL ;
1106- php_stream_context * context ;
1098+ php_stream_context * context = NULL ;
11071099
11081100 ZEND_PARSE_PARAMETERS_START (1 , 2 )
11091101 Z_PARAM_PATH (dir , dir_len )
11101102 Z_PARAM_OPTIONAL
1111- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
1103+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
11121104 ZEND_PARSE_PARAMETERS_END ();
11131105
1114- context = php_stream_context_from_zval (zcontext , 0 );
1115-
11161106 RETURN_BOOL (php_stream_rmdir (dir , REPORT_ERRORS , context ));
11171107}
11181108/* }}} */
@@ -1124,19 +1114,16 @@ PHP_FUNCTION(readfile)
11241114 size_t filename_len ;
11251115 size_t size = 0 ;
11261116 bool use_include_path = 0 ;
1127- zval * zcontext = NULL ;
11281117 php_stream * stream ;
11291118 php_stream_context * context = NULL ;
11301119
11311120 ZEND_PARSE_PARAMETERS_START (1 , 3 )
11321121 Z_PARAM_PATH (filename , filename_len )
11331122 Z_PARAM_OPTIONAL
11341123 Z_PARAM_BOOL (use_include_path )
1135- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
1124+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
11361125 ZEND_PARSE_PARAMETERS_END ();
11371126
1138- context = php_stream_context_from_zval (zcontext , 0 );
1139-
11401127 stream = php_stream_open_wrapper_ex (filename , "rb" , (use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS , NULL , context );
11411128 if (stream ) {
11421129 size = php_stream_passthru (stream );
@@ -1196,15 +1183,14 @@ PHP_FUNCTION(rename)
11961183{
11971184 char * old_name , * new_name ;
11981185 size_t old_name_len , new_name_len ;
1199- zval * zcontext = NULL ;
12001186 php_stream_wrapper * wrapper ;
1201- php_stream_context * context ;
1187+ php_stream_context * context = NULL ;
12021188
12031189 ZEND_PARSE_PARAMETERS_START (2 , 3 )
12041190 Z_PARAM_PATH (old_name , old_name_len )
12051191 Z_PARAM_PATH (new_name , new_name_len )
12061192 Z_PARAM_OPTIONAL
1207- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
1193+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
12081194 ZEND_PARSE_PARAMETERS_END ();
12091195
12101196 wrapper = php_stream_locate_url_wrapper (old_name , NULL , 0 );
@@ -1224,8 +1210,6 @@ PHP_FUNCTION(rename)
12241210 RETURN_FALSE ;
12251211 }
12261212
1227- context = php_stream_context_from_zval (zcontext , 0 );
1228-
12291213 RETURN_BOOL (wrapper -> wops -> rename (wrapper , old_name , new_name , 0 , context ));
12301214}
12311215/* }}} */
@@ -1236,17 +1220,14 @@ PHP_FUNCTION(unlink)
12361220 char * filename ;
12371221 size_t filename_len ;
12381222 php_stream_wrapper * wrapper ;
1239- zval * zcontext = NULL ;
12401223 php_stream_context * context = NULL ;
12411224
12421225 ZEND_PARSE_PARAMETERS_START (1 , 2 )
12431226 Z_PARAM_PATH (filename , filename_len )
12441227 Z_PARAM_OPTIONAL
1245- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
1228+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
12461229 ZEND_PARSE_PARAMETERS_END ();
12471230
1248- context = php_stream_context_from_zval (zcontext , 0 );
1249-
12501231 wrapper = php_stream_locate_url_wrapper (filename , NULL , 0 );
12511232
12521233 if (!wrapper || !wrapper -> wops ) {
@@ -1408,22 +1389,19 @@ PHP_FUNCTION(copy)
14081389{
14091390 char * source , * target ;
14101391 size_t source_len , target_len ;
1411- zval * zcontext = NULL ;
1412- php_stream_context * context ;
1392+ php_stream_context * context = NULL ;
14131393
14141394 ZEND_PARSE_PARAMETERS_START (2 , 3 )
14151395 Z_PARAM_PATH (source , source_len )
14161396 Z_PARAM_PATH (target , target_len )
14171397 Z_PARAM_OPTIONAL
1418- Z_PARAM_RESOURCE_OR_NULL ( zcontext )
1398+ PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT ( context )
14191399 ZEND_PARSE_PARAMETERS_END ();
14201400
14211401 if (php_stream_locate_url_wrapper (source , NULL , 0 ) == & php_plain_files_wrapper && php_check_open_basedir (source )) {
14221402 RETURN_FALSE ;
14231403 }
14241404
1425- context = php_stream_context_from_zval (zcontext , 0 );
1426-
14271405 RETURN_BOOL (php_copy_file_ctx (source , target , 0 , context ) == SUCCESS );
14281406}
14291407/* }}} */
0 commit comments