summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorSteve Hay <steve.m.hay@googlemail.com>2013-09-04 18:20:03 +0100
committerSteve Hay <steve.m.hay@googlemail.com>2013-09-16 15:37:31 +0100
commitc9beaf974d06db3d9c7faecba5bb3e9e2a91767d (patch)
tree5f2b0168225ee392642f4996e97e679ac1ad1c61 /win32/win32.c
parent80d2c56d79ef25871e30e4edd302eefe95af4b7f (diff)
downloadperl-c9beaf974d06db3d9c7faecba5bb3e9e2a91767d.tar.gz
Intercept assignment to $! to translate WSAExxx values to Exxx values on Windows
Since perl previously assigned WSAExxx values to $! on Windows it is quite possible that (Perl-level) user code may also manually make similar assignments, which will now cause breakage if the value put in $! is subsequently compared to Errno/POSIX constants because the latter are now the corresponding Exxx values where possible. An example of this is in Net::Ping::tcp_connect(), which does the following to fetch a socket-level error code: unpack("i", getsockopt($self->{"fh"}, SOL_SOCKET, SO_ERROR)) and assigns the result (a WSAExxx value such as 10061) to $! and then goes wrong in the subsequent test (in ping_tcp()) for $! == ECONNREFUSED (which is now 107 rather than 10061 if perl is built with VC10 or higher). To avoid this we now intercept assignment to $! and convert any WSAExxx values to Exxx values first. This causes a minor oddity in that this: perl -le "$! = 10061; print 0+$!" will now output 107 (for VC10+ perls) but this is surely preferable to the alternative breakage described above.
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 1a64f9f2cb..0e8a89e6d6 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2522,6 +2522,19 @@ win32_flock(int fd, int oper)
#undef LK_LEN
+/* Get the errno value corresponding to the given err. This function is not
+ * intended to handle conversion of general GetLastError() codes. It only exists
+ * to translate Windows sockets error codes from WSAGetLastError(). Such codes
+ * used to be assigned to errno/$! in earlier versions of perl; this function is
+ * used to catch any old Perl code which is still trying to assign such values
+ * to $! and convert them to errno values instead.
+ */
+int
+win32_get_errno(int err)
+{
+ return convert_wsa_error_to_errno(err);
+}
+
/*
* redirected io subsystem for all XS modules
*