Skip to content

Commit

Permalink
Protect use of dlopen() and dlsym() with HAVE_DLSYM and HAVE_DLFCN_H …
Browse files Browse the repository at this point in the history
…for compatibility with cases where these functions aren’t available.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10349 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Oct 1, 2014
1 parent fca603c commit ecbda61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Fl_Native_File_Chooser_FLTK.cxx
Expand Up @@ -16,6 +16,7 @@
// http://www.fltk.org/str.php
//

#include <config.h>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/Fl_File_Icon.H>
#define FLTK_CHOOSER_SINGLE Fl_File_Chooser::SINGLE
Expand Down Expand Up @@ -50,9 +51,11 @@ Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
#endif // FLTK_ABI_VERSION
if (have_looked_for_GTK_libs == 0) {
// First Time here, try to find the GTK libs if they are installed
#if HAVE_DLSYM && HAVE_DLFCN_H
if (Fl::option(Fl::OPTION_FNFC_USES_GTK)) {
Fl_GTK_File_Chooser::probe_for_GTK_libs();
}
#endif
have_looked_for_GTK_libs = -1;
}
// if we found all the GTK functions we need, we will use the GtkFileChooserDialog
Expand Down
8 changes: 7 additions & 1 deletion src/Fl_Native_File_Chooser_GTK.cxx
Expand Up @@ -17,7 +17,9 @@
//

#include <FL/x.H>
#if HAVE_DLSYM && HAVE_DLFCN_H
#include <dlfcn.h> // for dlopen et al
#endif
#include <locale.h> // for setlocale

/* --------------------- Type definitions from GLIB and GTK --------------------- */
Expand Down Expand Up @@ -620,8 +622,9 @@ int Fl_GTK_File_Chooser::fl_gtk_chooser_wrapper()
return result;
} // fl_gtk_chooser_wrapper

#if HAVE_DLSYM && HAVE_DLFCN_H
// macro to help with the symbol loading boilerplate...
#define GET_SYM(SSS, LLL) \
# define GET_SYM(SSS, LLL) \
dlerror(); /* Clear any existing error */ \
fl_##SSS = (XX_##SSS)dlsym(LLL, #SSS); \
if ((pc_dl_error = dlerror()) != NULL) { \
Expand All @@ -635,13 +638,15 @@ static void* fl_dlopen(const char *filename1, const char *filename2)
if (!ptr) ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL);
return ptr;
}
#endif

/*
* Use dlopen to see if we can load the gtk dynamic libraries that
* will allow us to create a GtkFileChooserDialog() on the fly,
* without linking to the GTK libs at compile time.
*/
void Fl_GTK_File_Chooser::probe_for_GTK_libs(void) {
#if HAVE_DLSYM && HAVE_DLFCN_H
void *ptr_glib = NULL;
void *ptr_gtk = NULL;

Expand Down Expand Up @@ -719,6 +724,7 @@ void Fl_GTK_File_Chooser::probe_for_GTK_libs(void) {
GET_SYM(gtk_toggle_button_set_active, ptr_gtk);

did_find_GTK_libs = 1;
#endif
} // probe_for_GTK_libs

//
Expand Down

0 comments on commit ecbda61

Please sign in to comment.