summaryrefslogtreecommitdiffstats
path: root/scriptstub.c
blob: de942c136e734ef3abe3ef5ec3e9c566f1f38ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/* Translate call of myself into call of same-named script in LIBDIR */
/* The macro LIBDIR must be defined as a double-quoted string */

int main (int argc, char **argv)
{
  char *basename;
  char *fullname;
  char **newargs;
  int i;

  basename = strrchr(argv[0], '/');
  if (basename)
    basename++;
  else
    basename = argv[0];
  fullname = malloc(strlen(LIBDIR) + strlen(basename) + 2);
  sprintf(fullname, "%s/%s", LIBDIR, basename);
  newargs = malloc((argc+1) * sizeof(char *));
  newargs[0] = fullname;
  for (i = 1; i < argc; i++)
    newargs[i] = argv[i];
  newargs[argc] = NULL;

  execvp(fullname, newargs);

  return 1;
}