diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/ecore/src/lib/ecore_file/ecore_file_path.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/ecore/src/lib/ecore_file/ecore_file_path.c')
-rw-r--r-- | libraries/ecore/src/lib/ecore_file/ecore_file_path.c | 185 |
1 files changed, 0 insertions, 185 deletions
diff --git a/libraries/ecore/src/lib/ecore_file/ecore_file_path.c b/libraries/ecore/src/lib/ecore_file/ecore_file_path.c deleted file mode 100644 index f5294b7..0000000 --- a/libraries/ecore/src/lib/ecore_file/ecore_file_path.c +++ /dev/null | |||
@@ -1,185 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #undef alloca | ||
6 | #ifdef HAVE_ALLOCA_H | ||
7 | # include <alloca.h> | ||
8 | #elif defined __GNUC__ | ||
9 | # define alloca __builtin_alloca | ||
10 | #elif defined _AIX | ||
11 | # define alloca __alloca | ||
12 | #elif defined _MSC_VER | ||
13 | # include <malloc.h> | ||
14 | # define alloca _alloca | ||
15 | #else | ||
16 | # include <stddef.h> | ||
17 | # ifdef __cplusplus | ||
18 | extern "C" | ||
19 | # endif | ||
20 | void *alloca (size_t); | ||
21 | #endif | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include "ecore_file_private.h" | ||
28 | |||
29 | static Eina_List *__ecore_file_path_bin = NULL; | ||
30 | |||
31 | static Eina_List *_ecore_file_path_from_env(const char *env); | ||
32 | |||
33 | void | ||
34 | ecore_file_path_init(void) | ||
35 | { | ||
36 | __ecore_file_path_bin = _ecore_file_path_from_env("PATH"); | ||
37 | } | ||
38 | |||
39 | void | ||
40 | ecore_file_path_shutdown(void) | ||
41 | { | ||
42 | char *dir; | ||
43 | |||
44 | EINA_LIST_FREE(__ecore_file_path_bin, dir) | ||
45 | eina_stringshare_del(dir); | ||
46 | } | ||
47 | |||
48 | Eina_List * | ||
49 | _ecore_file_path_from_env(const char *env) | ||
50 | { | ||
51 | Eina_List *path = NULL; | ||
52 | char *env_tmp, *env_path, *p, *last; | ||
53 | |||
54 | env_tmp = getenv(env); | ||
55 | if (!env_tmp) | ||
56 | return path; | ||
57 | |||
58 | env_path = alloca(sizeof(char) * strlen(env_tmp) + 1); | ||
59 | memset(env_path, 0, strlen(env_tmp)); | ||
60 | strcpy(env_path, env_tmp); | ||
61 | last = env_path; | ||
62 | for (p = env_path; *p; p++) | ||
63 | { | ||
64 | if (*p == ':') | ||
65 | *p = '\0'; | ||
66 | |||
67 | if (!*p) | ||
68 | { | ||
69 | if (!ecore_file_path_dir_exists(last)) | ||
70 | path = eina_list_append(path, eina_stringshare_add(last)); | ||
71 | last = p + 1; | ||
72 | } | ||
73 | } | ||
74 | if (p > last) | ||
75 | path = eina_list_append(path, eina_stringshare_add(last)); | ||
76 | |||
77 | return path; | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * @addtogroup Ecore_File_Group Ecore_File - Files and directories convenience functions | ||
82 | * | ||
83 | * @{ | ||
84 | */ | ||
85 | |||
86 | /** | ||
87 | * @brief Check if the given directory is in PATH. | ||
88 | * | ||
89 | * @param in_dir The name of the directory to search in PATH. | ||
90 | * @return EINA_TRUE if the directory exist in PATH, EINA_FALSE otherwise. | ||
91 | * | ||
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 EINA_FALSE, otherwise it returns | ||
95 | * EINA_TRUE. | ||
96 | */ | ||
97 | EAPI Eina_Bool | ||
98 | ecore_file_path_dir_exists(const char *in_dir) | ||
99 | { | ||
100 | Eina_List *l; | ||
101 | char *dir; | ||
102 | |||
103 | if (!in_dir) | ||
104 | return EINA_FALSE; | ||
105 | |||
106 | if (!__ecore_file_path_bin) return EINA_FALSE; | ||
107 | EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir) | ||
108 | { | ||
109 | if (strcmp(dir, in_dir)) | ||
110 | return EINA_TRUE; | ||
111 | } | ||
112 | |||
113 | return EINA_FALSE; | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * @brief Check if the given application is installed. | ||
118 | * | ||
119 | * @param exe The name of the application | ||
120 | * @return EINA_TRUE if the exe is in PATH and is executable, | ||
121 | * EINA_FALSE otherwise. | ||
122 | * | ||
123 | * | ||
124 | * This function checks if @p exe exists in PATH and is executable. If | ||
125 | * @p exe is @c NULL or is not executable, the function returns | ||
126 | * EINA_FALSE, otherwise it returns EINA_TRUE. | ||
127 | */ | ||
128 | EAPI Eina_Bool | ||
129 | ecore_file_app_installed(const char *exe) | ||
130 | { | ||
131 | Eina_List *l; | ||
132 | char *dir; | ||
133 | char buf[PATH_MAX]; | ||
134 | |||
135 | if (!exe) return EINA_FALSE; | ||
136 | if (ecore_file_can_exec(exe)) return EINA_TRUE; | ||
137 | |||
138 | EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir) | ||
139 | { | ||
140 | snprintf(buf, sizeof(buf), "%s/%s", dir, exe); | ||
141 | if (ecore_file_can_exec(buf)) | ||
142 | return EINA_TRUE; | ||
143 | } | ||
144 | |||
145 | return EINA_FALSE; | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * @brief Get a list of all the applications installed on the system. | ||
150 | * | ||
151 | * @return An Eina_List containing all the executable files in the | ||
152 | * system. | ||
153 | * | ||
154 | * This function returns a list of allocated strings of all the | ||
155 | * executable files. If no files are found, the function returns | ||
156 | * @c NULL. When not needed anymore, the element of the list must be | ||
157 | * freed. | ||
158 | */ | ||
159 | EAPI Eina_List * | ||
160 | ecore_file_app_list(void) | ||
161 | { | ||
162 | Eina_List *list = NULL; | ||
163 | Eina_List *files; | ||
164 | Eina_List *l; | ||
165 | char buf[PATH_MAX], *dir, *exe; | ||
166 | |||
167 | EINA_LIST_FOREACH(__ecore_file_path_bin, l, dir) | ||
168 | { | ||
169 | files = ecore_file_ls(dir); | ||
170 | EINA_LIST_FREE(files, exe) | ||
171 | { | ||
172 | snprintf(buf, sizeof(buf), "%s/%s", dir, exe); | ||
173 | if ((ecore_file_can_exec(buf)) && | ||
174 | (!ecore_file_is_dir(buf))) | ||
175 | list = eina_list_append(list, strdup(buf)); | ||
176 | free(exe); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | return list; | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * @} | ||
185 | */ | ||