9 # define alloca __builtin_alloca
11 # define alloca __alloca
12 #elif defined _MSC_VER
14 # define alloca _alloca
20 void *alloca (size_t);
27 #include "ecore_file_private.h"
29 static Eina_List *__ecore_file_path_bin = NULL;
31 static Eina_List *_ecore_file_path_from_env(const char *env);
34 ecore_file_path_init(void)
36 __ecore_file_path_bin = _ecore_file_path_from_env("PATH");
40 ecore_file_path_shutdown(void)
44 EINA_LIST_FREE(__ecore_file_path_bin, dir)
45 eina_stringshare_del(dir);
49 _ecore_file_path_from_env(const char *env)
51 Eina_List *path = NULL;
52 char *env_tmp, *env_path, *p, *last;
54 env_tmp = getenv(env);
58 env_path = alloca(sizeof(char) * strlen(env_tmp) + 1);
59 memset(env_path, 0, strlen(env_tmp));
60 strcpy(env_path, env_tmp);
62 for (p = env_path; *p; p++)
69 if (!ecore_file_path_dir_exists(last))
70 path = eina_list_append(path, eina_stringshare_add(last));
75 path = eina_list_append(path, eina_stringshare_add(last));
81 * @addtogroup Ecore_File_Group Ecore_File - Files and directories convenience functions
87 * @brief Check if the given directory is in PATH.
89 * @param in_dir The name of the directory to search in PATH.
90 * @return @c EINA_TRUE if the directory exist in PATH, @c EINA_FALSE otherwise.
92 * This function checks if @p in_dir is in the environment variable
93 * PATH. If @p in_dir is @c NULL, or if PATH is empty, or @p in_dir is
94 * not in PATH, the function returns @c EINA_FALSE, otherwise it returns
98 ecore_file_path_dir_exists(const char *in_dir)
106 if (!__ecore_file_path_bin) return EINA_FALSE;
107 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
109 if (strcmp(dir, in_dir))
117 * @brief Check if the given application is installed.
119 * @param exe The name of the application
120 * @return @c EINA_TRUE if the @p exe is in PATH and is executable,
121 * @c 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 * @c EINA_FALSE, otherwise it returns @c 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));