@@ -410,6 +410,53 @@ static void php_load_zend_extension_cb(void *arg) { }
410410#endif
411411/* }}} */
412412
413+ /* {{{ get_env_location
414+ */
415+ static char * get_env_location (const char * envname )
416+ {
417+ char * env_location = getenv (envname );
418+ #ifdef PHP_WIN32
419+ char * reg_location ;
420+ char phprc_path [MAXPATHLEN ];
421+ #endif
422+
423+ #ifdef PHP_WIN32
424+ if (!env_location ) {
425+ char dummybuf ;
426+ int size ;
427+
428+ SetLastError (0 );
429+
430+ /*If the given buffer is not large enough to hold the data, the return value is
431+ the buffer size, in characters, required to hold the string and its terminating
432+ null character. We use this return value to alloc the final buffer. */
433+ size = GetEnvironmentVariableA (envname , & dummybuf , 0 );
434+ if (GetLastError () == ERROR_ENVVAR_NOT_FOUND ) {
435+ /* The environment variable doesn't exist. */
436+ env_location = "" ;
437+ } else {
438+ if (size == 0 ) {
439+ env_location = "" ;
440+ } else {
441+ size = GetEnvironmentVariableA (envname , phprc_path , size );
442+ if (size == 0 ) {
443+ env_location = "" ;
444+ } else {
445+ env_location = phprc_path ;
446+ }
447+ }
448+ }
449+ }
450+ #else
451+ if (!env_location ) {
452+ env_location = "" ;
453+ }
454+ #endif
455+
456+ return env_location ;
457+ }
458+ /* }}} */
459+
413460/* {{{ append_ini_path
414461 */
415462static void append_ini_path (char * php_ini_search_path , int search_path_size , char * path )
@@ -455,46 +502,8 @@ int php_init_config(void)
455502 } else if (!sapi_module .php_ini_ignore ) {
456503 int search_path_size ;
457504 char * default_location ;
458- char * env_location ;
459- #ifdef PHP_WIN32
460- char * reg_location ;
461- char phprc_path [MAXPATHLEN ];
462- #endif
463-
464- env_location = getenv ("PHPRC" );
505+ char * env_location = get_env_location ("PHPRC" );
465506
466- #ifdef PHP_WIN32
467- if (!env_location ) {
468- char dummybuf ;
469- int size ;
470-
471- SetLastError (0 );
472-
473- /*If the given buffer is not large enough to hold the data, the return value is
474- the buffer size, in characters, required to hold the string and its terminating
475- null character. We use this return value to alloc the final buffer. */
476- size = GetEnvironmentVariableA ("PHPRC" , & dummybuf , 0 );
477- if (GetLastError () == ERROR_ENVVAR_NOT_FOUND ) {
478- /* The environment variable doesn't exist. */
479- env_location = "" ;
480- } else {
481- if (size == 0 ) {
482- env_location = "" ;
483- } else {
484- size = GetEnvironmentVariableA ("PHPRC" , phprc_path , size );
485- if (size == 0 ) {
486- env_location = "" ;
487- } else {
488- env_location = phprc_path ;
489- }
490- }
491- }
492- }
493- #else
494- if (!env_location ) {
495- env_location = "" ;
496- }
497- #endif
498507 /*
499508 * Prepare search path
500509 */
0 commit comments