From 26ee423f287afc0839b0904cff526bf1048515fc Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Mon, 17 Jun 2019 09:08:24 +0100 Subject: [PATCH] example - use putenev, not sentenv to be more portable yes - it's much more code too. that's life with putenv(). --- src/examples/edje/edje-text.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/examples/edje/edje-text.c b/src/examples/edje/edje-text.c index 0b7cf8f4bd..2f4d745aa0 100644 --- a/src/examples/edje/edje-text.c +++ b/src/examples/edje/edje-text.c @@ -50,13 +50,28 @@ _on_text_change(void *data EINA_UNUSED, Evas_Object *obj, const char *part) static void _on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o, void *event_info EINA_UNUSED) { + static char envbuf[20]; // doesn't have to be static, but a good habit char *env; lang_idx = (lang_idx + 1) % (sizeof (lang) / sizeof (lang[0])); fprintf(stderr, "Setting lang of this edje object to '%s'\n", lang[lang_idx]); + + // unfortunately dealing with env vars portably means using putenv() + // which has issues that lead to complexity like below. the envbuf is + // static because in general it's a good habit when dealing with putenv() + // but in this case it doesn't need to be. it's good to show good habits + // at any rate. read up pn putenv() and how it takes the string pointer + // directly into the env and takes "ownership" (but will never actually + // free it if its an allocated string etc.). env = getenv("LANGUAGE"); - setenv("LANGUAGE", lang[lang_idx], 1); + if (env) env = strdup(env); + snprintf(envbuf, sizeof(envbuf), "LANGUAGE=%s", lang[lang_idx]); + putenv(envbuf); + edje_object_language_set(o, lang[lang_idx]); - setenv("LANGUAGE", env, 1); + + snprintf(envbuf, sizeof(envbuf), "LANGUAGE=%s", env ? env : ""); + putenv(envbuf); + free(env); } static void