-rw-r--r-- | library/qlibrary_unix.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/library/qlibrary_unix.cpp b/library/qlibrary_unix.cpp new file mode 100644 index 0000000..50a5478 --- a/dev/null +++ b/library/qlibrary_unix.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "qlibrary_p.h" | ||
22 | |||
23 | #ifndef QT_NO_COMPONENT | ||
24 | |||
25 | /* | ||
26 | The platform dependent implementations of | ||
27 | - loadLibrary | ||
28 | - freeLibrary | ||
29 | - resolveSymbol | ||
30 | |||
31 | It's not too hard to guess what the functions do. | ||
32 | */ | ||
33 | #if defined(Q_OS_HPUX) | ||
34 | // for HP-UX < 11.x and 32 bit | ||
35 | #include <dl.h> | ||
36 | |||
37 | bool QLibraryPrivate::loadLibrary() | ||
38 | { | ||
39 | if ( pHnd ) | ||
40 | return TRUE; | ||
41 | |||
42 | QString filename = library->library(); | ||
43 | |||
44 | pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); | ||
45 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
46 | if ( !pHnd ) | ||
47 | qDebug( "Failed to load library %s!", filename.latin1() ); | ||
48 | #endif | ||
49 | return pHnd != 0; | ||
50 | } | ||
51 | |||
52 | bool QLibraryPrivate::freeLibrary() | ||
53 | { | ||
54 | if ( !pHnd ) | ||
55 | return TRUE; | ||
56 | |||
57 | if ( !shl_unload( (shl_t)pHnd ) ) { | ||
58 | pHnd = 0; | ||
59 | return TRUE; | ||
60 | } | ||
61 | return FALSE; | ||
62 | } | ||
63 | |||
64 | void* QLibraryPrivate::resolveSymbol( const char* symbol ) | ||
65 | { | ||
66 | if ( !pHnd ) | ||
67 | return 0; | ||
68 | |||
69 | void* address = 0; | ||
70 | if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, address ) < 0 ) { | ||
71 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
72 | qDebug( "Couldn't resolve symbol \"%s\"", symbol ); | ||
73 | #endif | ||
74 | return 0; | ||
75 | } | ||
76 | return address; | ||
77 | } | ||
78 | |||
79 | #else // Q_OS_HPUX | ||
80 | // Something else, assuming POSIX | ||
81 | #include <dlfcn.h> | ||
82 | |||
83 | bool QLibraryPrivate::loadLibrary() | ||
84 | { | ||
85 | if ( pHnd ) | ||
86 | return TRUE; | ||
87 | |||
88 | QString filename = library->library(); | ||
89 | |||
90 | pHnd = dlopen( filename.latin1() , RTLD_LAZY ); | ||
91 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
92 | if ( !pHnd ) | ||
93 | qWarning( "%s", dlerror() ); | ||
94 | #endif | ||
95 | return pHnd != 0; | ||
96 | } | ||
97 | |||
98 | bool QLibraryPrivate::freeLibrary() | ||
99 | { | ||
100 | if ( !pHnd ) | ||
101 | return TRUE; | ||
102 | |||
103 | int ec = dlclose( pHnd ); | ||
104 | if ( !ec ) | ||
105 | pHnd = 0; | ||
106 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
107 | else { | ||
108 | const char* error = dlerror(); | ||
109 | if ( error ) | ||
110 | qWarning( "%s", error ); | ||
111 | } | ||
112 | #endif | ||
113 | return pHnd == 0; | ||
114 | } | ||
115 | |||
116 | void* QLibraryPrivate::resolveSymbol( const char* f ) | ||
117 | { | ||
118 | if ( !pHnd ) | ||
119 | return 0; | ||
120 | |||
121 | void* address = dlsym( pHnd, f ); | ||
122 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
123 | const char* error = dlerror(); | ||
124 | if ( error ) | ||
125 | qWarning( "%s", error ); | ||
126 | #endif | ||
127 | return address; | ||
128 | } | ||
129 | |||
130 | #endif // POSIX | ||
131 | |||
132 | #endif // QT_NO_COMPONENT | ||