2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
12 #include "ecore_file_private.h"
14 static Eina_List *__ecore_file_path_bin = NULL;
16 static Eina_List *_ecore_file_path_from_env(const char *env);
19 ecore_file_path_init(void)
21 __ecore_file_path_bin = _ecore_file_path_from_env("PATH");
25 ecore_file_path_shutdown(void)
29 EINA_LIST_FREE(__ecore_file_path_bin, dir)
34 _ecore_file_path_from_env(const char *env)
36 Eina_List *path = NULL;
37 char *env_path, *p, *last;
39 env_path = getenv(env);
43 env_path = strdup(env_path);
45 for (p = env_path; *p; p++)
52 if (!ecore_file_path_dir_exists(last))
53 path = eina_list_append(path, strdup(last));
58 path = eina_list_append(path, strdup(last));
65 * Check if the given directory is in PATH
66 * @param The name of the directory to search in PATH
67 * @return 1 if the directory exist in PATH, 0 otherwise
70 ecore_file_path_dir_exists(const char *in_dir)
75 if (!__ecore_file_path_bin) return 0;
76 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
78 if (strcmp(dir, in_dir))
86 * Check if the given application is installed
87 * @param exe The name of the application
88 * @return 1 if the exe is in PATH and is executable
90 * This function check if the given name exist in PATH and is executable
93 ecore_file_app_installed(const char *exe)
100 if (ecore_file_can_exec(exe)) return 1;
102 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
104 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
105 if (ecore_file_can_exec(buf))
113 * Get a list of all the applications installed on the system
114 * @return An Eina_List containing all the executable files in the system
117 ecore_file_app_list(void)
119 Eina_List *list = NULL;
122 char buf[PATH_MAX], *dir, *exe;
124 EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir)
126 files = ecore_file_ls(dir);
127 EINA_LIST_FREE(files, exe)
129 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
130 if ((ecore_file_can_exec(buf)) &&
131 (!ecore_file_is_dir(buf)))
132 list = eina_list_append(list, strdup(buf));