aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/test.c b/test.c
index d6280e4..878694e 100644
--- a/test.c
+++ b/test.c
@@ -31,7 +31,8 @@
31#define CLOSE_LIB dlclose( library ) 31#define CLOSE_LIB dlclose( library )
32#define CLOSE_GLOBAL dlclose( global ) 32#define CLOSE_GLOBAL dlclose( global )
33 33
34#define RETURN_ERROR return 1 34#define RETURN_ERROR printf("From line %d\n", __LINE__); return 1
35
35#define RUNFUNC do { \ 36#define RUNFUNC do { \
36 ret = function (); \ 37 ret = function (); \
37 if( ret != 0) { \ 38 if( ret != 0) { \
@@ -73,6 +74,7 @@ int main()
73 void *library; 74 void *library;
74 char *error; 75 char *error;
75 int (*function)( void ); 76 int (*function)( void );
77 int (*printf_local)( const char * );
76 int (*nonexistentfunction)( void ); 78 int (*nonexistentfunction)( void );
77 int ret; 79 int ret;
78 80
@@ -106,6 +108,20 @@ int main()
106 else 108 else
107 printf( "SUCCESS\tGot global handle: %p\n", global ); 109 printf( "SUCCESS\tGot global handle: %p\n", global );
108 110
111 printf_local = dlsym(global, "printf");
112 if (!printf_local)
113 {
114 error = dlerror();
115 printf("ERROR\tCould not get symbol from global handle: %s\n",
116 error ? error : "");
117 CLOSE_LIB;
118 CLOSE_GLOBAL;
119 RETURN_ERROR;
120 }
121 else
122 printf("SUCCESS\tGot symbol from global handle: %p\n", printf_local);
123 printf_local("Hello world from local printf!\n");
124
109 function = dlsym( library, "function" ); 125 function = dlsym( library, "function" );
110 if( !function ) 126 if( !function )
111 { 127 {
@@ -288,6 +304,19 @@ int main()
288 error ? error : "" ); 304 error ? error : "" );
289 } 305 }
290 306
307 function = dlsym(global, "printf");
308 if (!function)
309 {
310 error = dlerror();
311 printf("ERROR\tCould not get symbol from global handle: %s\n",
312 error ? error : "");
313 CLOSE_LIB;
314 CLOSE_GLOBAL;
315 RETURN_ERROR;
316 }
317 else
318 printf("SUCCESS\tGot symbol from global handle: %p\n", function);
319
291 ret = dlclose( library ); 320 ret = dlclose( library );
292 if( ret ) 321 if( ret )
293 { 322 {