From 72eb2e9bc949847e7447dfe352f656334aa77864 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Thu, 14 Apr 2005 09:09:22 +0000 Subject: [PATCH] wrap putenv... (and for remote_main just strudup - if we leak it doesnt matter - it will not run for long :) ) SVN revision: 14195 --- configure.in | 3 +++ src/bin/e_intl.c | 3 +-- src/bin/e_main.c | 13 ++++++------- src/bin/e_remote_main.c | 4 ++-- src/bin/e_utils.c | 29 +++++++++++++++++++++++++++++ src/bin/e_utils.h | 3 ++- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/configure.in b/configure.in index ae03c5bf4..064389f3d 100644 --- a/configure.in +++ b/configure.in @@ -20,6 +20,9 @@ AM_ENABLE_SHARED AM_PROG_LIBTOOL AC_C___ATTRIBUTE__ +AC_CHECK_FUNCS(setenv) +AC_CHECK_FUNCS(unsetenv) + MODULE_ARCH="$target_os-$target_cpu" AC_SUBST(MODULE_ARCH) AC_DEFINE_UNQUOTED(MODULE_ARCH, "$MODULE_ARCH", "Module architecture") diff --git a/src/bin/e_intl.c b/src/bin/e_intl.c index 80bf6e41a..42dfa2591 100644 --- a/src/bin/e_intl.c +++ b/src/bin/e_intl.c @@ -66,8 +66,7 @@ e_intl_language_set(const char *lang) if (!lang) lang = getenv("LANG"); if (!lang) lang = "en"; _e_intl_language = strdup(lang); - snprintf(buf, sizeof(buf), "LANG=%s", _e_intl_language); - putenv(buf); + e_util_env_set("LANG", _e_intl_language); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALE_DIR); textdomain(PACKAGE); diff --git a/src/bin/e_main.c b/src/bin/e_main.c index 459695402..eed888090 100644 --- a/src/bin/e_main.c +++ b/src/bin/e_main.c @@ -80,7 +80,7 @@ main(int argc, char **argv) printf("after restart!!!\n"); after_restart = 1; } - putenv("RESTART=1"); + e_util_env_set("RESTART", "1"); e_intl_init(); @@ -91,8 +91,7 @@ main(int argc, char **argv) { i++; - snprintf(buf, sizeof(buf), "DISPLAY=%s", argv[i]); - putenv(buf); + e_util_env_set("DISPLAY", argv[i]); } else if ((!strcmp(argv[i], "-fake-xinerama-screen")) && (i < (argc - 1))) { @@ -132,16 +131,16 @@ main(int argc, char **argv) p = strrchr(s, ':'); if (!p) { - snprintf(buf, sizeof(buf), "DISPLAY=%s:0.0", s); - putenv(buf); + snprintf(buf, sizeof(buf), "%s:0.0", s); + e_util_env_set("DISPLAY", buf); } else { p = strrchr(p, '.'); if (!p) { - snprintf(buf, sizeof(buf), "DISPLAY=%s.0", s); - putenv(buf); + snprintf(buf, sizeof(buf), "%s.0", s); + e_util_env_set("DISPLAY", buf); } } } diff --git a/src/bin/e_remote_main.c b/src/bin/e_remote_main.c index f31000c47..a2c88b614 100644 --- a/src/bin/e_remote_main.c +++ b/src/bin/e_remote_main.c @@ -86,7 +86,7 @@ main(int argc, char **argv) if (!p) { snprintf(buf, sizeof(buf), "DISPLAY=%s:0.0", s); - putenv(buf); + putenv(strdup(buf)); } else { @@ -94,7 +94,7 @@ main(int argc, char **argv) if (!p) { snprintf(buf, sizeof(buf), "DISPLAY=%s.0", s); - putenv(buf); + putenv(strdup(buf)); } } } diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c index c31503a9a..00d794c86 100644 --- a/src/bin/e_utils.c +++ b/src/bin/e_utils.c @@ -49,6 +49,35 @@ e_util_wakeup(void) _e_util_dummy_timer = ecore_timer_add(0.0, _e_util_wakeup_cb, NULL); } +void +e_util_env_set(const char *var, const char *val) +{ + char buf[4096]; + + if (val) + { +#ifdef HAVE_SETENV + setenv(var, val, 1); +#else + char buf[8192]; + + snprintf(buf, sizeof(buf), "%s=%s", var, val); + if (getenv(var)) + putenv(buf); + else + putenv(strdup(buf)); +#endif + } + else + { +#ifdef HAVE_UNSETENV + unsetenv(var); +#else + if (getenv(var)) putenv(var); +#endif + } +} + /* local subsystem functions */ static void _e_util_container_fake_mouse_up_cb(void *data) diff --git a/src/bin/e_utils.h b/src/bin/e_utils.h index e7cd560d4..e28728a01 100644 --- a/src/bin/e_utils.h +++ b/src/bin/e_utils.h @@ -9,6 +9,7 @@ EAPI void e_util_container_fake_mouse_up_later(E_Container *con, int button); EAPI void e_util_container_fake_mouse_up_all_later(E_Container *con); EAPI void e_util_wakeup(void); - +EAPI void e_util_env_set(const char *var, const char *val); + #endif #endif