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);
59 if (++_efreet_init_count != 1)
60 return _efreet_init_count;
62 /* Find users real uid and gid */
63 tmp = getenv("SUDO_UID");
65 ruid = strtoul(tmp, NULL, 10);
69 tmp = getenv("SUDO_GID");
71 rgid = strtoul(tmp, NULL, 10);
76 return --_efreet_init_count;
81 if (!ecore_file_init())
84 if (!efreet_base_init())
85 goto shutdown_ecore_file;
87 if (!efreet_cache_init())
88 goto shutdown_efreet_base;
90 if (!efreet_xml_init())
91 goto shutdown_efreet_cache;
93 if (!efreet_icon_init())
94 goto shutdown_efreet_xml;
96 if (!efreet_ini_init())
97 goto shutdown_efreet_icon;
99 if (!efreet_desktop_init())
100 goto shutdown_efreet_ini;
102 if (!efreet_menu_init())
103 goto shutdown_efreet_desktop;
105 if (!efreet_util_init())
106 goto shutdown_efreet_menu;
108 return _efreet_init_count;
110 shutdown_efreet_menu:
111 efreet_menu_shutdown();
112 shutdown_efreet_desktop:
113 efreet_desktop_shutdown();
115 efreet_ini_shutdown();
116 shutdown_efreet_icon:
117 efreet_icon_shutdown();
119 efreet_xml_shutdown();
120 shutdown_efreet_cache:
121 efreet_cache_shutdown();
122 shutdown_efreet_base:
123 efreet_base_shutdown();
125 ecore_file_shutdown();
133 return --_efreet_init_count;
137 efreet_shutdown(void)
139 if (_efreet_init_count <= 0)
141 EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
144 if (--_efreet_init_count != 0)
145 return _efreet_init_count;
147 efreet_util_shutdown();
148 efreet_menu_shutdown();
149 efreet_desktop_shutdown();
150 efreet_ini_shutdown();
151 efreet_icon_shutdown();
152 efreet_xml_shutdown();
153 efreet_cache_shutdown();
154 efreet_base_shutdown();
156 IF_RELEASE(efreet_lang);
157 IF_RELEASE(efreet_lang_country);
158 IF_RELEASE(efreet_lang_modifier);
159 efreet_parsed_locale = 0; /* reset this in case they init efreet again */
161 ecore_file_shutdown();
166 return _efreet_init_count;
170 efreet_lang_reset(void)
172 IF_RELEASE(efreet_lang);
173 IF_RELEASE(efreet_lang_country);
174 IF_RELEASE(efreet_lang_modifier);
175 efreet_parsed_locale = 0; /* reset this in case they init efreet again */
178 efreet_cache_desktop_reset();
183 * @return Returns the current users language setting or NULL if none set
184 * @brief Retrieves the current language setting
187 efreet_lang_get(void)
189 if (efreet_parsed_locale) return efreet_lang;
191 efreet_parse_locale();
197 * @return Returns the current language country setting or NULL if none set
198 * @brief Retrieves the current country setting for the current language or
201 efreet_lang_country_get(void)
203 if (efreet_parsed_locale) return efreet_lang_country;
205 efreet_parse_locale();
206 return efreet_lang_country;
211 * @return Returns the current language modifier setting or NULL if none
213 * @brief Retrieves the modifier setting for the language.
216 efreet_lang_modifier_get(void)
218 if (efreet_parsed_locale) return efreet_lang_modifier;
220 efreet_parse_locale();
221 return efreet_lang_modifier;
226 * @return Returns no value
227 * @brief Parses out the language, country and modifer setting from the
228 * LC_MESSAGES environment variable
231 efreet_parse_locale(void)
233 efreet_parsed_locale = 1;
235 if (efreet_parse_locale_setting("LANG"))
238 if (efreet_parse_locale_setting("LC_ALL"))
241 efreet_parse_locale_setting("LC_MESSAGES");
246 * @param env The environment variable to grab
247 * @return Returns 1 if we parsed something of @a env, 0 otherwise
248 * @brief Tries to parse the lang settings out of the given environment
252 efreet_parse_locale_setting(const char *env)
262 setting = alloca(len);
263 memcpy(setting, p, len);
265 /* pull the modifier off the end */
266 p = strrchr(setting, '@');
270 efreet_lang_modifier = eina_stringshare_add(p + 1);
274 /* if there is an encoding we ignore it */
275 p = strrchr(setting, '.');
278 /* get the country if available */
279 p = strrchr(setting, '_');
283 efreet_lang_country = eina_stringshare_add(p + 1);
287 if (*setting != '\0')
289 efreet_lang = eina_stringshare_add(setting);
298 * @param buffer The destination buffer
299 * @param size The destination buffer size
300 * @param strs The strings to concatenate together
301 * @return Returns the size of the string in @a buffer
302 * @brief Concatenates the strings in @a strs into the given @a buffer not
303 * exceeding the given @a size.
306 efreet_array_cat(char *buffer, size_t size, const char *strs[])
310 for (i = 0, n = 0; n < size && strs[i]; i++)
312 n += eina_strlcpy(buffer + n, strs[i], size - n);
318 efreet_fsetowner(int fd)
323 if (fstat(fd, &st) < 0) return;
324 if (st.st_uid == ruid) return;
326 if (fchown(fd, ruid, rgid) != 0) return;
330 efreet_setowner(const char *path)
332 EINA_SAFETY_ON_NULL_RETURN(path);
336 fd = open(path, O_RDONLY);
338 efreet_fsetowner(fd);