diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2019-06-17 09:08:24 +0100 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2019-06-17 09:08:24 +0100 |
commit | 26ee423f287afc0839b0904cff526bf1048515fc (patch) | |
tree | 8885b7eecbaa532d3af782ecf91cd4a5d828d16f | |
parent | 4c6f875c353586ee66c9af0aed48e4866865f846 (diff) | |
download | efl-26ee423f287afc0839b0904cff526bf1048515fc.tar.gz |
example - use putenev, not sentenv to be more portable
yes - it's much more code too. that's life with putenv().
-rw-r--r-- | src/examples/edje/edje-text.c | 19 |
1 files 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 |