nixpkgs/pkgs/applications/networking/browsers/mozilla-plugins/google-talk-plugin/preload.c
Eelco Dolstra 63bf8c3a0d * Support the 32-bit version of the Google Talk plugin.
svn path=/nixpkgs/trunk/; revision=33533
2012-04-02 09:59:25 +00:00

32 lines
949 B
C

/* Google Talk Plugin executes a helper program in /opt. This
LD_PRELOAD library intercepts execvp() calls to redirect them to
the corresponding location in $out. */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
char origDir [] = "/opt/google/talkplugin/GoogleTalkPlugin";
char realDir [] = OUT "/libexec/google/talkplugin/GoogleTalkPlugin";
const char * rewrite(const char * path, char * buf)
{
if (strncmp(path, origDir, sizeof(origDir) - 1) != 0) return path;
if (snprintf(buf, PATH_MAX, "%s%s", realDir, path + sizeof(origDir) - 1) >= PATH_MAX)
abort();
return buf;
}
int execvp(const char * path, char * const argv[])
{
int (*_execvp) (const char *, char * const argv[]) = dlsym(RTLD_NEXT, "execvp");
char buf[PATH_MAX];
return _execvp(rewrite(path, buf), argv);
}