confirm results
[tridge/junkcode.git] / fwide.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <dlfcn.h>
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <errno.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <wchar.h>
10
11 FILE *xxfopen1(const char *filename, const char *mode)
12 {
13         FILE *(*fopen_orig)(const char *, const char *);
14         void *dl = dlopen("/lib/libc.so.6", RTLD_NOW);
15         fopen_orig = dlsym(dl, "fopen");
16         printf("fopen: %p  fopen_orig_dlopen: %p\n", fopen, fopen_orig);
17         return fopen_orig(filename, mode);
18 }
19
20 FILE *xxfopen2(const char *filename, const char *mode)
21 {
22         FILE *(*fopen_orig)(const char *, const char *);
23         FILE *(*fopen_orig2)(const char *, const char *);
24         fopen_orig = dlsym(RTLD_NEXT, "fopen");
25         fopen_orig2 = dlsym(RTLD_NEXT, "fopen");
26         printf("fopen: %p  fopen_orig_next: %p %p\n", fopen, fopen_orig, fopen_orig2);
27         return fopen_orig(filename, mode);
28 }
29
30 int main(void)
31 {
32         FILE *f1, *f2, *f3;
33         int ret1, ret2, ret3;
34         char *s;
35         
36         f1 = xxfopen1("test.txt", "w");
37         f2 = xxfopen2("test.txt", "w");
38         f3 = fopen("test.txt", "w");
39         ret1 = fwide(f1, 1);
40         ret2 = fwide(f2, 1);
41         ret3 = fwide(f3, 1);
42
43         printf("f1 %d  f2 %d f3 %d\n", ret1, ret2, ret3);
44
45         asprintf(&s, "cat /proc/%d/maps", getpid());
46         system(s);
47
48         return 0;
49 }