Back to index

glibc  2.9
failtest.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 
00004 
00005 /* Number of rounds we perform the test.  */
00006 #define TEST_ROUNDS  10
00007 
00008 
00009 static const char unknown[] = "a-file-with-this-name-does-not-exist";
00010 static const char exists[] = "failtestmod.so";
00011 
00012 
00013 int
00014 main (void)
00015 {
00016   int i;
00017 
00018   setvbuf (stdout, NULL, _IONBF, 0);
00019 
00020   for (i = 0; i < TEST_ROUNDS; ++i)
00021     {
00022       void *dsc;
00023 
00024       printf ("Round %d: Try loading \"%s\"\n", i, unknown);
00025 
00026       dsc = dlopen (unknown, RTLD_NOW);
00027       if (dsc != NULL)
00028        {
00029          printf ("We found a file of name \"%s\": this should not happen\n",
00030                 unknown);
00031          return 1;
00032        }
00033 
00034       printf ("Round %d: loading \"%s\" failed\n", i, unknown);
00035 
00036       /* Don't use `dlerror', just load an existing file.  */
00037       dsc = dlopen (exists, RTLD_NOW);
00038       if (dsc == NULL)
00039        {
00040          printf ("Could not load \"%s\": %s\n", exists, dlerror ());
00041          return 1;
00042        }
00043 
00044       printf ("Round %d: Loaded \"%s\"\n", i, exists);
00045 
00046       dlclose (dsc);
00047 
00048       printf ("Round %d: Unloaded \"%s\"\n", i, exists);
00049     }
00050 
00051   return 0;
00052 }
00053 
00054 
00055 extern void foo (void);
00056 
00057 void
00058 foo (void)
00059 {
00060 }