1 /*****************************************************************************
2 * plugin.c : Low-level dynamic library handling
3 *****************************************************************************
4 * Copyright (C) 2001-2007 VLC authors and VideoLAN
5 * Copyright (C) 2012 KO Myung-Hun
8 * Authors: Sam Hocevar <sam@zoy.org>
9 * Ethan C. Baldridge <BaldridgeE@cadmus.com>
10 * Hans-Peter Jansen <hpj@urpla.net>
11 * Gildas Bazin <gbazin@videolan.org>
12 * KO Myung-Hun <komh@chollian.net>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation; either version 2.1 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this program; if not, write to the Free Software Foundation,
26 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
34 #include <sys/types.h>
37 #include <vlc_common.h>
38 #include <vlc_charset.h>
39 #include "modules/modules.h"
41 void *vlc_dlopen(const char *psz_file
, bool lazy
)
43 const int flags
= lazy
? RTLD_LAZY
: RTLD_NOW
;
44 char *path
= ToLocaleDup( psz_file
);
45 if (unlikely(path
== NULL
))
48 void *handle
= dlopen( path
, flags
);
53 int vlc_dlclose(void *handle
)
55 return dlclose( handle
);
58 void *vlc_dlsym(void *handle
, const char *psz_function
)
60 char buf
[strlen(psz_function
) + 2];
62 strcpy(buf
+ 1, psz_function
);
63 return dlsym( handle
, buf
);
66 char *vlc_dlerror(void)
68 const char *errmsg
= dlerror();
69 return (errmsg
!= NULL
) ? FromLocaleDup(errmsg
) : NULL
;