naspro
view naspro-core/src/posix/dl.c @ 172:d1f0d4a83318
Switching to CMake, part #1
| author | Stefano D'Angelo <zanga.mail@gmail.com> |
|---|---|
| date | Thu Mar 25 18:16:12 2010 +0200 (2010-03-25) |
| parents | d7568c8379c1 |
| children | 4f7243a606b1 |
line source
1 /*
2 * NASPRO - NASPRO Architecture for Sound Processing
3 * Core library
4 *
5 * Copyright (C) 2007-2009 Stefano D'Angelo <zanga.mail@gmail.com>
6 *
7 * See the COPYING file for license conditions.
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <errno.h>
15 #include <dlfcn.h>
17 #include <NASPRO/core/lib.h>
19 #include "src/dl.h"
21 #include "config.h"
23 struct _nacore_dl_module
24 {
25 void *handle;
26 };
28 static size_t dl_file_ext_len;
30 void
31 _nacore_dl_init()
32 {
33 dl_file_ext_len = strlen(SO_FILE_EXT);
34 }
36 void
37 _nacore_dl_fini()
38 {
39 }
41 nacore_dl_module_t
42 nacore_dl_open(const char *file)
43 {
44 void *handle;
45 nacore_dl_module_t dl_handle;
47 handle = dlopen(file, RTLD_LAZY);
48 if (handle == NULL)
49 return NULL;
51 dl_handle = malloc(sizeof(struct _nacore_dl_module));
52 if (dl_handle == NULL)
53 {
54 dlclose(handle);
55 return NULL;
56 }
58 dl_handle->handle = handle;
60 return dl_handle;
61 }
63 void *
64 nacore_dl_sym(nacore_dl_module_t handle, const char *symbol)
65 {
66 void *sym;
67 char *error;
69 dlerror(); /* Clear any existing error */
70 *(void **)(&sym) = dlsym(handle->handle, symbol);
71 error = dlerror();
72 if (error != NULL)
73 return NULL;
75 return sym;
76 }
78 void
79 nacore_dl_close(nacore_dl_module_t handle)
80 {
81 dlclose(handle->handle);
82 free(handle);
83 }
85 char
86 nacore_dl_filename_filter(const char *file)
87 {
88 size_t file_len;
90 file_len = strlen(file);
92 if (file_len <= dl_file_ext_len)
93 return 0;
95 return !strcmp(file + file_len - dl_file_ext_len, SO_FILE_EXT);
96 }
