XrdSysPlugin.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                       X r d S y s P l u g i n . c c                        */
00004 /*                                                                            */
00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010   
00011 //       $Id: XrdSysPlugin.cc 38011 2011-02-08 18:35:57Z ganis $
00012 
00013 const char *XrdSysPluginCVSID = "$Id: XrdSysPlugin.cc 38011 2011-02-08 18:35:57Z ganis $";
00014 
00015 // Bypass Solaris ELF madness
00016 //
00017 #ifdef __solaris__
00018 #include <sys/isa_defs.h>
00019 #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
00020 #undef  _FILE_OFFSET_BITS
00021 #define _FILE_OFFSET_BITS 32
00022 #undef  _LARGEFILE_SOURCE
00023 #endif
00024 #endif
00025 
00026 #ifndef WIN32
00027 #include <dlfcn.h>
00028 #if !defined(__macos__) && !defined(__CYGWIN__)
00029 #include <link.h>
00030 #endif
00031 #include <stdio.h>
00032 #include <strings.h>
00033 #include <sys/types.h>
00034 #include <errno.h>
00035 #else
00036 #include "XrdSys/XrdWin32.hh"
00037 #endif
00038   
00039 #include "XrdSys/XrdSysError.hh"
00040 #include "XrdSys/XrdSysHeaders.hh"
00041 #include "XrdSys/XrdSysPlugin.hh"
00042  
00043 /******************************************************************************/
00044 /*                            D e s t r u c t o r                             */
00045 /******************************************************************************/
00046   
00047 XrdSysPlugin::~XrdSysPlugin()
00048 {
00049    if (libHandle) dlclose(libHandle);
00050 }
00051 
00052 /******************************************************************************/
00053 /*                             g e t P l u g i n                              */
00054 /******************************************************************************/
00055 
00056 
00057 void *XrdSysPlugin::getPlugin(const char *pname, int errok)
00058 {
00059    return getPlugin(pname, errok, false);
00060 }
00061 
00062 void *XrdSysPlugin::getPlugin(const char *pname, int errok, bool global)
00063 {
00064    void *ep;
00065 
00066 // Open the plugin library if not already opened
00067 //
00068    int flags = RTLD_NOW;
00069 #ifndef WIN32
00070    flags |= global ? RTLD_GLOBAL : RTLD_LOCAL;
00071 #else
00072    if (global)
00073       eDest->Emsg("getPlugin",
00074                   "request for global symbols unsupported under Windows - ignored");
00075 #endif
00076    if (!libHandle && !(libHandle = dlopen(libPath, flags)))
00077       {eDest->Emsg("getPlugin", "Unable to open", libPath, dlerror());
00078        return 0;
00079       }
00080 
00081 // Get the plugin object creator
00082 //
00083    if (!(ep = dlsym(libHandle, pname)) && !errok)
00084       {char buff[1024];
00085        sprintf(buff, "Unable to find %s in", pname);
00086        eDest->Emsg("getPlugin", buff, libPath, dlerror());
00087        return 0;
00088       }
00089 
00090 // All done
00091 //
00092    return ep;
00093 }

Generated on Tue Jul 5 14:47:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1