Skip to content

Commit 25e3547

Browse files
committed
move env variable extract to get_env_location
1 parent 62cf9e6 commit 25e3547

File tree

1 file changed

+47
-37
lines changed

1 file changed

+47
-37
lines changed

main/php_ini.c

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,52 @@ 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 phprc_path[MAXPATHLEN];
420+
#endif
421+
422+
#ifdef PHP_WIN32
423+
if (!env_location) {
424+
char dummybuf;
425+
int size;
426+
427+
SetLastError(0);
428+
429+
/*If the given buffer is not large enough to hold the data, the return value is
430+
the buffer size, in characters, required to hold the string and its terminating
431+
null character. We use this return value to alloc the final buffer. */
432+
size = GetEnvironmentVariableA(envname, &dummybuf, 0);
433+
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
434+
/* The environment variable doesn't exist. */
435+
env_location = "";
436+
} else {
437+
if (size == 0) {
438+
env_location = "";
439+
} else {
440+
size = GetEnvironmentVariableA(envname, phprc_path, size);
441+
if (size == 0) {
442+
env_location = "";
443+
} else {
444+
env_location = phprc_path;
445+
}
446+
}
447+
}
448+
}
449+
#else
450+
if (!env_location) {
451+
env_location = "";
452+
}
453+
#endif
454+
455+
return env_location;
456+
}
457+
/* }}} */
458+
413459
/* {{{ append_ini_path
414460
*/
415461
static void append_ini_path(char *php_ini_search_path, int search_path_size, char *path)
@@ -455,50 +501,14 @@ int php_init_config(void)
455501
} else if (!sapi_module.php_ini_ignore) {
456502
int search_path_size;
457503
char *default_location;
458-
char *env_location;
504+
char *env_location = get_env_location("PHPRC");
459505
#ifdef PHP_WIN32
460506
char *reg_location;
461-
char phprc_path[MAXPATHLEN];
462507
#endif
463508

464-
env_location = getenv("PHPRC");
465-
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
498509
/*
499510
* Prepare search path
500511
*/
501-
502512
search_path_size = MAXPATHLEN * 4 + (int)strlen(env_location) + 3 + 1;
503513
php_ini_search_path = (char *) emalloc(search_path_size);
504514
free_ini_search_path = 1;

0 commit comments

Comments
 (0)