1#include <ruby.h> 2static void stub_sysinit(int *argc, char ***argv); 3#define ruby_sysinit stub_sysinit 4#include <main.c> 5#undef ruby_sysinit 6 7void 8stub_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 43