summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-06-17 09:08:24 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-06-17 09:08:24 +0100
commit26ee423f287afc0839b0904cff526bf1048515fc (patch)
tree8885b7eecbaa532d3af782ecf91cd4a5d828d16f
parent4c6f875c353586ee66c9af0aed48e4866865f846 (diff)
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.c19
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)
50static void 50static void
51_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o, void *event_info EINA_UNUSED) 51_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o, void *event_info EINA_UNUSED)
52{ 52{
53 static char envbuf[20]; // doesn't have to be static, but a good habit
53 char *env; 54 char *env;
54 lang_idx = (lang_idx + 1) % (sizeof (lang) / sizeof (lang[0])); 55 lang_idx = (lang_idx + 1) % (sizeof (lang) / sizeof (lang[0]));
55 fprintf(stderr, "Setting lang of this edje object to '%s'\n", lang[lang_idx]); 56 fprintf(stderr, "Setting lang of this edje object to '%s'\n", lang[lang_idx]);
57
58 // unfortunately dealing with env vars portably means using putenv()
59 // which has issues that lead to complexity like below. the envbuf is
60 // static because in general it's a good habit when dealing with putenv()
61 // but in this case it doesn't need to be. it's good to show good habits
62 // at any rate. read up pn putenv() and how it takes the string pointer
63 // directly into the env and takes "ownership" (but will never actually
64 // free it if its an allocated string etc.).
56 env = getenv("LANGUAGE"); 65 env = getenv("LANGUAGE");
57 setenv("LANGUAGE", lang[lang_idx], 1); 66 if (env) env = strdup(env);
67 snprintf(envbuf, sizeof(envbuf), "LANGUAGE=%s", lang[lang_idx]);
68 putenv(envbuf);
69
58 edje_object_language_set(o, lang[lang_idx]); 70 edje_object_language_set(o, lang[lang_idx]);
59 setenv("LANGUAGE", env, 1); 71
72 snprintf(envbuf, sizeof(envbuf), "LANGUAGE=%s", env ? env : "");
73 putenv(envbuf);
74 free(env);
60} 75}
61 76
62static void 77static void