]> pd.if.org Git - lice/blobdiff - tests/dl.c
autocommit for files dated 2014-11-17 20:13:34
[lice] / tests / dl.c
diff --git a/tests/dl.c b/tests/dl.c
new file mode 100644 (file)
index 0000000..80a9fc4
--- /dev/null
@@ -0,0 +1,30 @@
+// dynamic loading
+#include <stddef.h>
+
+// should be good for the next ten thousand years :P
+#define SOMAX 128
+
+int main(void) {
+    int so = 0;
+    char buffer[32];
+    void *handle = dlopen("libc.so", 1);
+
+    if (!handle) {
+        for (so = 0; so < SOMAX; so++) {
+            snprintf(buffer, sizeof(buffer), "libc.so.%d", so);
+            if ((handle = dlopen(buffer, 1)))
+                break;
+        }
+    }
+
+    if (!handle) {
+        printf("failed to load libc\n");
+        return 1;
+    }
+
+    // test must return 0 to succeed
+    int (*a)(int) = dlsym(handle, "exit");
+    a(0);
+
+    return 1;
+}