develooper Front page | perl.perl5.porters | Postings from January 2006

Why doesn't $^E work with Borland builds on Win32?

Thread Next
Steve Hay
January 30, 2006 09:34
Why doesn't $^E work with Borland builds on Win32?
Message ID:
I have a problem with a Borland build of perl on Win32 not setting $^E, 

 >perl -e "open F, 'nothere' or die $^E"
Died at -e line 1.

whereas a VC++ build says:

 >perl -e "open F, 'nothere' or die $^E"
The system cannot find the file specified at -e line 1.

Looking at Perl_magic_get() in mg.c, it appears that getting $^E 
actually calls GetLastError(), so I changed win32/win32.c as follows:

@@ -3122,6 +3122,7 @@
      va_list ap;
      int pmode;
+    int retval;

      va_start(ap, flag);
      pmode = va_arg(ap, int);
@@ -3130,7 +3131,10 @@
      if (stricmp(path, "/dev/null")==0)
         path = "NUL";

-    return open(PerlDir_mapA(path), flag, pmode);
+    printf("open(%s, %d, %d)\n", PerlDir_mapA(path), flag, pmode);
+    retval = open(PerlDir_mapA(path), flag, pmode);
+    printf("last error=%lu\n", GetLastError());
+    return retval;

  /* close() that understands socket */

and now the command:

perl -e "open F, 'nothere' or die $^E"


open(C:\p5p\bleadperl\nothere, 32768, 438)
last error=0
Died at -e line 1.

So then I tried a standalone C program that calls open() with the same 

#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
void main(void) {
   char *path = "C:\\p5p\\bleadperl\\nothere";
   int flag = 32768;
   int pmode = 438;
   printf("open(%s, %d, %d)\n", path, flag, pmode);
   open(path, flag, pmode);
   printf("last error=%lu\n", GetLastError());

but when I run this (also built with Borland, of course) it works fine:

open(C:\p5p\bleadperl\nothere, 32768, 438)
last error=2

Why doesn't open() set the Windows last error code when called inside 
perl, but does normally?  What weirdness does perl do that stops it from 

Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About