naspro
view naspro-core/src/posix/dl.c @ 163:d7568c8379c1
Initiial DSSI support + reorganization
| author | Stefano D'Angelo <zanga.mail@gmail.com> |
|---|---|
| date | Fri Sep 11 13:31:52 2009 +0200 (2009-09-11) |
| parents | src/core/posix/dl.c@cc067fdfbaf4 |
| children | d1f0d4a83318 |
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 struct _nacore_dl_module
22 {
23 void *handle;
24 };
26 static size_t dl_file_ext_len;
28 void
29 _nacore_dl_init()
30 {
31 dl_file_ext_len = strlen(SO_FILE_EXT);
32 }
34 void
35 _nacore_dl_fini()
36 {
37 }
39 nacore_dl_module_t
40 nacore_dl_open(const char *file)
41 {
42 void *handle;
43 nacore_dl_module_t dl_handle;
45 handle = dlopen(file, RTLD_LAZY);
46 if (handle == NULL)
47 return NULL;
49 dl_handle = malloc(sizeof(struct _nacore_dl_module));
50 if (dl_handle == NULL)
51 {
52 dlclose(handle);
53 return NULL;
54 }
56 dl_handle->handle = handle;
58 return dl_handle;
59 }
61 void *
62 nacore_dl_sym(nacore_dl_module_t handle, const char *symbol)
63 {
64 void *sym;
65 char *error;
67 dlerror(); /* Clear any existing error */
68 *(void **)(&sym) = dlsym(handle->handle, symbol);
69 error = dlerror();
70 if (error != NULL)
71 return NULL;
73 return sym;
74 }
76 void
77 nacore_dl_close(nacore_dl_module_t handle)
78 {
79 dlclose(handle->handle);
80 free(handle);
81 }
83 char
84 nacore_dl_filename_filter(const char *file)
85 {
86 size_t file_len;
88 file_len = strlen(file);
90 if (file_len <= dl_file_ext_len)
91 return 0;
93 return !strcmp(file + file_len - dl_file_ext_len, SO_FILE_EXT);
94 }
