Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 1 | /* plugin infrastructure */ |
| 2 | |
| 3 | /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "../config.h" |
| 24 | |
| 25 | #if HAVE_DLFCN_H |
| 26 | |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 27 | #include <dirent.h> |
| 28 | #include <dlfcn.h> |
| 29 | #include <stdio.h> |
| 30 | #include <errno.h> |
Holger Hans Peter Freyther | be0f7fa | 2010-08-31 17:14:04 +0800 | [diff] [blame] | 31 | #include <limits.h> |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 32 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 33 | #include <osmocom/core/plugin.h> |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 34 | |
Pablo Neira Ayuso | 2c34867 | 2011-05-07 12:50:08 +0200 | [diff] [blame] | 35 | int osmo_plugin_load_all(const char *directory) |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 36 | { |
| 37 | unsigned int num = 0; |
| 38 | char fname[PATH_MAX]; |
| 39 | DIR *dir; |
| 40 | struct dirent *entry; |
| 41 | |
| 42 | dir = opendir(directory); |
| 43 | if (!dir) |
| 44 | return -errno; |
| 45 | |
| 46 | while ((entry = readdir(dir))) { |
| 47 | snprintf(fname, sizeof(fname), "%s/%s", directory, |
| 48 | entry->d_name); |
| 49 | if (dlopen(fname, RTLD_NOW)) |
| 50 | num++; |
| 51 | } |
| 52 | |
| 53 | closedir(dir); |
| 54 | |
| 55 | return num; |
| 56 | } |
| 57 | #else |
Pablo Neira Ayuso | 2c34867 | 2011-05-07 12:50:08 +0200 | [diff] [blame] | 58 | int osmo_plugin_load_all(const char *directory) |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 59 | { |
| 60 | return 0; |
| 61 | } |
| 62 | #endif /* HAVE_DLFCN_H */ |