Function
GLibsetenv
since: 2.4
Declaration [src]
gboolean
g_setenv (
const gchar* variable,
const gchar* value,
gboolean overwrite
)
Description [src]
Sets an environment variable. On UNIX, both the variable’s name and value can be arbitrary byte strings, except that the variable’s name cannot contain ‘=’. 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 isn’t reclaimed.
You should be mindful of the fact that environment variable handling
in UNIX is not thread-safe, and your program may crash if one thread
calls g_setenv()
while another thread is calling getenv(). (And note
that many functions, such as gettext(), call getenv()
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 g_get_environ()
to get an environment array, modify that with
g_environ_setenv()
and g_environ_unsetenv(), and then pass that
array directly to execvpe(), g_spawn_async(), or the like.
Available since: 2.4
Parameters
variable
-
Type:
const gchar*
The environment variable to set, must not contain ‘=’.
The data is owned by the caller of the function. The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows. value
-
Type:
const gchar*
The value for to set the variable to.
The data is owned by the caller of the function. The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows. overwrite
-
Type:
gboolean
Whether to change the variable if it already exists.