Back to index

glibc  2.9
noload.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 
00004 int
00005 main (void)
00006 {
00007   int result = 0;
00008 
00009   /* First try to load an object which is a dependency.  This should
00010      succeed.  */
00011   if (dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
00012     {
00013       printf ("cannot open \"testobj1.so\": %s\n", dlerror ());
00014       result = 1;
00015     }
00016   else
00017     puts ("loading \"testobj1.so\" succeeded, OK");
00018 
00019   /* Now try loading an object which is not already loaded.  */
00020   if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) != NULL)
00021     {
00022       puts ("succeeded in loading \"testobj5.so\"");
00023       result = 1;
00024     }
00025   else
00026     {
00027       /* Load the object and run the same test again.  */
00028       void *p;
00029 
00030       puts ("\"testobj5.so\" wasn't loaded and RTLD_NOLOAD prevented it, OK");
00031 
00032       p = dlopen ("testobj5.so", RTLD_LAZY);
00033 
00034       if (p == NULL)
00035        {
00036          printf ("cannot open \"testobj5.so\" without RTLD_NOLOAD: %s\n",
00037                 dlerror ());
00038          result = 1;
00039        }
00040       else
00041        {
00042          puts ("loading \"testobj5.so\" succeeded, OK");
00043 
00044          if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
00045            {
00046              printf ("cannot open \"testobj5.so\": %s\n", dlerror ());
00047              result = 1;
00048            }
00049          else
00050            puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
00051 
00052          if (dlclose (p) != 0)
00053            {
00054              printf ("cannot close \"testobj5.so\": %s\n", dlerror ());
00055              result = 1;
00056            }
00057          else
00058            puts ("closing \"testobj5.so\" succeeded, OK");
00059        }
00060     }
00061 
00062   return result;
00063 }
00064 
00065 
00066 extern int foo (int a);
00067 int
00068 foo (int a)
00069 {
00070   return 42 + a;
00071 }