X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=tools%2Flibopen.c;h=f6b935ee5d15ddf2853718f5ddcee7fbc4017a1a;hp=b3b5dce7a5a0ab25f660740f1c73291f0c2bafb6;hb=e9f6e4e8facac1243a8bbc93c704e4f2d1a28cc7;hpb=b001c3168f53cb99a5faeb9adc8b0af75013bb4d diff --git a/tools/libopen.c b/tools/libopen.c index b3b5dce..f6b935e 100644 --- a/tools/libopen.c +++ b/tools/libopen.c @@ -45,6 +45,7 @@ int open64(const char *pathname, int flags, ...) return fd; } +#if _FILE_OFFSET_BITS != 64 int open(const char *pathname, int flags, ...) { typedef int (*FUNC_PTR) (const char* pathname, int flags, ...); @@ -81,6 +82,7 @@ int open(const char *pathname, int flags, ...) } return fd; } +#endif FILE *fopen64(const char *pathname, const char *mode) { @@ -120,6 +122,7 @@ FILE *fopen64(const char *pathname, const char *mode) return f; } +#if _FILE_OFFSET_BITS != 64 FILE *fopen(const char *pathname, const char *mode) { typedef FILE *(*FUNC_PTR) (const char* pathname, const char *mode); @@ -157,6 +160,7 @@ FILE *fopen(const char *pathname, const char *mode) } return f; } +#endif int socket(int domain, int type, int protocol) { @@ -195,6 +199,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]);