4 #include <sys/socket.h>
12 int open64(const char *pathname, int flags, ...)
14 static int (*libc_open64) (const char* pathname, int flags, ...);
20 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
23 fputs(dlerror(), stderr);
26 libc_open64 = 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 static int (*libc_open) (const char* pathname, int flags, ...);
56 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
59 fputs(dlerror(), stderr);
62 libc_open = dlsym(handle, "open");
63 if ((error = dlerror()) != NULL) {
64 fprintf(stderr, "%s\n", error);
68 fd = libc_open(pathname, flags);
71 int fd_flags = fcntl(fd, F_GETFD, 0);
74 fd_flags |= FD_CLOEXEC;
75 fcntl(fd, F_SETFD, fd_flags);
78 fprintf(stdout, "open %s, flags %d returned fd %d\n", pathname, flags, fd);
84 FILE *fopen64(const char *pathname, const char *mode)
86 static FILE *(*libc_fopen64) (const char* pathname, const char *mode);
92 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
95 fputs(dlerror(), stderr);
98 libc_fopen64 = dlsym(handle, "fopen64");
99 if ((error = dlerror()) != NULL) {
100 fprintf(stderr, "%s\n", error);
104 f = libc_fopen64(pathname, mode);
108 int fd_flags = fcntl(fd, F_GETFD, 0);
111 fd_flags |= FD_CLOEXEC;
112 fcntl(fd, F_SETFD, fd_flags);
115 fprintf(stdout, "fopen64 %s, mode %s returned FILE* %p fd %d\n", pathname, mode, f, fd);
121 FILE *fopen(const char *pathname, const char *mode)
123 static FILE *(*libc_fopen) (const char* pathname, const char *mode);
129 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
132 fputs(dlerror(), stderr);
135 libc_fopen = dlsym(handle, "fopen");
136 if ((error = dlerror()) != NULL) {
137 fprintf(stderr, "%s\n", error);
141 f = libc_fopen(pathname, mode);
145 int fd_flags = fcntl(fd, F_GETFD, 0);
148 fd_flags |= FD_CLOEXEC;
149 fcntl(fd, F_SETFD, fd_flags);
152 fprintf(stdout, "fopen %s, mode %s returned FILE* %p fd %d\n", pathname, mode, f, fd);
158 int socket(int domain, int type, int protocol)
160 static int (*libc_socket) (int domain, int type, int protocol);
166 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
169 fputs(dlerror(), stderr);
172 libc_socket = dlsym(handle, "socket");
173 if ((error = dlerror()) != NULL) {
174 fprintf(stderr, "%s\n", error);
178 fd = libc_socket(domain, type, protocol);
181 int fd_flags = fcntl(fd, F_GETFD, 0);
184 fd_flags |= FD_CLOEXEC;
185 fcntl(fd, F_SETFD, fd_flags);
188 fprintf(stdout, "socket fd %d\n", fd);
194 int pipe(int modus[2])
196 static int (*libc_pipe) (int modus[2]);
202 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
205 fputs(dlerror(), stderr);
208 libc_pipe = dlsym(handle, "pipe");
209 if ((error = dlerror()) != NULL) {
210 fprintf(stderr, "%s\n", error);
214 ret = libc_pipe(modus);
217 int fd_flags = fcntl(modus[0], F_GETFD, 0);
220 fd_flags |= FD_CLOEXEC;
221 fcntl(modus[0], F_SETFD, fd_flags);
223 fd_flags = fcntl(modus[1], F_GETFD, 0);
226 fd_flags |= FD_CLOEXEC;
227 fcntl(modus[1], F_SETFD, fd_flags);
230 fprintf(stdout, "pipe fds[%d, %d]\n", modus[0], modus[1]);