9 # define alloca __builtin_alloca
11 # define alloca __alloca
12 #elif defined _MSC_VER
14 # define alloca _alloca
20 void *alloca (size_t);
26 #include "ecore_file_private.h"
28 static Eina_List *__ecore_file_path_bin = NULL;
30 static Eina_List *_ecore_file_path_from_env(const char *env);
33 ecore_file_path_init(void)
35 __ecore_file_path_bin = _ecore_file_path_from_env("PATH");
39 ecore_file_path_shutdown(void)
43 EINA_LIST_FREE(__ecore_file_path_bin, dir)
44 eina_stringshare_del(dir);
48 _ecore_file_path_from_env(const char *env)
50 Eina_List *path = NULL;
51 char *env_tmp, *env_path, *p, *last;
53 env_tmp = getenv(env);
57 env_path = alloca(sizeof(char) * strlen(env_tmp) + 1);
58 memset(env_path, 0, strlen(env_tmp));
59 strcpy(env_path, env_tmp);
61 for (p = env_path; *p; p++)
68 if (!ecore_file_path_dir_exists(last))
69 path = eina_list_append(path, eina_stringshare_add(last));
74 path = eina_list_append(path, eina_stringshare_add(last));
80 * @addtogroup Ecore_File_Group Ecore_File - Files and directories convenience functions
86 * @brief Check if the given directory is in PATH.
88 * @param The name of the directory to search in PATH.
89 * @return EINA_TRUE if the directory exist in PATH, EINA_FALSE otherwise.
91 * This function checks if @p in_dir is in the environment variable
92 * PATH. If @p in_dir is @c NULL, or if PATH is empty, or @p in_dir is
93 * not in PATH, the function returns EINA_FALSE, otherwise it returns
97 ecore_file_path_dir_exists(const char *in_dir)
105 if (!__ecore_file_path_bin) return EINA_FALSE;
106 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
108 if (strcmp(dir, in_dir))
116 * @brief Check if the given application is installed.
118 * @param exe The name of the application
119 * @return EINA_TRUE if the exe is in PATH and is executable,
120 * EINA_FALSE otherwise.
123 * This function checks if @p exe exists in PATH and is executable. If
124 * @p exe is @c NULL or is not executable, the function returns
125 * EINA_FALSE, otherwise it returns EINA_TRUE.
128 ecore_file_app_installed(const char *exe)
134 if (!exe) return EINA_FALSE;
135 if (ecore_file_can_exec(exe)) return EINA_TRUE;
137 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
139 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
140 if (ecore_file_can_exec(buf))
148 * @brief Get a list of all the applications installed on the system.
150 * @return An Eina_List containing all the executable files in the
153 * This function returns a list of allocated strings of all the
154 * executable files. If no files are found, the function returns
155 * @c NULL. When not needed anymore, the element of the list must be
159 ecore_file_app_list(void)
161 Eina_List *list = NULL;
164 char buf[PATH_MAX], *dir, *exe;
166 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
168 files = ecore_file_ls(dir);
169 EINA_LIST_FREE(files, exe)
171 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
172 if ((ecore_file_can_exec(buf)) &&
173 (!ecore_file_is_dir(buf)))
174 list = eina_list_append(list, strdup(buf));