diff options
author | Timothy Gu <timothygu99@gmail.com> | 2014-01-22 04:24:38 +0000 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2014-01-22 04:24:38 +0000 |
commit | cd27689181969c3144dbf4ec17f8ec90d7b04bd0 (patch) | |
tree | 5754bb2b6ca0ba5a24e367fdb60162d8124e8189 | |
parent | 539e732b6a9025ac6325fff23c33b25a19cd9445 (diff) | |
download | dlfcn-win32-cd27689181969c3144dbf4ec17f8ec90d7b04bd0.tar.gz dlfcn-win32-cd27689181969c3144dbf4ec17f8ec90d7b04bd0.tar.bz2 dlfcn-win32-cd27689181969c3144dbf4ec17f8ec90d7b04bd0.zip |
test.c: return 1 if error
-rw-r--r-- | test.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -20,6 +20,13 @@ | |||
20 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include "dlfcn.h" | 21 | #include "dlfcn.h" |
22 | 22 | ||
23 | /* If these dlclose's fails, we don't care as the handles are going to be | ||
24 | closed eventually when the program ends. */ | ||
25 | #define CLOSE_LIB dlclose( library ); | ||
26 | #define CLOSE_GLOBAL dlclose( global ); | ||
27 | |||
28 | #define RETURN_ERROR return 1; | ||
29 | |||
23 | /* This is what this test does: | 30 | /* This is what this test does: |
24 | * - Open library with RTLD_GLOBAL | 31 | * - Open library with RTLD_GLOBAL |
25 | * - Get global object | 32 | * - Get global object |
@@ -61,6 +68,8 @@ int main() | |||
61 | { | 68 | { |
62 | error = dlerror( ); | 69 | error = dlerror( ); |
63 | printf( "Could not open global handle: %s\n", error ? error : "" ); | 70 | printf( "Could not open global handle: %s\n", error ? error : "" ); |
71 | CLOSE_LIB | ||
72 | RETURN_ERROR | ||
64 | } | 73 | } |
65 | else | 74 | else |
66 | printf( "Got global handle: %p\n", global ); | 75 | printf( "Got global handle: %p\n", global ); |
@@ -71,6 +80,9 @@ int main() | |||
71 | error = dlerror( ); | 80 | error = dlerror( ); |
72 | printf( "Could not get symbol from library handle: %s\n", | 81 | printf( "Could not get symbol from library handle: %s\n", |
73 | error ? error : "" ); | 82 | error ? error : "" ); |
83 | CLOSE_LIB | ||
84 | CLOSE_GLOBAL | ||
85 | RETURN_ERROR | ||
74 | } | 86 | } |
75 | else | 87 | else |
76 | printf( "Got symbol from library handle: %p\n", function ); | 88 | printf( "Got symbol from library handle: %p\n", function ); |
@@ -84,6 +96,9 @@ int main() | |||
84 | error = dlerror( ); | 96 | error = dlerror( ); |
85 | printf( "Could not get symbol from global handle: %s\n", | 97 | printf( "Could not get symbol from global handle: %s\n", |
86 | error ? error : "" ); | 98 | error ? error : "" ); |
99 | CLOSE_LIB | ||
100 | CLOSE_GLOBAL | ||
101 | RETURN_ERROR | ||
87 | } | 102 | } |
88 | else | 103 | else |
89 | printf( "Got symbol from global handle: %p\n", function ); | 104 | printf( "Got symbol from global handle: %p\n", function ); |
@@ -105,6 +120,9 @@ int main() | |||
105 | { | 120 | { |
106 | error = dlerror( ); | 121 | error = dlerror( ); |
107 | printf( "Could not open library locally: %s\n", error ? error : "" ); | 122 | printf( "Could not open library locally: %s\n", error ? error : "" ); |
123 | CLOSE_LIB | ||
124 | CLOSE_GLOBAL | ||
125 | RETURN_ERROR | ||
108 | } | 126 | } |
109 | else | 127 | else |
110 | printf( "Opened library locally: %p\n", library ); | 128 | printf( "Opened library locally: %p\n", library ); |
@@ -115,6 +133,9 @@ int main() | |||
115 | error = dlerror( ); | 133 | error = dlerror( ); |
116 | printf( "Could not get symbol from library handle: %s\n", | 134 | printf( "Could not get symbol from library handle: %s\n", |
117 | error ? error : "" ); | 135 | error ? error : "" ); |
136 | CLOSE_LIB | ||
137 | CLOSE_GLOBAL | ||
138 | RETURN_ERROR | ||
118 | } | 139 | } |
119 | else | 140 | else |
120 | printf( "Got symbol from library handle: %p\n", function ); | 141 | printf( "Got symbol from library handle: %p\n", function ); |
@@ -128,6 +149,9 @@ int main() | |||
128 | error = dlerror( ); | 149 | error = dlerror( ); |
129 | printf( "Could not get symbol from global handle: %s\n", | 150 | printf( "Could not get symbol from global handle: %s\n", |
130 | error ? error : "" ); | 151 | error ? error : "" ); |
152 | CLOSE_LIB | ||
153 | CLOSE_GLOBAL | ||
154 | RETURN_ERROR | ||
131 | } | 155 | } |
132 | else | 156 | else |
133 | printf( "Got symbol from global handle: %p\n", function ); | 157 | printf( "Got symbol from global handle: %p\n", function ); |
@@ -140,6 +164,8 @@ int main() | |||
140 | { | 164 | { |
141 | error = dlerror( ); | 165 | error = dlerror( ); |
142 | printf( "Could not close library: %s\n", error ? error : "" ); | 166 | printf( "Could not close library: %s\n", error ? error : "" ); |
167 | CLOSE_GLOBAL | ||
168 | RETURN_ERROR | ||
143 | } | 169 | } |
144 | else | 170 | else |
145 | printf( "Closed library.\n" ); | 171 | printf( "Closed library.\n" ); |
@@ -149,6 +175,7 @@ int main() | |||
149 | { | 175 | { |
150 | error = dlerror( ); | 176 | error = dlerror( ); |
151 | printf( "Could not close global handle: %s\n", error ? error : "" ); | 177 | printf( "Could not close global handle: %s\n", error ? error : "" ); |
178 | RETURN_ERROR | ||
152 | } | 179 | } |
153 | else | 180 | else |
154 | printf( "Closed global handle.\n" ); | 181 | printf( "Closed global handle.\n" ); |