summaryrefslogtreecommitdiffstats
path: root/doc/sources/c
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 17:43:19 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 17:43:19 +0000
commit0292059f4a16434600564cfa3f0ad2309a508a54 (patch)
treed95953cd53011917c4df679b96aedca39401b54f /doc/sources/c
downloadlibksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.tar.gz
libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.zip
Added libksquirrel for KDE3
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'doc/sources/c')
-rwxr-xr-xdoc/sources/c/compile5
-rw-r--r--doc/sources/c/main.c56
-rw-r--r--doc/sources/c/module.c4
3 files changed, 65 insertions, 0 deletions
diff --git a/doc/sources/c/compile b/doc/sources/c/compile
new file mode 100755
index 0000000..9be0fbb
--- /dev/null
+++ b/doc/sources/c/compile
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+gcc -Wall -O2 -fPIC -c module.c
+gcc -shared -o module.so module.o
+gcc -o test main.c -ldl \ No newline at end of file
diff --git a/doc/sources/c/main.c b/doc/sources/c/main.c
new file mode 100644
index 0000000..96d60ad
--- /dev/null
+++ b/doc/sources/c/main.c
@@ -0,0 +1,56 @@
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <dlfcn.h>
+
+#define PATH_LENGTH 256
+
+int main(int argc, char * argv[])
+{
+ char path[PATH_LENGTH], *msg = NULL;
+ const char* (*fmt)();
+ void *module;
+
+ getcwd(path, PATH_LENGTH);
+ strcat(path, "/");
+ strcat(path, "module.so");
+
+ /* Load module */
+ module = dlopen(path, RTLD_NOW);
+
+ /* Error ! */
+ if(!module)
+ {
+ msg = dlerror();
+
+ if(msg != NULL)
+ {
+ dlclose(module);
+ exit(1);
+ }
+ }
+
+ /* Try to resolve function "fmt_info()" */
+ fmt = dlsym(module, "fmt_info");
+
+ msg = dlerror();
+
+ if(msg != NULL)
+ {
+ perror(msg);
+ dlclose(module);
+ exit(1);
+ }
+
+ /* call fmt_info() through a pointer*/
+ printf("%s\n", fmt());
+
+ /* close module */
+ if(dlclose(module))
+ {
+ perror("error");
+ exit(1);
+ }
+
+ return 0;
+}
diff --git a/doc/sources/c/module.c b/doc/sources/c/module.c
new file mode 100644
index 0000000..36c5d2a
--- /dev/null
+++ b/doc/sources/c/module.c
@@ -0,0 +1,4 @@
+const char* fmt_info()
+{
+ return "It is really cool format!";
+}