8 #include "ecore_file_private.h"
10 static Eina_List *__ecore_file_path_bin = NULL;
12 static Eina_List *_ecore_file_path_from_env(const char *env);
15 ecore_file_path_init(void)
17 __ecore_file_path_bin = _ecore_file_path_from_env("PATH");
21 ecore_file_path_shutdown(void)
25 EINA_LIST_FREE(__ecore_file_path_bin, dir)
30 _ecore_file_path_from_env(const char *env)
32 Eina_List *path = NULL;
33 char *env_path, *p, *last;
35 env_path = getenv(env);
39 env_path = strdup(env_path);
41 for (p = env_path; *p; p++)
48 if (!ecore_file_path_dir_exists(last))
49 path = eina_list_append(path, strdup(last));
54 path = eina_list_append(path, strdup(last));
61 * @addtogroup Ecore_File_Group Ecore_File - Files and direcotries convenience functions
67 * @brief Check if the given directory is in PATH.
69 * @param The name of the directory to search in PATH.
70 * @return EINA_TRUE if the directory exist in PATH, EINA_FALSE otherwise.
72 * This function checks if @p in_dir is in the environment variable
73 * PATH. If @p in_dir is @c NULL, or if PATH is empty, or @p in_dir is
74 * not in PATH, the function returns EINA_FALSE, otherwise it returns
78 ecore_file_path_dir_exists(const char *in_dir)
86 if (!__ecore_file_path_bin) return EINA_FALSE;
87 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
89 if (strcmp(dir, in_dir))
97 * @brief Check if the given application is installed.
99 * @param exe The name of the application
100 * @return EINA_TRUE if the exe is in PATH and is executable,
101 * EINA_FALSE otherwise.
104 * This function checks if @p exe exists in PATH and is executable. If
105 * @p exe is @c NULL or is not executable, the function returns
106 * EINA_FALSE, otherwise it returns EINA_TRUE.
109 ecore_file_app_installed(const char *exe)
115 if (!exe) return EINA_FALSE;
116 if (ecore_file_can_exec(exe)) return EINA_TRUE;
118 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
120 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
121 if (ecore_file_can_exec(buf))
129 * @brief Get a list of all the applications installed on the system.
131 * @return An Eina_List containing all the executable files in the
134 * This function returns a list of allocated strings of all the
135 * executable files. If no files are found, the function returns
136 * @c NULL. When not needed anymore, the element of the list must be
140 ecore_file_app_list(void)
142 Eina_List *list = NULL;
145 char buf[PATH_MAX], *dir, *exe;
147 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
149 files = ecore_file_ls(dir);
150 EINA_LIST_FREE(files, exe)
152 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
153 if ((ecore_file_can_exec(buf)) &&
154 (!ecore_file_is_dir(buf)))
155 list = eina_list_append(list, strdup(buf));