Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
forgot the test file
[simgrid.git] / buildtools / Cmake / test_prog / prog_gnu_dynlinker.c
1 /* prog_gnu_dynlinker.c -- check that RTLD_NEXT is defined as in GNU linker */
2 /* Copyright (c) 2012. The SimGrid Team. All rights reserved.               */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #define _GNU_SOURCE 1
8 #include <dlfcn.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12
13 static void * (*real_malloc) (size_t);
14
15 int main(void) {
16    char *error;
17    dlerror(); // clear any previous error
18    real_malloc = (void * (*) (size_t)) dlsym(RTLD_NEXT, "malloc");
19    error = dlerror();
20    if (!error && real_malloc) {
21       char *A = real_malloc(20);
22       strcpy(A,"epic success");
23       free(A);
24       return 0; // SUCCESS
25    } else {
26       if (error)
27          printf("Error while checking for dlsym: %s\n",error);
28       else
29          printf("dlsym did not return any error, but failed to find malloc()\n",error);
30       return 1; // FAILED
31    }
32 }