Back to index

glibc  2.9
glrefmain.c
Go to the documentation of this file.
00001 /* Test for dependency tracking  added by relocations.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <dlfcn.h>
00021 #include <error.h>
00022 #include <errno.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 
00026 
00027 static void *
00028 load (const char *name)
00029 {
00030   void *d = dlopen (name, RTLD_LAZY | RTLD_GLOBAL);
00031   if (d == NULL)
00032     error (EXIT_FAILURE, errno, "cannot load `%s'", name);
00033   return d;
00034 }
00035 
00036 
00037 #define TEST_FUNCTION do_test ()
00038 extern int do_test (void);
00039 
00040 int
00041 do_test (void)
00042 {
00043   void *d1;
00044   void *d2;
00045   int (*f) (void);
00046 
00047   d1 = load ("glreflib1.so");
00048   d2 = load ("glreflib2.so");
00049 
00050   f = dlsym (d2, "ref2");
00051   if (f == NULL)
00052     error (EXIT_FAILURE, errno, "cannot get pointer to `%s'", "ref2");
00053 
00054   if (f () != 42)
00055     error (EXIT_FAILURE, 0, "wrong result from `%s'", "ref2");
00056 
00057   puts ("Correct result in first call");
00058   fflush (stdout);
00059 
00060   /* Now unload the first file.  */
00061   dlclose (d1);
00062 
00063   puts ("About to call the second time");
00064   fflush (stdout);
00065 
00066   /* Try calling the function again.  */
00067   if (f () != 42)
00068     error (EXIT_FAILURE, 0, "wrong result from `%s' (second call)", "ref2");
00069 
00070   puts ("Second call succeeded!");
00071   fflush (stdout);
00072 
00073   dlclose (d2);
00074 
00075   puts ("glreflib2 also closed");
00076   fflush (stdout);
00077 
00078   return 0;
00079 }
00080 
00081 #include "../test-skeleton.c"