aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.wixfakelibs4
-rw-r--r--preload.c42
2 files changed, 45 insertions, 1 deletions
diff --git a/Makefile.wixfakelibs b/Makefile.wixfakelibs
index f53c539..6cce710 100644
--- a/Makefile.wixfakelibs
+++ b/Makefile.wixfakelibs
@@ -2,7 +2,7 @@
2 2
3.SUFFIXES: .c .lo .la 3.SUFFIXES: .c .lo .la
4 4
5all: libwinterop.so.la libmsi.so.la 5all: libwinterop.so.la libmsi.so.la libpreload.la
6 6
7%.la: 7%.la:
8 libtool --mode=link gcc -o $@ $^ -rpath /usr/local/lib 8 libtool --mode=link gcc -o $@ $^ -rpath /usr/local/lib
@@ -14,6 +14,8 @@ libwinterop.so.la: fake-winterop.lo fake-lib.lo
14 14
15libmsi.so.la: fake-msi.lo fake-lib.lo 15libmsi.so.la: fake-msi.lo fake-lib.lo
16 16
17libpreload.la: preload.lo
18
17clean: 19clean:
18 rm -rf .libs 20 rm -rf .libs
19 rm -f *.o *.lo *.la 21 rm -f *.o *.lo *.la
diff --git a/preload.c b/preload.c
new file mode 100644
index 0000000..1665515
--- /dev/null
+++ b/preload.c
@@ -0,0 +1,42 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <dlfcn.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <unistd.h>
9
10static const char *munge(const char *n) {
11 static const char *e = NULL;
12 static size_t elen;
13 if (!e) {
14 e = getenv("WIX");
15 if (!e)
16 return n;
17 elen = strlen(e);
18 }
19
20 const char *last_slash = strrchr(n, '/');
21 if (!last_slash)
22 return n;
23 if (last_slash - n > elen && !strncmp(last_slash - elen, e, elen))
24 return last_slash - elen;
25 return n;
26}
27
28#define dofunc(rettype,sym,proto,proto2) \
29 rettype sym proto { \
30 rettype (*real) proto; \
31 real = dlsym(RTLD_NEXT, #sym); \
32 fname = munge(fname); \
33 return real proto2; \
34 }
35
36dofunc(int,open,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
37dofunc(int,open64,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
38dofunc(int,__open,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
39dofunc(int,__open64,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
40dofunc(int,stat,(const char *fname,struct stat *sbuf),(fname,sbuf))
41dofunc(int,lstat,(const char *fname,struct stat *sbuf),(fname,sbuf))
42dofunc(int,access,(const char *fname,int mode),(fname,mode))