Ruby  2.0.0p247(2013-06-27revision41674)
win32/stub.c
Go to the documentation of this file.
00001 #include <ruby.h>
00002 static void stub_sysinit(int *argc, char ***argv);
00003 #define ruby_sysinit stub_sysinit
00004 #include <main.c>
00005 #undef ruby_sysinit
00006 
00007 void
00008 stub_sysinit(int *argc, char ***argv)
00009 {
00010     char exename[4096];
00011     size_t lenexe, len0, lenall;
00012     int i, ac;
00013     char **av, *p;
00014 
00015     lenexe = (size_t)GetModuleFileName(NULL, exename, sizeof exename);
00016     ruby_sysinit(argc, argv);
00017     ac = *argc;
00018     av = *argv;
00019     len0 = strlen(av[0]) + 1;
00020     lenall = 0;
00021     for (i = 1; i < ac; ++i) {
00022         lenall += strlen(av[i]) + 1;
00023     }
00024     *argv = av = realloc(av, lenall + (lenexe + 1) * 2 + sizeof(char *) * (i + 2));
00025     *argc = ++ac;
00026     p = (char *)(av + i + 2);
00027     memmove(p + (lenexe + 1) * 2, (char *)(av + ac) + len0, lenall);
00028     memcpy(p, exename, lenexe);
00029     p[lenexe] = '\0';
00030     *av++ = p;
00031     p += lenexe + 1;
00032     memcpy(p, exename, lenexe);
00033     p[lenexe] = '\0';
00034     *av++ = p;
00035     p += lenexe + 1;
00036     while (--i) {
00037         *av++ = p;
00038         p += strlen(p) + 1;
00039     }
00040     *av = NULL;
00041 }
00042 
00043