[gnome-builder] libide/foundry: add getenv/setenv helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/foundry: add getenv/setenv helper
- Date: Thu, 15 Sep 2022 23:00:15 +0000 (UTC)
commit cc97e049b27c9950068af3c8bb3f25fa0d32dad5
Author: Christian Hergert <chergert redhat com>
Date: Thu Sep 15 15:43:15 2022 -0700
libide/foundry: add getenv/setenv helper
This is nice so that you don't have to work with the char** environment
variables directly.
src/libide/foundry/ide-run-command.c | 36 ++++++++++++++++++++++++++++++++++++
src/libide/foundry/ide-run-command.h | 7 +++++++
2 files changed, 43 insertions(+)
---
diff --git a/src/libide/foundry/ide-run-command.c b/src/libide/foundry/ide-run-command.c
index 642473c93..eb798aa33 100644
--- a/src/libide/foundry/ide-run-command.c
+++ b/src/libide/foundry/ide-run-command.c
@@ -712,3 +712,39 @@ ide_run_command_set_can_default (IdeRunCommand *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_DEFAULT]);
}
}
+
+const char *
+ide_run_command_getenv (IdeRunCommand *self,
+ const char *key)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+
+ if (priv->environ == NULL)
+ return NULL;
+
+ return g_environ_getenv (priv->environ, key);
+}
+
+void
+ide_run_command_setenv (IdeRunCommand *self,
+ const char *key,
+ const char *value)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_RUN_COMMAND (self));
+ g_return_if_fail (key != NULL);
+
+ if (value == NULL && priv->environ == NULL)
+ return;
+
+ if (value != NULL)
+ priv->environ = g_environ_setenv (priv->environ, key, value, TRUE);
+ else
+ priv->environ = g_environ_unsetenv (priv->environ, key);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ENVIRON]);
+}
diff --git a/src/libide/foundry/ide-run-command.h b/src/libide/foundry/ide-run-command.h
index f299f67af..d529c93b1 100644
--- a/src/libide/foundry/ide-run-command.h
+++ b/src/libide/foundry/ide-run-command.h
@@ -82,6 +82,13 @@ IDE_AVAILABLE_IN_ALL
void ide_run_command_set_environ (IdeRunCommand *self,
const char * const *environ);
IDE_AVAILABLE_IN_ALL
+const char *ide_run_command_getenv (IdeRunCommand *self,
+ const char *key);
+IDE_AVAILABLE_IN_ALL
+void ide_run_command_setenv (IdeRunCommand *self,
+ const char *key,
+ const char *value);
+IDE_AVAILABLE_IN_ALL
int ide_run_command_get_priority (IdeRunCommand *self);
IDE_AVAILABLE_IN_ALL
void ide_run_command_set_priority (IdeRunCommand *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]