2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
9 #include "ecore_file_private.h"
12 static Ecore_List *__ecore_file_path_bin = NULL;
14 static Ecore_List *_ecore_file_path_from_env(const char *env);
17 ecore_file_path_init(void)
19 if (++init != 1) return init;
20 __ecore_file_path_bin = _ecore_file_path_from_env("PATH");
21 ecore_list_free_cb_set(__ecore_file_path_bin, free);
26 ecore_file_path_shutdown(void)
28 if (--init != 0) return init;
29 ecore_list_destroy(__ecore_file_path_bin);
30 __ecore_file_path_bin = NULL;
35 _ecore_file_path_from_env(const char *env)
38 char *env_path, *p, *last;
40 path = ecore_list_new();
42 env_path = getenv(env);
46 env_path = strdup(env_path);
48 for (p = env_path; *p; p++)
55 if (!ecore_file_path_dir_exists(last))
56 ecore_list_append(path, strdup(last));
61 ecore_list_append(path, strdup(last));
68 * Check if the given directory is in PATH
69 * @param The name of the directory to search in PATH
70 * @return 1 if the directory exist in PATH, 0 otherwise
73 ecore_file_path_dir_exists(const char *in_dir)
77 if (!__ecore_file_path_bin) return 0;
78 ecore_list_first_goto(__ecore_file_path_bin);
79 while ((dir = ecore_list_next(__ecore_file_path_bin)) != NULL)
81 if (!strcmp(dir, in_dir)) return 1;
87 * Check if the given application is installed
88 * @param exe The name of the application
89 * @return 1 if the exe is in PATH and is executable
91 * This function check if the given name exist in PATH and is executable
94 ecore_file_app_installed(const char *exe)
100 if (ecore_file_can_exec(exe)) return 1;
102 ecore_list_first_goto(__ecore_file_path_bin);
103 while ((dir = ecore_list_next(__ecore_file_path_bin)) != NULL)
105 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
106 if (ecore_file_can_exec(buf)) return 1;
112 * Get a list of all the applications installed on the system
113 * @return An Ecore_List containing all the executable files in the system
116 ecore_file_app_list(void)
118 Ecore_List *list, *files;
119 char buf[PATH_MAX], *dir, *exe;
121 list = ecore_list_new();
122 if (!list) return NULL;
123 ecore_list_free_cb_set(list, free);
124 ecore_list_first_goto(__ecore_file_path_bin);
125 while ((dir = ecore_list_next(__ecore_file_path_bin)) != NULL)
127 files = ecore_file_ls(dir);
130 ecore_list_first_goto(files);
131 while ((exe = ecore_list_next(files)) != NULL)
133 snprintf(buf, sizeof(buf), "%s/%s", dir, exe);
134 if ((ecore_file_can_exec(buf)) &&
135 (!ecore_file_is_dir(buf)))
136 ecore_list_append(list, strdup(buf));
138 ecore_list_destroy(files);