aboutsummaryrefslogtreecommitdiff
path: root/tools/libopen.c
diff options
context:
space:
mode:
authorghost <andreas.monzner@multimedia-labs.de>2009-05-28 15:06:12 +0200
committerghost <andreas.monzner@multimedia-labs.de>2009-05-28 15:06:12 +0200
commitda9ff2d4793dd5c6ab21763b3c4189ff2d4ab972 (patch)
tree76615766414edbe677be613234f2733eb8769200 /tools/libopen.c
parent13b86c205e12d0237a8134e25b2d5e145ac01730 (diff)
downloadenigma2-da9ff2d4793dd5c6ab21763b3c4189ff2d4ab972.tar.gz
enigma2-da9ff2d4793dd5c6ab21763b3c4189ff2d4ab972.zip
tools/libopen.c: add socketpair
Diffstat (limited to 'tools/libopen.c')
-rw-r--r--tools/libopen.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/libopen.c b/tools/libopen.c
index b3b5dce7..a3ae07cd 100644
--- a/tools/libopen.c
+++ b/tools/libopen.c
@@ -195,6 +195,49 @@ int socket(int domain, int type, int protocol)
return fd;
}
+int socketpair(int d, int type, int protocol, int sv[2])
+{
+ typedef int (*FUNC_PTR) (int d, int type, int protocol, int sv[2]);
+ static FUNC_PTR libc_socketpair;
+ int ret=-1;
+ if (!libc_socketpair)
+ {
+ void *handle;
+ char *error;
+ handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
+ if (!handle)
+ {
+ fputs(dlerror(), stderr);
+ exit(1);
+ }
+ libc_socketpair = (FUNC_PTR) dlsym(handle, "socketpair");
+ if ((error = dlerror()) != NULL) {
+ fprintf(stderr, "%s\n", error);
+ exit(1);
+ }
+ }
+ ret = libc_socketpair(d, type, protocol, sv);
+ if (!ret)
+ {
+ int fd_flags = fcntl(sv[0], F_GETFD, 0);
+ if (fd_flags >= 0)
+ {
+ fd_flags |= FD_CLOEXEC;
+ fcntl(sv[0], F_SETFD, fd_flags);
+ }
+ fd_flags = fcntl(sv[1], F_GETFD, 0);
+ if (fd_flags >= 0)
+ {
+ fd_flags |= FD_CLOEXEC;
+ fcntl(sv[1], F_SETFD, fd_flags);
+ }
+#ifdef DEBUG
+ fprintf(stdout, "socketpair fd %d %d\n", sv[0], sv[1]);
+#endif
+ }
+ return ret;
+}
+
int pipe(int modus[2])
{
typedef int (*FUNC_PTR) (int modus[2]);