diff options
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -24,6 +24,7 @@ | |||
24 | #include <crtdbg.h> | 24 | #include <crtdbg.h> |
25 | #endif | 25 | #endif |
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include <string.h> | ||
27 | #include "dlfcn.h" | 28 | #include "dlfcn.h" |
28 | 29 | ||
29 | /* If these dlclose's fails, we don't care as the handles are going to be | 30 | /* If these dlclose's fails, we don't care as the handles are going to be |
@@ -41,7 +42,6 @@ | |||
41 | RETURN_ERROR; \ | 42 | RETURN_ERROR; \ |
42 | } \ | 43 | } \ |
43 | } while( 0 ) | 44 | } while( 0 ) |
44 | |||
45 | 45 | ||
46 | /* This is what this test does: | 46 | /* This is what this test does: |
47 | * - Open library with RTLD_GLOBAL | 47 | * - Open library with RTLD_GLOBAL |
@@ -74,7 +74,7 @@ int main() | |||
74 | void *library; | 74 | void *library; |
75 | char *error; | 75 | char *error; |
76 | int (*function)( void ); | 76 | int (*function)( void ); |
77 | int (*printf_local)( const char * ); | 77 | size_t (*fwrite_local) ( const void *, size_t, size_t, FILE * ); |
78 | int (*nonexistentfunction)( void ); | 78 | int (*nonexistentfunction)( void ); |
79 | int ret; | 79 | int ret; |
80 | 80 | ||
@@ -108,8 +108,8 @@ int main() | |||
108 | else | 108 | else |
109 | printf( "SUCCESS\tGot global handle: %p\n", global ); | 109 | printf( "SUCCESS\tGot global handle: %p\n", global ); |
110 | 110 | ||
111 | printf_local = dlsym(global, "printf"); | 111 | fwrite_local = dlsym(global, "fwrite"); |
112 | if (!printf_local) | 112 | if (!fwrite_local) |
113 | { | 113 | { |
114 | error = dlerror(); | 114 | error = dlerror(); |
115 | printf("ERROR\tCould not get symbol from global handle: %s\n", | 115 | printf("ERROR\tCould not get symbol from global handle: %s\n", |
@@ -119,8 +119,10 @@ int main() | |||
119 | RETURN_ERROR; | 119 | RETURN_ERROR; |
120 | } | 120 | } |
121 | else | 121 | else |
122 | printf("SUCCESS\tGot symbol from global handle: %p\n", printf_local); | 122 | printf("SUCCESS\tGot symbol from global handle: %p\n", fwrite_local); |
123 | printf_local("Hello world from local printf!\n"); | 123 | char * hello_world = "Hello world from local fwrite!\n"; |
124 | fwrite_local(hello_world,sizeof(char),strlen(hello_world),stderr); | ||
125 | fflush(stderr); | ||
124 | 126 | ||
125 | function = dlsym( library, "function" ); | 127 | function = dlsym( library, "function" ); |
126 | if( !function ) | 128 | if( !function ) |
@@ -304,7 +306,7 @@ int main() | |||
304 | error ? error : "" ); | 306 | error ? error : "" ); |
305 | } | 307 | } |
306 | 308 | ||
307 | function = dlsym(global, "printf"); | 309 | function = dlsym(global, "fwrite"); |
308 | if (!function) | 310 | if (!function) |
309 | { | 311 | { |
310 | error = dlerror(); | 312 | error = dlerror(); |
@@ -316,6 +318,7 @@ int main() | |||
316 | } | 318 | } |
317 | else | 319 | else |
318 | printf("SUCCESS\tGot symbol from global handle: %p\n", function); | 320 | printf("SUCCESS\tGot symbol from global handle: %p\n", function); |
321 | |||
319 | 322 | ||
320 | ret = dlclose( library ); | 323 | ret = dlclose( library ); |
321 | if( ret ) | 324 | if( ret ) |