aboutsummaryrefslogtreecommitdiff
path: root/tests/core/c_linkmodes/crypto_test_dl.c
blob: 36e2149546998db88778bc932a61076a34daffae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <dlfcn.h>
#include <stdio.h>

#ifndef SO
#error No SO path defined
#endif

int main() {
  void* handle = dlopen(SO, RTLD_NOW);
  if (!handle) {
    printf("dlopen: %s\n", dlerror());
    return 1;
  }

  typedef void (*gofn_t)();
  gofn_t gofn = (gofn_t)dlsym(handle, "GoFn");
  const char* dlsym_error = dlerror();
  if (dlsym_error) {
    printf("dlsym: %s\n", dlerror());
    dlclose(handle);
    return 1;
  }

  gofn();

  if (dlclose(handle)) {
    printf("dlclose: %s\n", dlerror());
  }
  return 0;
}