Ruby  2.0.0p594(2014-10-27revision48167)
stub.c
Go to the documentation of this file.
1 #include <ruby.h>
2 static void stub_sysinit(int *argc, char ***argv);
3 #define ruby_sysinit stub_sysinit
4 #include <main.c>
5 #undef ruby_sysinit
6 
7 void
8 stub_sysinit(int *argc, char ***argv)
9 {
10  char exename[4096];
11  size_t lenexe, len0, lenall;
12  int i, ac;
13  char **av, *p;
14 
15  lenexe = (size_t)GetModuleFileName(NULL, exename, sizeof exename);
16  ruby_sysinit(argc, argv);
17  ac = *argc;
18  av = *argv;
19  len0 = strlen(av[0]) + 1;
20  lenall = 0;
21  for (i = 1; i < ac; ++i) {
22  lenall += strlen(av[i]) + 1;
23  }
24  *argv = av = realloc(av, lenall + (lenexe + 1) * 2 + sizeof(char *) * (i + 2));
25  *argc = ++ac;
26  p = (char *)(av + i + 2);
27  memmove(p + (lenexe + 1) * 2, (char *)(av + ac) + len0, lenall);
28  memcpy(p, exename, lenexe);
29  p[lenexe] = '\0';
30  *av++ = p;
31  p += lenexe + 1;
32  memcpy(p, exename, lenexe);
33  p[lenexe] = '\0';
34  *av++ = p;
35  p += lenexe + 1;
36  while (--i) {
37  *av++ = p;
38  p += strlen(p) + 1;
39  }
40  *av = NULL;
41 }
42 
size_t strlen(const char *)
Win32OLEIDispatch * p
Definition: win32ole.c:786
ssize_t i
Definition: bigdecimal.c:5676
RUBY_EXTERN void * memmove(void *, const void *, size_t)
Definition: memmove.c:7
void * realloc()
static void stub_sysinit(int *argc, char ***argv)
Definition: stub.c:8
VALUE * argv
Definition: tcltklib.c:1970
memcpy(buf+1, str, len)
#define ruby_sysinit
Definition: stub.c:3
int argc
Definition: tcltklib.c:1969
char ** av
Definition: tcltklib.c:8851
#define NULL
Definition: _sdbm.c:103