Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qlibrary_unix.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: qlibrary_unix.cpp,v 1.2 2003/07/10 02:40:12 llornkcor Exp $
00003 **
00004 ** Implementation of QLibraryPrivate class
00005 **
00006 ** Created : 000101
00007 **
00008 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the tools module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #include "qplatformdefs.h"
00039 #include "private/qlibrary_p.h"
00040 
00041 #ifndef QT_NO_LIBRARY
00042 
00043 #if defined(QT_AOUT_UNDERSCORE)
00044 #include <string.h>
00045 #endif
00046 
00047 /*
00048   The platform dependent implementations of
00049   - loadLibrary
00050   - freeLibrary
00051   - resolveSymbol
00052 
00053   It's not too hard to guess what the functions do.
00054 */
00055 
00056 #if defined(Q_OS_MAC)
00057 
00058 bool QLibraryPrivate::loadLibrary()
00059 {
00060     return FALSE;
00061 }
00062 
00063 bool QLibraryPrivate::freeLibrary()
00064 {
00065     return FALSE;
00066 }
00067 
00068 void* QLibraryPrivate::resolveSymbol( const char* )
00069 {
00070     return 0;
00071 }
00072 
00073 #elif defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit
00074 
00075 bool QLibraryPrivate::loadLibrary()
00076 {
00077     if ( pHnd )
00078         return TRUE;
00079 
00080     QString filename = library->library();
00081 
00082     pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 );
00083 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
00084     if ( !pHnd )
00085         qWarning( "%s: failed to load library!", filename.latin1() );
00086 #endif
00087     return pHnd != 0;
00088 }
00089 
00090 bool QLibraryPrivate::freeLibrary()
00091 {
00092     if ( !pHnd )
00093         return TRUE;
00094 
00095     if ( shl_unload( (shl_t)pHnd ) ) {
00096 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
00097         QString filename = library->library();
00098         qWarning( "%s: Failed to unload library!", filename.latin1() );
00099 #endif
00100         return FALSE;
00101     }
00102     pHnd = 0;
00103     return TRUE;
00104 }
00105 
00106 void* QLibraryPrivate::resolveSymbol( const char* symbol )
00107 {
00108     if ( !pHnd )
00109         return 0;
00110 
00111     void* address = 0;
00112     if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, &address ) < 0 ) {
00113 #if defined(QT_DEBUG_COMPONENT)
00114         QString filename = library->library();
00115         qWarning( "%s: couldn't resolve symbol \"%s\"", filename.latin1(), symbol );
00116 #endif
00117     }
00118     return address;
00119 }
00120 
00121 #else // POSIX
00122 #include <dlfcn.h>
00123 
00124 bool QLibraryPrivate::loadLibrary()
00125 {
00126     if ( pHnd )
00127         return TRUE;
00128 
00129     QString filename = library->library();
00130 
00131     pHnd = dlopen( filename.latin1(), RTLD_LAZY );
00132 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
00133     if ( !pHnd )
00134         qWarning( "%s", dlerror() );
00135 #endif
00136     return pHnd != 0;
00137 }
00138 
00139 bool QLibraryPrivate::freeLibrary()
00140 {
00141     if ( !pHnd )
00142         return TRUE;
00143 
00144     if ( dlclose( pHnd ) ) {
00145 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
00146         qWarning( "%s", dlerror() );
00147 #endif
00148         return FALSE;
00149     }
00150 
00151     pHnd = 0;
00152     return TRUE;
00153 }
00154 
00155 void* QLibraryPrivate::resolveSymbol( const char* symbol )
00156 {
00157     if ( !pHnd )
00158         return 0;
00159 
00160 #if defined(QT_AOUT_UNDERSCORE)
00161     // older a.out systems add an underscore in front of symbols
00162     char* undrscr_symbol = new char[strlen(symbol)+2];
00163     undrscr_symbol[0] = '_';
00164     strcpy(undrscr_symbol+1, symbol);
00165     void* address = dlsym( pHnd, undrscr_symbol );
00166     delete [] undrscr_symbol;
00167 #else
00168     void* address = dlsym( pHnd, symbol );
00169 #endif
00170 #if defined(QT_DEBUG_COMPONENT)
00171     const char* error = dlerror();
00172     if ( error )
00173         qWarning( "%s", error );
00174 #endif
00175     return address;
00176 }
00177 
00178 #endif // POSIX
00179 
00180 #endif

Generated on Sat Nov 5 16:16:38 2005 for OPIE by  doxygen 1.4.2