[3/4] Allow NULL to be passed to environment-related functions
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
This changse the various environment-related helper functions to
accept a NULL environment pointer. This special case means that the
function should affect gdb's global environment.
---
gdb/infcmd.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
@@ -2014,7 +2014,7 @@ display_environment (const gdb_environ *env, const char *var)
{
if (var)
{
- const char *val = env->get (var);
+ const char *val = env == nullptr ? getenv (var) : env->get (var);
if (val)
{
@@ -2032,7 +2032,9 @@ display_environment (const gdb_environ *env, const char *var)
}
else
{
- char **envp = env->envp ();
+ char **envp = env == nullptr ? environ : env->envp ();
+ if (envp == nullptr)
+ return;
for (int idx = 0; envp[idx] != nullptr; ++idx)
{
@@ -2108,10 +2110,18 @@ set_var_in_environment (gdb_environ *env, const char *arg)
gdb_printf (_("Setting environment variable "
"\"%s\" to null value.\n"),
var.c_str ());
- env->set (var.c_str (), "");
+ if (env == nullptr)
+ setenv (var.c_str (), "", 1);
+ else
+ env->set (var.c_str (), "");
}
else
- env->set (var.c_str (), val);
+ {
+ if (env == nullptr)
+ setenv (var.c_str (), val, 1);
+ else
+ env->set (var.c_str (), val);
+ }
}
static void
@@ -2132,10 +2142,20 @@ unset_var_in_environment (gdb_environ *env, const char *var, int from_tty)
/* If there is no argument, delete all environment variables.
Ask for confirmation if reading from the terminal. */
if (!from_tty || query (_("Delete all environment variables? ")))
- env->clear ();
+ {
+ if (env == nullptr)
+ clearenv ();
+ else
+ env->clear ();
+ }
}
else
- env->unset (var);
+ {
+ if (env == nullptr)
+ unsetenv (var);
+ else
+ env->unset (var);
+ }
}
static void