summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-12-09 13:09:07 +0100
committerNicholas Clark <nick@ccl4.org>2011-12-22 16:48:39 +0100
commitff98948cb46d88b7ceff65a134edd044953f6934 (patch)
tree9743a4c047a5d7851c1dbc85c6b7bb13f58e33af
parentf60d889184369ca9b18bb2bfee2997a546106a1f (diff)
downloadperl-smoke-me/POSIX-sleep.tar.gz
Provide the correct POSIX return value for POSIX::dup2() on Win32.smoke-me/POSIX-sleep
Microsoft, in their wisdom, chose to ignore the POSIX spec when implementing their dup2(), and have theirs return 0 on success, instead of the file descriptor. It seems that no other vendor is this, um, "special", so code the exception directly, as we don't run Configure on Win32, so there's little point probing for this. This resolves RT #98912.
-rw-r--r--ext/POSIX/POSIX.xs11
-rw-r--r--ext/POSIX/t/posix.t3
2 files changed, 11 insertions, 3 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index e8ac77114e..2b2055d19c 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1466,6 +1466,17 @@ SysRet
dup2(fd1, fd2)
int fd1
int fd2
+ CODE:
+#ifdef WIN32
+ /* RT #98912 - More Microsoft muppetry - failing to actually implemented
+ the well known documented POSIX behaviour for a POSIX API.
+ http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
+ RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
+#else
+ RETVAL = dup2(fd1, fd2);
+#endif
+ OUTPUT:
+ RETVAL
SV *
lseek(fd, offset, whence)
diff --git a/ext/POSIX/t/posix.t b/ext/POSIX/t/posix.t
index a5585e0561..442b540dac 100644
--- a/ext/POSIX/t/posix.t
+++ b/ext/POSIX/t/posix.t
@@ -346,9 +346,6 @@ is($buffer, "# Ex", 'read');
# The descriptor $testfd was using is now free, and is lower than that which
# $fd1 was using. Hence if dup2() behaves as dup(), we'll know :-)
{
- local $TODO;
- $TODO = "dup2's return value is not correct on $^O"
- if $Is_W32;
$testfd = dup2($fd2, $fd1);
is($testfd, $fd1, 'dup2');
undef $buffer;