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 #if _FILE_OFFSET_BITS != 64
49 int open(const char *pathname, int flags, ...)
51 typedef int (*FUNC_PTR) (const char* pathname, int flags, ...);
52 static FUNC_PTR libc_open;
58 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
61 fputs(dlerror(), stderr);
64 libc_open = (FUNC_PTR) dlsym(handle, "open");
65 if ((error = dlerror()) != NULL) {
66 fprintf(stderr, "%s\n", error);
70 fd = libc_open(pathname, flags);
73 int fd_flags = fcntl(fd, F_GETFD, 0);
76 fd_flags |= FD_CLOEXEC;
77 fcntl(fd, F_SETFD, fd_flags);
80 fprintf(stdout, "open %s, flags %d returned fd %d\n", pathname, flags, fd);
87 FILE *fopen64(const char *pathname, const char *mode)
89 typedef FILE *(*FUNC_PTR) (const char* pathname, const char *mode);
90 static FUNC_PTR libc_fopen64;
96 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
99 fputs(dlerror(), stderr);
102 libc_fopen64 = (FUNC_PTR) dlsym(handle, "fopen64");
103 if ((error = dlerror()) != NULL) {
104 fprintf(stderr, "%s\n", error);
108 f = libc_fopen64(pathname, mode);
112 int fd_flags = fcntl(fd, F_GETFD, 0);
115 fd_flags |= FD_CLOEXEC;
116 fcntl(fd, F_SETFD, fd_flags);
119 fprintf(stdout, "fopen64 %s, mode %s returned FILE* %p fd %d\n", pathname, mode, f, fd);
125 #if _FILE_OFFSET_BITS != 64
126 FILE *fopen(const char *pathname, const char *mode)
128 typedef FILE *(*FUNC_PTR) (const char* pathname, const char *mode);
129 static FUNC_PTR libc_fopen;
135 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
138 fputs(dlerror(), stderr);
141 libc_fopen = (FUNC_PTR) dlsym(handle, "fopen");
142 if ((error = dlerror()) != NULL) {
143 fprintf(stderr, "%s\n", error);
147 f = libc_fopen(pathname, mode);
151 int fd_flags = fcntl(fd, F_GETFD, 0);
154 fd_flags |= FD_CLOEXEC;
155 fcntl(fd, F_SETFD, fd_flags);
158 fprintf(stdout, "fopen %s, mode %s returned FILE* %p fd %d\n", pathname, mode, f, fd);
165 int socket(int domain, int type, int protocol)
167 typedef int (*FUNC_PTR) (int domain, int type, int protocol);
168 static FUNC_PTR libc_socket;
174 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
177 fputs(dlerror(), stderr);
180 libc_socket = (FUNC_PTR) dlsym(handle, "socket");
181 if ((error = dlerror()) != NULL) {
182 fprintf(stderr, "%s\n", error);
186 fd = libc_socket(domain, type, protocol);
189 int fd_flags = fcntl(fd, F_GETFD, 0);
192 fd_flags |= FD_CLOEXEC;
193 fcntl(fd, F_SETFD, fd_flags);
196 fprintf(stdout, "socket fd %d\n", fd);
202 int socketpair(int d, int type, int protocol, int sv[2])
204 typedef int (*FUNC_PTR) (int d, int type, int protocol, int sv[2]);
205 static FUNC_PTR libc_socketpair;
207 if (!libc_socketpair)
211 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
214 fputs(dlerror(), stderr);
217 libc_socketpair = (FUNC_PTR) dlsym(handle, "socketpair");
218 if ((error = dlerror()) != NULL) {
219 fprintf(stderr, "%s\n", error);
223 ret = libc_socketpair(d, type, protocol, sv);
226 int fd_flags = fcntl(sv[0], F_GETFD, 0);
229 fd_flags |= FD_CLOEXEC;
230 fcntl(sv[0], F_SETFD, fd_flags);
232 fd_flags = fcntl(sv[1], F_GETFD, 0);
235 fd_flags |= FD_CLOEXEC;
236 fcntl(sv[1], F_SETFD, fd_flags);
239 fprintf(stdout, "socketpair fd %d %d\n", sv[0], sv[1]);
245 int pipe(int modus[2])
247 typedef int (*FUNC_PTR) (int modus[2]);
248 static FUNC_PTR libc_pipe;
254 handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
257 fputs(dlerror(), stderr);
260 libc_pipe = (FUNC_PTR) dlsym(handle, "pipe");
261 if ((error = dlerror()) != NULL) {
262 fprintf(stderr, "%s\n", error);
266 ret = libc_pipe(modus);
269 int fd_flags = fcntl(modus[0], F_GETFD, 0);
272 fd_flags |= FD_CLOEXEC;
273 fcntl(modus[0], F_SETFD, fd_flags);
275 fd_flags = fcntl(modus[1], F_GETFD, 0);
278 fd_flags |= FD_CLOEXEC;
279 fcntl(modus[1], F_SETFD, fd_flags);
282 fprintf(stdout, "pipe fds[%d, %d]\n", modus[0], modus[1]);