Integrate from mainperl.
[p5sagit/p5-mst-13.2.git] / win32 / runperl.c
index 3947f9e..8cf521d 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"
@@ -37,8 +36,17 @@ 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];
+
+    GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
+    argv[0] = szModuleName;
+#endif
 
-    if(!host.PerlCreate())
+    if (!host.PerlCreate())
        exit(exitstatus);
 
     exitstatus = host.PerlParse(xs_init, argc, argv, NULL);
@@ -74,6 +82,14 @@ __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];
+    GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
+    argv[0] = szModuleName;
+#endif
     return RunPerl(argc, argv, env, (void*)0);
 }