blob: 4924e9501c29960f118c6ef38e9ec283a77672e6 [file] [log] [blame]
Harald Welteb9ce51c2010-06-30 19:43:11 +02001/* 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
27#include <sys/types.h>
28#include <dirent.h>
29#include <dlfcn.h>
30#include <stdio.h>
31#include <errno.h>
Holger Hans Peter Freytherbe0f7fa2010-08-31 17:14:04 +080032#include <limits.h>
Harald Welteb9ce51c2010-06-30 19:43:11 +020033
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010034#include <osmocom/core/plugin.h>
Harald Welteb9ce51c2010-06-30 19:43:11 +020035
36int plugin_load_all(const char *directory)
37{
38 unsigned int num = 0;
39 char fname[PATH_MAX];
40 DIR *dir;
41 struct dirent *entry;
42
43 dir = opendir(directory);
44 if (!dir)
45 return -errno;
46
47 while ((entry = readdir(dir))) {
48 snprintf(fname, sizeof(fname), "%s/%s", directory,
49 entry->d_name);
50 if (dlopen(fname, RTLD_NOW))
51 num++;
52 }
53
54 closedir(dir);
55
56 return num;
57}
58#else
59int plugin_load_all(const char *directory)
60{
61 return 0;
62}
63#endif /* HAVE_DLFCN_H */