diff options
author | Timothy Gu <timothygu99@gmail.com> | 2014-02-10 03:08:12 +0000 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2014-02-10 03:08:12 +0000 |
commit | 507ae09fede6b17eddc5bff1a0b0572a3f3db37b (patch) | |
tree | db6560dab20d6f199eeb25d5535b4bc66701ff62 | |
parent | 346543d6f955f6f3aff4fb54f4e5c2d3829897e3 (diff) | |
download | dlfcn-win32-507ae09fede6b17eddc5bff1a0b0572a3f3db37b.tar.gz dlfcn-win32-507ae09fede6b17eddc5bff1a0b0572a3f3db37b.tar.bz2 dlfcn-win32-507ae09fede6b17eddc5bff1a0b0572a3f3db37b.zip |
test.c: make errors stand out
-rw-r--r-- | test.c | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -59,34 +59,34 @@ int main() | |||
59 | if( !library ) | 59 | if( !library ) |
60 | { | 60 | { |
61 | error = dlerror( ); | 61 | error = dlerror( ); |
62 | printf( "Could not open library globally: %s\n", error ? error : "" ); | 62 | printf( "ERROR\tCould not open library globally: %s\n", error ? error : "" ); |
63 | } | 63 | } |
64 | else | 64 | else |
65 | printf( "Opened library globally: %p\n", library ); | 65 | printf( "SUCCESS\tOpened library globally: %p\n", library ); |
66 | 66 | ||
67 | global = dlopen( 0, RTLD_GLOBAL ); | 67 | global = dlopen( 0, RTLD_GLOBAL ); |
68 | if( !global ) | 68 | if( !global ) |
69 | { | 69 | { |
70 | error = dlerror( ); | 70 | error = dlerror( ); |
71 | printf( "Could not open global handle: %s\n", error ? error : "" ); | 71 | printf( "ERROR\tCould not open global handle: %s\n", error ? error : "" ); |
72 | CLOSE_LIB | 72 | CLOSE_LIB |
73 | RETURN_ERROR | 73 | RETURN_ERROR |
74 | } | 74 | } |
75 | else | 75 | else |
76 | printf( "Got global handle: %p\n", global ); | 76 | printf( "SUCCESS\tGot global handle: %p\n", global ); |
77 | 77 | ||
78 | function = dlsym( library, "function" ); | 78 | function = dlsym( library, "function" ); |
79 | if( !function ) | 79 | if( !function ) |
80 | { | 80 | { |
81 | error = dlerror( ); | 81 | error = dlerror( ); |
82 | printf( "Could not get symbol from library handle: %s\n", | 82 | printf( "ERROR\tCould not get symbol from library handle: %s\n", |
83 | error ? error : "" ); | 83 | error ? error : "" ); |
84 | CLOSE_LIB | 84 | CLOSE_LIB |
85 | CLOSE_GLOBAL | 85 | CLOSE_GLOBAL |
86 | RETURN_ERROR | 86 | RETURN_ERROR |
87 | } | 87 | } |
88 | else | 88 | else |
89 | printf( "Got symbol from library handle: %p\n", function ); | 89 | printf( "SUCCESS\tGot symbol from library handle: %p\n", function ); |
90 | 90 | ||
91 | if( function ) | 91 | if( function ) |
92 | function( ); | 92 | function( ); |
@@ -95,14 +95,14 @@ int main() | |||
95 | if( !function ) | 95 | if( !function ) |
96 | { | 96 | { |
97 | error = dlerror( ); | 97 | error = dlerror( ); |
98 | printf( "Could not get symbol from global handle: %s\n", | 98 | printf( "ERROR\tCould not get symbol from global handle: %s\n", |
99 | error ? error : "" ); | 99 | error ? error : "" ); |
100 | CLOSE_LIB | 100 | CLOSE_LIB |
101 | CLOSE_GLOBAL | 101 | CLOSE_GLOBAL |
102 | RETURN_ERROR | 102 | RETURN_ERROR |
103 | } | 103 | } |
104 | else | 104 | else |
105 | printf( "Got symbol from global handle: %p\n", function ); | 105 | printf( "SUCCESS\tGot symbol from global handle: %p\n", function ); |
106 | 106 | ||
107 | if( function ) | 107 | if( function ) |
108 | function( ); | 108 | function( ); |
@@ -111,35 +111,36 @@ int main() | |||
111 | if( ret ) | 111 | if( ret ) |
112 | { | 112 | { |
113 | error = dlerror( ); | 113 | error = dlerror( ); |
114 | printf( "Could not close library: %s\n", error ? error : "" ); | 114 | printf( "ERROR\tCould not close library: %s\n", error ? error : "" ); |
115 | RETURN_ERROR | ||
115 | } | 116 | } |
116 | else | 117 | else |
117 | printf( "Closed library.\n" ); | 118 | printf( "SUCCESS\tClosed library.\n" ); |
118 | 119 | ||
119 | library = dlopen( "testdll.dll", RTLD_LOCAL ); | 120 | library = dlopen( "testdll.dll", RTLD_LOCAL ); |
120 | if( !library ) | 121 | if( !library ) |
121 | { | 122 | { |
122 | error = dlerror( ); | 123 | error = dlerror( ); |
123 | printf( "Could not open library locally: %s\n", error ? error : "" ); | 124 | printf( "ERROR\tCould not open library locally: %s\n", error ? error : "" ); |
124 | CLOSE_LIB | 125 | CLOSE_LIB |
125 | CLOSE_GLOBAL | 126 | CLOSE_GLOBAL |
126 | RETURN_ERROR | 127 | RETURN_ERROR |
127 | } | 128 | } |
128 | else | 129 | else |
129 | printf( "Opened library locally: %p\n", library ); | 130 | printf( "SUCCESS\tOpened library locally: %p\n", library ); |
130 | 131 | ||
131 | function = dlsym( library, "function" ); | 132 | function = dlsym( library, "function" ); |
132 | if( !function ) | 133 | if( !function ) |
133 | { | 134 | { |
134 | error = dlerror( ); | 135 | error = dlerror( ); |
135 | printf( "Could not get symbol from library handle: %s\n", | 136 | printf( "ERROR\tCould not get symbol from library handle: %s\n", |
136 | error ? error : "" ); | 137 | error ? error : "" ); |
137 | CLOSE_LIB | 138 | CLOSE_LIB |
138 | CLOSE_GLOBAL | 139 | CLOSE_GLOBAL |
139 | RETURN_ERROR | 140 | RETURN_ERROR |
140 | } | 141 | } |
141 | else | 142 | else |
142 | printf( "Got symbol from library handle: %p\n", function ); | 143 | printf( "SUCCESS\tGot symbol from library handle: %p\n", function ); |
143 | 144 | ||
144 | if( function ) | 145 | if( function ) |
145 | function( ); | 146 | function( ); |
@@ -148,14 +149,14 @@ int main() | |||
148 | if( function ) | 149 | if( function ) |
149 | { | 150 | { |
150 | error = dlerror( ); | 151 | error = dlerror( ); |
151 | printf( "Got local symbol from global handle: %s\n", | 152 | printf( "ERROR\tGot local symbol from global handle: %s\n", |
152 | error ? error : "" ); | 153 | error ? error : "" ); |
153 | CLOSE_LIB | 154 | CLOSE_LIB |
154 | CLOSE_GLOBAL | 155 | CLOSE_GLOBAL |
155 | RETURN_ERROR | 156 | RETURN_ERROR |
156 | } | 157 | } |
157 | else | 158 | else |
158 | printf( "Did not get local symbol from global handle: %p\n", function ); | 159 | printf( "SUCCESS\tDid not get local symbol from global handle: %p\n", function ); |
159 | 160 | ||
160 | if( function ) | 161 | if( function ) |
161 | function( ); | 162 | function( ); |
@@ -164,22 +165,22 @@ int main() | |||
164 | if( ret ) | 165 | if( ret ) |
165 | { | 166 | { |
166 | error = dlerror( ); | 167 | error = dlerror( ); |
167 | printf( "Could not close library: %s\n", error ? error : "" ); | 168 | printf( "ERROR\tCould not close library: %s\n", error ? error : "" ); |
168 | CLOSE_GLOBAL | 169 | CLOSE_GLOBAL |
169 | RETURN_ERROR | 170 | RETURN_ERROR |
170 | } | 171 | } |
171 | else | 172 | else |
172 | printf( "Closed library.\n" ); | 173 | printf( "SUCCESS\tClosed library.\n" ); |
173 | 174 | ||
174 | ret = dlclose( global ); | 175 | ret = dlclose( global ); |
175 | if( ret ) | 176 | if( ret ) |
176 | { | 177 | { |
177 | error = dlerror( ); | 178 | error = dlerror( ); |
178 | printf( "Could not close global handle: %s\n", error ? error : "" ); | 179 | printf( "ERROR\tCould not close global handle: %s\n", error ? error : "" ); |
179 | RETURN_ERROR | 180 | RETURN_ERROR |
180 | } | 181 | } |
181 | else | 182 | else |
182 | printf( "Closed global handle.\n" ); | 183 | printf( "SUCCESS\tClosed global handle.\n" ); |
183 | 184 | ||
184 | return 0; | 185 | return 0; |
185 | } | 186 | } |