Back to index

glibc  2.9
tst-tls5.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 #include <tls.h>
00006 
00007 
00008 #define TEST_FUNCTION do_test ()
00009 static int
00010 do_test (void)
00011 {
00012   static const char modname[] = "tst-tlsmod2.so";
00013   int result = 0;
00014   int *foop;
00015   int *foop2;
00016   int (*fp) (int, int *);
00017   void *h;
00018 
00019   h = dlopen (modname, RTLD_LAZY);
00020   if (h == NULL)
00021     {
00022       printf ("cannot open '%s': %s\n", modname, dlerror ());
00023       exit (1);
00024     }
00025 
00026   foop = dlsym (h, "foo");
00027   if (foop == NULL)
00028     {
00029       printf ("cannot get symbol 'foo': %s\n", dlerror ());
00030       exit (1);
00031     }
00032 
00033   *foop = 42;
00034 
00035   fp = dlsym (h, "in_dso");
00036   if (fp == NULL)
00037     {
00038       printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
00039       exit (1);
00040     }
00041 
00042   result |= fp (42, foop);
00043 
00044   foop2 = dlsym (h, "foo");
00045   if (foop2 == NULL)
00046     {
00047       printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
00048       exit (1);
00049     }
00050 
00051   if (foop != foop2)
00052     {
00053       puts ("address of 'foo' different the second time");
00054       result = 1;
00055     }
00056   else if (*foop != 16)
00057     {
00058       puts ("foo != 16");
00059       result = 1;
00060     }
00061 
00062   dlclose (h);
00063 
00064   return result;
00065 }
00066 
00067 
00068 #include "../test-skeleton.c"