9 # define alloca __builtin_alloca
11 # define alloca __alloca
12 #elif defined _MSC_VER
14 # define alloca _alloca
20 void *alloca (size_t);
29 #include <Ecore_File.h>
31 /* define macros and variable for using the eina logging system */
32 #define EFREET_MODULE_LOG_DOM /* no logging in this file */
35 #include "efreet_private.h"
36 #include "efreet_xml.h"
39 * Needs EAPI because of helper binaries
41 EAPI int efreet_cache_update = 1;
43 static int _efreet_init_count = 0;
44 static int efreet_parsed_locale = 0;
45 static const char *efreet_lang = NULL;
46 static const char *efreet_lang_country = NULL;
47 static const char *efreet_lang_modifier = NULL;
48 static void efreet_parse_locale(void);
49 static int efreet_parse_locale_setting(const char *env);
63 if (++_efreet_init_count != 1)
64 return _efreet_init_count;
67 /* Find users real uid and gid */
68 tmp = getenv("SUDO_UID");
70 ruid = strtoul(tmp, NULL, 10);
74 tmp = getenv("SUDO_GID");
76 rgid = strtoul(tmp, NULL, 10);
82 return --_efreet_init_count;
87 if (!ecore_file_init())
90 if (!efreet_base_init())
91 goto shutdown_ecore_file;
93 if (!efreet_cache_init())
94 goto shutdown_efreet_base;
96 if (!efreet_xml_init())
97 goto shutdown_efreet_cache;
99 if (!efreet_icon_init())
100 goto shutdown_efreet_xml;
102 if (!efreet_ini_init())
103 goto shutdown_efreet_icon;
105 if (!efreet_desktop_init())
106 goto shutdown_efreet_ini;
108 if (!efreet_menu_init())
109 goto shutdown_efreet_desktop;
111 if (!efreet_util_init())
112 goto shutdown_efreet_menu;
115 bindtextdomain(PACKAGE, LOCALE_DIR);
116 bind_textdomain_codeset(PACKAGE, "UTF-8");
119 return _efreet_init_count;
121 shutdown_efreet_menu:
122 efreet_menu_shutdown();
123 shutdown_efreet_desktop:
124 efreet_desktop_shutdown();
126 efreet_ini_shutdown();
127 shutdown_efreet_icon:
128 efreet_icon_shutdown();
130 efreet_xml_shutdown();
131 shutdown_efreet_cache:
132 efreet_cache_shutdown();
133 shutdown_efreet_base:
134 efreet_base_shutdown();
136 ecore_file_shutdown();
144 return --_efreet_init_count;
148 efreet_shutdown(void)
150 if (_efreet_init_count <= 0)
152 EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
155 if (--_efreet_init_count != 0)
156 return _efreet_init_count;
158 efreet_util_shutdown();
159 efreet_menu_shutdown();
160 efreet_desktop_shutdown();
161 efreet_ini_shutdown();
162 efreet_icon_shutdown();
163 efreet_xml_shutdown();
164 efreet_cache_shutdown();
165 efreet_base_shutdown();
167 IF_RELEASE(efreet_lang);
168 IF_RELEASE(efreet_lang_country);
169 IF_RELEASE(efreet_lang_modifier);
170 efreet_parsed_locale = 0; /* reset this in case they init efreet again */
172 ecore_file_shutdown();
177 return _efreet_init_count;
181 efreet_lang_reset(void)
183 IF_RELEASE(efreet_lang);
184 IF_RELEASE(efreet_lang_country);
185 IF_RELEASE(efreet_lang_modifier);
186 efreet_parsed_locale = 0; /* reset this in case they init efreet again */
189 efreet_cache_desktop_close();
190 efreet_cache_desktop_update();
195 * @return Returns the current users language setting or NULL if none set
196 * @brief Retrieves the current language setting
199 efreet_lang_get(void)
201 if (efreet_parsed_locale) return efreet_lang;
203 efreet_parse_locale();
209 * @return Returns the current language country setting or NULL if none set
210 * @brief Retrieves the current country setting for the current language or
213 efreet_lang_country_get(void)
215 if (efreet_parsed_locale) return efreet_lang_country;
217 efreet_parse_locale();
218 return efreet_lang_country;
223 * @return Returns the current language modifier setting or NULL if none
225 * @brief Retrieves the modifier setting for the language.
228 efreet_lang_modifier_get(void)
230 if (efreet_parsed_locale) return efreet_lang_modifier;
232 efreet_parse_locale();
233 return efreet_lang_modifier;
238 * @return Returns no value
239 * @brief Parses out the language, country and modifer setting from the
240 * LC_MESSAGES environment variable
243 efreet_parse_locale(void)
245 efreet_parsed_locale = 1;
247 if (efreet_parse_locale_setting("LANG"))
250 if (efreet_parse_locale_setting("LC_ALL"))
253 efreet_parse_locale_setting("LC_MESSAGES");
258 * @param env The environment variable to grab
259 * @return Returns 1 if we parsed something of @a env, 0 otherwise
260 * @brief Tries to parse the lang settings out of the given environment
264 efreet_parse_locale_setting(const char *env)
274 setting = alloca(len);
275 memcpy(setting, p, len);
277 /* pull the modifier off the end */
278 p = strrchr(setting, '@');
282 efreet_lang_modifier = eina_stringshare_add(p + 1);
286 /* if there is an encoding we ignore it */
287 p = strrchr(setting, '.');
290 /* get the country if available */
291 p = strrchr(setting, '_');
295 efreet_lang_country = eina_stringshare_add(p + 1);
299 if (*setting != '\0')
301 efreet_lang = eina_stringshare_add(setting);
310 * @param buffer The destination buffer
311 * @param size The destination buffer size
312 * @param strs The strings to concatenate together
313 * @return Returns the size of the string in @a buffer
314 * @brief Concatenates the strings in @a strs into the given @a buffer not
315 * exceeding the given @a size.
318 efreet_array_cat(char *buffer, size_t size, const char *strs[])
322 for (i = 0, n = 0; n < size && strs[i]; i++)
324 n += eina_strlcpy(buffer + n, strs[i], size - n);
331 efreet_fsetowner(int fd)
336 if (fstat(fd, &st) < 0) return;
337 if (st.st_uid == ruid) return;
339 if (fchown(fd, ruid, rgid) != 0) return;
343 efreet_fsetowner(int fd __UNUSED__)
350 efreet_setowner(const char *path)
352 EINA_SAFETY_ON_NULL_RETURN(path);
356 fd = open(path, O_RDONLY);
358 efreet_fsetowner(fd);
363 efreet_setowner(const char *path __UNUSED__)