#include #include #include void *handle = NULL; #if 0 # define DLCLOSE_ATEXIT 1 #endif #ifdef DLCLOSE_ATEXIT static void dlclose_atexit(void) { if (dlclose(handle) != 0) { fprintf(stderr, "dlclose fail : %s\n", dlerror()); } } #endif int main() { handle = dlopen("libz.so", RTLD_LAZY | RTLD_NOW); if (handle == NULL) { fprintf(stderr, "dlopen fail : %s\n", dlerror()); return 1; } #ifndef DLCLOSE_ATEXIT if (dlclose(handle) != 0) { fprintf(stderr, "dlclose fail : %s\n", dlerror()); return 2; } #else if (atexit(dlclose_atexit) != 0) { fprintf(stderr, "atexit fail\n"); return 3; } #endif printf("exit with code 33\n"); return 33; }