Package: glib

Function g-setenv

Lambda List

g-setenv (variable value overwrite)

Arguments

variable -- a string with the the environment variable to set, must not contain '='
value -- a string with the value for to set the variable to
overwrite -- a boolean whether to change the variable if it already exists

Return Value

False if the environment variable could not be set.

Details

Sets an environment variable.

Both the name and value of the variable should be in the GLib file name encoding. On UNIX, this means that they can be arbitrary byte strings. On Windows, they should be in UTF-8.

Note that on some systems, when variables are overwritten, the memory used for the previous variables and its value is not reclaimed.

Warning

Environment variable handling in UNIX is not thread-safe, and your program may crash if one thread calls the g-setenv function while another thread is calling the getenv() function. And note that many functions, such as GNU gettext, call the getenv() function internally. This function is only safe to use at the very start of your program, before creating any other threads or creating objects that create worker threads of their own.

If you need to set up the environment for a child process, you can use the g_get_environ() function to get an environment array, modify that with the g_environ_setenv() and g_environ_unsetenv() functions, and then pass that array directly to the execvpe(), g_spawn_async() functions, or the like.
 

See also

2021-9-3