3 #include <sys/socket.h>
11 int open64(const char *pathname, int flags, ...)
13 typedef int (*FUNC_PTR) (const char* pathname, int flags, ...);
14 static FUNC_PTR libc_open64;
20 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
23 fputs(dlerror(), stderr);
26 libc_open64 = (FUNC_PTR) dlsym(handle, "open64");
27 if ((error = dlerror()) != NULL) {
28 fprintf(stderr, "%s\n", error);
32 fd = libc_open64(pathname, flags);
35 int fd_flags = fcntl(fd, F_GETFD, 0);
38 fd_flags |= FD_CLOEXEC;
39 fcntl(fd, F_SETFD, fd_flags);
42 fprintf(stdout, "open64 %s, flags %d returned fd %d\n", pathname, flags, fd);
48 int open(const char *pathname, int flags, ...)
50 typedef int (*FUNC_PTR) (const char* pathname, int flags, ...);
51 static FUNC_PTR libc_open;
57 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
60 fputs(dlerror(), stderr);
63 libc_open = (FUNC_PTR) dlsym(handle, "open");
64 if ((error = dlerror()) != NULL) {
65 fprintf(stderr, "%s\n", error);
69 fd = libc_open(pathname, flags);
72 int fd_flags = fcntl(fd, F_GETFD, 0);
75 fd_flags |= FD_CLOEXEC;
76 fcntl(fd, F_SETFD, fd_flags);
79 fprintf(stdout, "open %s, flags %d returned fd %d\n", pathname, flags, fd);
85 FILE *fopen64(const char *pathname, const char *mode)
87 typedef FILE *(*FUNC_PTR) (const char* pathname, const char *mode);
88 static FUNC_PTR libc_fopen64;
94 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
97 fputs(dlerror(), stderr);
100 libc_fopen64 = (FUNC_PTR) dlsym(handle, "fopen64");
101 if ((error = dlerror()) != NULL) {
102 fprintf(stderr, "%s\n", error);
106 f = libc_fopen64(pathname, mode);
110 int fd_flags = fcntl(fd, F_GETFD, 0);
113 fd_flags |= FD_CLOEXEC;
114 fcntl(fd, F_SETFD, fd_flags);
117 fprintf(stdout, "fopen64 %s, mode %s returned FILE* %p fd %d\n", pathname, mode, f, fd);
123 FILE *fopen(const char *pathname, const char *mode)
125 typedef FILE *(*FUNC_PTR) (const char* pathname, const char *mode);
126 static FUNC_PTR libc_fopen;
132 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
135 fputs(dlerror(), stderr);
138 libc_fopen = (FUNC_PTR) dlsym(handle, "fopen");
139 if ((error = dlerror()) != NULL) {
140 fprintf(stderr, "%s\n", error);
144 f = libc_fopen(pathname, mode);
148 int fd_flags = fcntl(fd, F_GETFD, 0);
151 fd_flags |= FD_CLOEXEC;
152 fcntl(fd, F_SETFD, fd_flags);
155 fprintf(stdout, "fopen %s, mode %s returned FILE* %p fd %d\n", pathname, mode, f, fd);
161 int socket(int domain, int type, int protocol)
163 typedef int (*FUNC_PTR) (int domain, int type, int protocol);
164 static FUNC_PTR libc_socket;
170 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
173 fputs(dlerror(), stderr);
176 libc_socket = (FUNC_PTR) dlsym(handle, "socket");
177 if ((error = dlerror()) != NULL) {
178 fprintf(stderr, "%s\n", error);
182 fd = libc_socket(domain, type, protocol);
185 int fd_flags = fcntl(fd, F_GETFD, 0);
188 fd_flags |= FD_CLOEXEC;
189 fcntl(fd, F_SETFD, fd_flags);
192 fprintf(stdout, "socket fd %d\n", fd);
198 int pipe(int modus[2])
200 typedef int (*FUNC_PTR) (int modus[2]);
201 static FUNC_PTR libc_pipe;
207 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
210 fputs(dlerror(), stderr);
213 libc_pipe = (FUNC_PTR) dlsym(handle, "pipe");
214 if ((error = dlerror()) != NULL) {
215 fprintf(stderr, "%s\n", error);
219 ret = libc_pipe(modus);
222 int fd_flags = fcntl(modus[0], F_GETFD, 0);
225 fd_flags |= FD_CLOEXEC;
226 fcntl(modus[0], F_SETFD, fd_flags);
228 fd_flags = fcntl(modus[1], F_GETFD, 0);
231 fd_flags |= FD_CLOEXEC;
232 fcntl(modus[1], F_SETFD, fd_flags);
235 fprintf(stdout, "pipe fds[%d, %d]\n", modus[0], modus[1]);