Blame dlfcn/defaultmod2.c

Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
Packit 6c4009
extern int found_in_mod1 (void);
Packit 6c4009
int
Packit 6c4009
found_in_mod1 (void)
Packit 6c4009
{
Packit 6c4009
  return 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
extern int found_in_mod2 (void);
Packit 6c4009
int
Packit 6c4009
found_in_mod2 (void)
Packit 6c4009
{
Packit 6c4009
  return 2;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
extern int test_in_mod2 (int (*mainp)(int, char **));
Packit 6c4009
int
Packit 6c4009
test_in_mod2 (int (*mainp)(int, char **))
Packit 6c4009
{
Packit 6c4009
  int (*ifp) (void);
Packit 6c4009
  void *p;
Packit 6c4009
  int result = 0;
Packit 6c4009
Packit 6c4009
  /* Find function `main'.  */
Packit 6c4009
  p = dlsym (RTLD_DEFAULT, "main");
Packit 6c4009
  if (p == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s: main not found\n", __FILE__);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else if ((int (*)(int, char **))p != mainp)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s: wrong address returned for main\n", __FILE__);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    printf ("%s: main correctly found\n", __FILE__);
Packit 6c4009
Packit 6c4009
  ifp = dlsym (RTLD_DEFAULT, "found_in_mod1");
Packit 6c4009
  if ((void *) ifp == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s: found_in_mod1 not found\n", __FILE__);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else if (ifp () != 1)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s: wrong address returned for found_in_mod1\n", __FILE__);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    printf ("%s: found_in_mod1 correctly found\n", __FILE__);
Packit 6c4009
Packit 6c4009
  ifp = dlsym (RTLD_DEFAULT, "found_in_mod2");
Packit 6c4009
  if ((void *) ifp == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s: found_in_mod2 not found\n", __FILE__);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else if (ifp () != 2)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s: wrong address returned for found_in_mod2\n", __FILE__);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    printf ("%s: found_in_mod2 correctly found\n", __FILE__);
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}