glib: use portable g_setenv()
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Wed, 11 Dec 2019 14:23:28 +0000 (15:23 +0100)
committerThomas Huth <thuth@redhat.com>
Tue, 17 Dec 2019 08:05:23 +0000 (09:05 +0100)
We have a setenv() wrapper in os-win32.c that no one is actually using.
Drop it and change to g_setenv() uniformly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1576074210-52834-7-git-send-email-pbonzini@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
include/sysemu/os-win32.h
os-win32.c
tests/libqtest.c
tests/test-crypto-tlscredsx509.c
tests/test-crypto-tlssession.c
tests/test-io-channel-tls.c
tests/test-vmstate.c
ui/sdl2.c

index ff18b23db148fbb74bd370d83aae8aaefe6b2227..d8978e28c03f5a03bb9c9810a4b547ad8c74d734 100644 (file)
@@ -67,8 +67,6 @@ int getpagesize(void);
 # define EPROTONOSUPPORT EINVAL
 #endif
 
-int setenv(const char *name, const char *value, int overwrite);
-
 typedef struct {
     long tv_sec;
     long tv_usec;
index 1336cd34f03c45219629870764657cd98ca78e75..6b86e022f0e9c9e34c1e3fa3c668aa9c964721e2 100644 (file)
 #include "qemu-options.h"
 #include "sysemu/runstate.h"
 
-/***********************************************************/
-/* Functions missing in mingw */
-
-int setenv(const char *name, const char *value, int overwrite)
-{
-    int result = 0;
-    if (overwrite || !getenv(name)) {
-        size_t length = strlen(name) + strlen(value) + 2;
-        char *string = g_malloc(length);
-        snprintf(string, length, "%s=%s", name, value);
-        result = putenv(string);
-
-        /* Windows takes a copy and does not continue to use our string.
-         * Therefore it can be safely freed on this platform.  POSIX code
-         * typically has to leak the string because according to the spec it
-         * becomes part of the environment.
-         */
-        g_free(string);
-    }
-    return result;
-}
-
 static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 {
     qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_SIGNAL);
index 91e9cb220c59caf8bb35b057d346cd82f78ab7ae..f36e30a4de2a4b4e2921c7fc04b082ff0d63049f 100644 (file)
@@ -254,7 +254,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     s->expected_status = 0;
     s->qemu_pid = fork();
     if (s->qemu_pid == 0) {
-        setenv("QEMU_AUDIO_DRV", "none", true);
+        g_setenv("QEMU_AUDIO_DRV", "none", true);
         execlp("/bin/sh", "sh", "-c", command, NULL);
         exit(1);
     }
index a27efb7540093f2e968d9da16d9243fc5f31b6a1..f487349c32d765ffcd30329c6bdf2c843242e13e 100644 (file)
@@ -141,7 +141,7 @@ int main(int argc, char **argv)
 
     module_call_init(MODULE_INIT_QOM);
     g_test_init(&argc, &argv, NULL);
-    setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
+    g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
     mkdir(WORKDIR, 0700);
 
index 6560d7134f9ce735c13329ecf146c4c22bfe1bba..8b2453fa79b625c12196c26cef9887307a30ac0f 100644 (file)
@@ -398,7 +398,7 @@ int main(int argc, char **argv)
 
     module_call_init(MODULE_INIT_QOM);
     g_test_init(&argc, &argv, NULL);
-    setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
+    g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
     mkdir(WORKDIR, 0700);
 
index 3c9ef6f941fc053dc9e3a02ff0b928cec85de07d..ad7554c534f595a8eccc29833c631e0ac5592d9e 100644 (file)
@@ -273,7 +273,7 @@ int main(int argc, char **argv)
 
     module_call_init(MODULE_INIT_QOM);
     g_test_init(&argc, &argv, NULL);
-    setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
+    g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
     mkdir(WORKDIR, 0700);
 
index 1e5be1d4ffca154d6224993d0e4c76b72b959bbf..8f184f3556690bdd5ab4a3c2a7dbe87ece6c30f9 100644 (file)
@@ -1325,7 +1325,7 @@ int main(int argc, char **argv)
 
     module_call_init(MODULE_INIT_QOM);
 
-    setenv("QTEST_SILENT_ERRORS", "1", 1);
+    g_setenv("QTEST_SILENT_ERRORS", "1", 1);
 
     g_test_init(&argc, &argv, NULL);
     g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
index bd4e73661debd971b92ae7e5a587c36e178550a5..9030f1c42efb846317877fd8257ccc4428ec6272 100644 (file)
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -772,7 +772,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
      * This is a bit hackish but saves us from bigger problem.
      * Maybe it's a good idea to fix this in SDL instead.
      */
-    setenv("SDL_VIDEODRIVER", "x11", 0);
+    g_setenv("SDL_VIDEODRIVER", "x11", 0);
 #endif
 
     if (SDL_Init(SDL_INIT_VIDEO)) {