dlopen-test.c 786 Bytes
Newer Older
1 2 3 4 5 6 7
#include "testutils.h"
#include "version.h"

#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif

8 9 10 11 12 13
#ifdef __APPLE__
#define SO_EXT "dylib"
#else
#define SO_EXT "so"
#endif

14
int
15
main (int argc UNUSED, char **argv UNUSED)
16 17
{
#if HAVE_LIBDL
18
  void *handle = dlopen ("../libnettle." SO_EXT, RTLD_NOW);
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  int (*get_version)(void);
  if (!handle)
    {
      fprintf (stderr, "dlopen failed: %s\n", dlerror());
      FAIL ();
    }

  get_version = (int(*)(void)) dlsym (handle, "nettle_version_minor");
  if (!get_version)
    {
      fprintf (stderr, "dlsym failed: %s\n", dlerror());
      FAIL ();
    }
  if (get_version() != NETTLE_VERSION_MINOR)
    {
      fprintf (stderr, "unexpected nettle version\n");
      FAIL ();
    }
37
  dlclose (handle);
38 39 40 41 42
  return EXIT_SUCCESS;
#else
  SKIP();
#endif
}