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 * Check if the given directory is in PATH
62 * @param The name of the directory to search in PATH
63 * @return 1 if the directory exist in PATH, 0 otherwise
66 ecore_file_path_dir_exists(const char *in_dir)
71 if (!__ecore_file_path_bin) return 0;
72 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
74 if (strcmp(dir, in_dir))
82 * Check if the given application is installed
83 * @param exe The name of the application
84 * @return 1 if the exe is in PATH and is executable
86 * This function check if the given name exist in PATH and is executable
89 ecore_file_app_installed(const char *exe)
96 if (ecore_file_can_exec(exe)) return 1;
98 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
100 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
101 if (ecore_file_can_exec(buf))
109 * Get a list of all the applications installed on the system
110 * @return An Eina_List containing all the executable files in the system
113 ecore_file_app_list(void)
115 Eina_List *list = NULL;
118 char buf[PATH_MAX], *dir, *exe;
120 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
122 files = ecore_file_ls(dir);
123 EINA_LIST_FREE(files, exe)
125 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
126 if ((ecore_file_can_exec(buf)) &&
127 (!ecore_file_is_dir(buf)))
128 list = eina_list_append(list, strdup(buf));