From cd27689181969c3144dbf4ec17f8ec90d7b04bd0 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Wed, 22 Jan 2014 04:24:38 +0000 Subject: test.c: return 1 if error --- test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test.c b/test.c index f45a5be..e278c55 100644 --- a/test.c +++ b/test.c @@ -20,6 +20,13 @@ #include #include "dlfcn.h" +/* If these dlclose's fails, we don't care as the handles are going to be + closed eventually when the program ends. */ +#define CLOSE_LIB dlclose( library ); +#define CLOSE_GLOBAL dlclose( global ); + +#define RETURN_ERROR return 1; + /* This is what this test does: * - Open library with RTLD_GLOBAL * - Get global object @@ -61,6 +68,8 @@ int main() { error = dlerror( ); printf( "Could not open global handle: %s\n", error ? error : "" ); + CLOSE_LIB + RETURN_ERROR } else printf( "Got global handle: %p\n", global ); @@ -71,6 +80,9 @@ int main() error = dlerror( ); printf( "Could not get symbol from library handle: %s\n", error ? error : "" ); + CLOSE_LIB + CLOSE_GLOBAL + RETURN_ERROR } else printf( "Got symbol from library handle: %p\n", function ); @@ -84,6 +96,9 @@ int main() error = dlerror( ); printf( "Could not get symbol from global handle: %s\n", error ? error : "" ); + CLOSE_LIB + CLOSE_GLOBAL + RETURN_ERROR } else printf( "Got symbol from global handle: %p\n", function ); @@ -105,6 +120,9 @@ int main() { error = dlerror( ); printf( "Could not open library locally: %s\n", error ? error : "" ); + CLOSE_LIB + CLOSE_GLOBAL + RETURN_ERROR } else printf( "Opened library locally: %p\n", library ); @@ -115,6 +133,9 @@ int main() error = dlerror( ); printf( "Could not get symbol from library handle: %s\n", error ? error : "" ); + CLOSE_LIB + CLOSE_GLOBAL + RETURN_ERROR } else printf( "Got symbol from library handle: %p\n", function ); @@ -128,6 +149,9 @@ int main() error = dlerror( ); printf( "Could not get symbol from global handle: %s\n", error ? error : "" ); + CLOSE_LIB + CLOSE_GLOBAL + RETURN_ERROR } else printf( "Got symbol from global handle: %p\n", function ); @@ -140,6 +164,8 @@ int main() { error = dlerror( ); printf( "Could not close library: %s\n", error ? error : "" ); + CLOSE_GLOBAL + RETURN_ERROR } else printf( "Closed library.\n" ); @@ -149,6 +175,7 @@ int main() { error = dlerror( ); printf( "Could not close global handle: %s\n", error ? error : "" ); + RETURN_ERROR } else printf( "Closed global handle.\n" ); -- cgit v1.2.3-55-g6feb