more testsuite smarts (many of them courtesy Ilya)
[p5sagit/p5-mst-13.2.git] / win32 / runperl.c
index 3947f9e..336f2a8 100644 (file)
@@ -1,9 +1,8 @@
-
-#ifdef PERL_OBJECT
-#define USE_SOCKETS_AS_HANDLES
 #include "EXTERN.h"
 #include "perl.h"
 
+#ifdef PERL_OBJECT
+
 #define NO_XSLOCKS
 #include "XSUB.H"
 #include "win32iop.h"
@@ -29,16 +28,26 @@ xs_init(CPERLarg)
 
 CPerlObj *pPerl;
 
-#undef PERL_SYS_INIT
-#define PERL_SYS_INIT(a, c)
-
 int
 main(int argc, char **argv, char **env)
 {
     CPerlHost host;
     int exitstatus = 1;
+#ifndef __BORLANDC__
+    /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
+     * want to free() argv after main() returns.  As luck would have it,
+     * Borland's CRT does the right thing to argv[0] already. */
+    char szModuleName[MAX_PATH];
+    char *ptr;
+
+    GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
+    (void)win32_longpath(szModuleName);
+    argv[0] = szModuleName;
+#endif
 
-    if(!host.PerlCreate())
+    PERL_SYS_INIT(&argc,&argv);
+
+    if (!host.PerlCreate())
        exit(exitstatus);
 
     exitstatus = host.PerlParse(xs_init, argc, argv, NULL);
@@ -74,6 +83,17 @@ __declspec(dllimport) int RunPerl(int argc, char **argv, char **env, void *ios);
 int
 main(int argc, char **argv, char **env)
 {
+#ifndef __BORLANDC__
+    /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
+     * want to free() argv after main() returns.  As luck would have it,
+     * Borland's CRT does the right thing to argv[0] already. */
+    char szModuleName[MAX_PATH];
+    char *ptr;
+
+    GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
+    (void)win32_longpath(szModuleName);
+    argv[0] = szModuleName;
+#endif
     return RunPerl(argc, argv, env, (void*)0);
 }