2 #include "e_precache.h"
4 static void *lib_eina = NULL;
5 static void *lib_ecore = NULL;
6 static void *lib_ecore_file = NULL;
7 static void *lib_ecore_x = NULL;
8 static void *lib_evas = NULL;
9 static void *lib_edje = NULL;
10 static void *lib_eet = NULL;
12 static int *e_precache_end = NULL;
15 static int log_fd = -1;
16 static int do_log = 0;
21 char buf[4096] = "DUMMY", *home;
23 if (log_fd != -1) return;
27 unsetenv("LD_PRELOAD");
29 if (getenv("LD_PRELOAD")) putenv("LD_PRELOAD");
31 e_precache_end = dlsym(NULL, "e_precache_end");
33 if (!e_precache_end) return;
34 if (*e_precache_end) return;
36 home = getenv("HOME");
38 snprintf(buf, sizeof(buf), "%s/.e-precache", home);
40 snprintf(buf, sizeof(buf), "/tmp/.e-precache");
41 log_fd = open(buf, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
42 if (log_fd) do_log = 1;
57 log_write(const char *type, const char *file)
59 static Eina_Hash *s_hash = NULL;
60 static Eina_Hash *o_hash = NULL;
61 static Eina_Hash *d_hash = NULL;
64 if ((e_precache_end) && (*e_precache_end))
71 if (eina_hash_find(s_hash, file)) return;
72 if (!s_hash) s_hash = eina_hash_string_superfast_new(NULL);
73 eina_hash_add(s_hash, file, (void *)1);
75 else if (type[0] == 'o')
77 if (eina_hash_find(o_hash, file)) return;
78 if (!o_hash) o_hash = eina_hash_string_superfast_new(NULL);
79 eina_hash_add(o_hash, file, (void *)1);
81 else if (type[0] == 'd')
83 if (eina_hash_find(d_hash, file)) return;
84 if (!d_hash) d_hash = eina_hash_string_superfast_new(NULL);
85 eina_hash_add(d_hash, file, (void *)1);
87 buf[0] = type[0]; buf[1] = ' ';
88 write(log_fd, buf, 2);
89 write(log_fd, file, strlen(file));
90 write(log_fd, "\n", 1);
94 lib_func(const char *lib1, const char *lib2, const char *fname, const char *libname, void **lib)
98 if (!*lib) *lib = dlopen(lib1, RTLD_GLOBAL | RTLD_LAZY);
99 if (!*lib) *lib = dlopen(lib2, RTLD_GLOBAL | RTLD_LAZY);
100 func = dlsym(*lib, fname);
103 printf("ABORT: Can't find %s() in %s or %s (%s = %p)\n",
104 fname, lib1, lib2, libname, *lib);
113 eina_module_find(const Eina_Array *array, const char *module)
115 static Eina_Module *(*func) (const Eina_Array *array, const char *module) = NULL;
118 func = lib_func("libeina.so", "libeina.so.1",
119 "eina_module_find", "lib_eina", &lib_eina);
120 if (do_log) log_write("o", module);
121 return (*func) (array, module);
125 ecore_app_args_set(int argc, const char **argv)
127 static void (*func) (int argc, const char **argv) = NULL;
130 func = lib_func("libecore.so", "libecore.so.1",
131 "ecore_app_args_set", "lib_ecore", &lib_ecore);
132 if (do_log) log_write("o", (const char *)argv);
133 (*func) (argc, argv);
137 ecore_file_mod_time(const char *file)
139 static long long (*func) (const char *file) = NULL;
142 func = lib_func("libecore_file.so", "libecore_file.so.1",
143 "ecore_file_mod_time", "lib_ecore_file", &lib_ecore_file);
144 if (do_log) log_write("s", file);
145 return (*func) (file);
149 ecore_file_size(const char *file)
151 static int (*func) (const char *file) = NULL;
154 func = lib_func("libecore_file.so", "libecore_file.so.1",
155 "ecore_file_size", "lib_ecore_file", &lib_ecore_file);
156 if (do_log) log_write("s", file);
157 return (*func) (file);
161 ecore_file_exists(const char *file)
163 static int (*func) (const char *file) = NULL;
166 func = lib_func("libecore_file.so", "libecore_file.so.1",
167 "ecore_file_exists", "lib_ecore_file", &lib_ecore_file);
168 if (do_log) log_write("s", file);
169 return (*func) (file);
173 ecore_file_is_dir(const char *file)
175 static int (*func) (const char *file) = NULL;
178 func = lib_func("libecore_file.so", "libecore_file.so.1",
179 "ecore_file_is_dir", "lib_ecore_file", &lib_ecore_file);
180 if (do_log) log_write("s", file);
181 return (*func) (file);
185 ecore_file_can_read(const char *file)
187 static int (*func) (const char *file) = NULL;
190 func = lib_func("libecore_file.so", "libecore_file.so.1",
191 "ecore_file_can_read", "lib_ecore_file", &lib_ecore_file);
192 if (do_log) log_write("s", file);
193 return (*func) (file);
197 ecore_file_can_write(const char *file)
199 static int (*func) (const char *file) = NULL;
202 func = lib_func("libecore_file.so", "libecore_file.so.1",
203 "ecore_file_can_write", "lib_ecore_file", &lib_ecore_file);
204 if (do_log) log_write("s", file);
205 return (*func) (file);
209 ecore_file_can_exec(const char *file)
211 static int (*func) (const char *file) = NULL;
214 func = lib_func("libecore_file.so", "libecore_file.so.1",
215 "ecore_file_can_exec", "lib_ecore_file", &lib_ecore_file);
216 if (do_log) log_write("s", file);
217 return (*func) (file);
221 ecore_file_ls(const char *file)
223 static Eina_List * (*func) (const char *file) = NULL;
226 func = lib_func("libecore_file.so", "libecore_file.so.1",
227 "ecore_file_ls", "lib_ecore_file", &lib_ecore_file);
228 if (do_log) log_write("d", file);
229 return (*func) (file);
233 ecore_x_init(const char *name)
235 static int (*func) (const char *name) = NULL;
238 func = lib_func("libecore_x.so", "libecore_x.so.1",
239 "ecore_x_init", "lib_ecore_x", &lib_ecore_x);
240 if (do_log) log_write("o", name);
241 return (*func) (name);
245 evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
247 static void (*func) (Evas_Object *obj, const char *file, const char *key) = NULL;
250 func = lib_func("libevas.so", "libevas.so.1",
251 "evas_object_image_file_set", "lib_evas", &lib_evas);
252 if (do_log) log_write("o", file);
253 (*func) (obj, file, key);
258 edje_object_file_set(Evas_Object *obj, const char *file, const char *group)
260 static Eina_Bool (*func) (Evas_Object *obj, const char *file, const char *group) = NULL;
263 func = lib_func("libedje.so", "libedje.so.1",
264 "edje_object_file_set", "lib_edje", &lib_edje);
265 if (do_log) log_write("o", file);
266 return (*func) (obj, file, group);
270 eet_open(const char *file, Eet_File_Mode mode)
272 static Eet_File * (*func) (const char *file, Eet_File_Mode mode) = NULL;
275 func = lib_func("libeet.so", "libeet.so.0",
276 "eet_open", "lib_eet", &lib_eet);
277 if (do_log) log_write("o", file);
278 return (*func) (file, mode);