wix-on-linux/preload.c
Simon Tatham decda92874 Use an LD_PRELOAD library in place of symlink to /home.
Apart from dependency on native-code DLLs, the one other quirk of
running WiX under mono is that it doesn't seem to quite get the right
answers when combining $PWD with a Unix absolute path to one of its
own supporting files - it doesn't interpret the leading slash on the
latter as meaning $PWD should be ignored, so it tries to look for
/home/my/build/dir/home/my/wix/install/dir/some.file. Previously I was
bodging around that by having my build dir contain a symlink 'home'
pointing at /home; this is marginally less intrusive.
2017-05-16 07:03:19 +01:00

42 lines
1.4 KiB
C

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static const char *munge(const char *n) {
static const char *e = NULL;
static size_t elen;
if (!e) {
e = getenv("WIX");
if (!e)
return n;
elen = strlen(e);
}
const char *last_slash = strrchr(n, '/');
if (!last_slash)
return n;
if (last_slash - n > elen && !strncmp(last_slash - elen, e, elen))
return last_slash - elen;
return n;
}
#define dofunc(rettype,sym,proto,proto2) \
rettype sym proto { \
rettype (*real) proto; \
real = dlsym(RTLD_NEXT, #sym); \
fname = munge(fname); \
return real proto2; \
}
dofunc(int,open,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,open64,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,__open,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,__open64,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,stat,(const char *fname,struct stat *sbuf),(fname,sbuf))
dofunc(int,lstat,(const char *fname,struct stat *sbuf),(fname,sbuf))
dofunc(int,access,(const char *fname,int mode),(fname,mode))