summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-12-08 16:46:21 +0100
committerNicholas Clark <nick@ccl4.org>2011-12-30 11:36:39 +0100
commita387c53a5a2f3e13850addc6976624f827a26226 (patch)
tree9f5aed62be62f37269e9e83bd92bae669aa767e1 /ext
parent937a45d0cc6e5b194e9242faa9cf78ba2122e6a3 (diff)
downloadperl-a387c53a5a2f3e13850addc6976624f827a26226.tar.gz
Convert POSIX::sleep to an XS wrapper for PerlProc_sleep().
Previously it was a Perl wrapper for CORE::sleep, converting CORE::sleep's return value of elapsed time slept into the POSIX return value of seconds remaining. However, that approach could sometimes return a negative result if CORE::sleep had slept for more than a second longer than the requested time.
Diffstat (limited to 'ext')
-rw-r--r--ext/B/t/concise-xs.t2
-rw-r--r--ext/POSIX/POSIX.xs8
-rw-r--r--ext/POSIX/lib/POSIX.pm3
3 files changed, 10 insertions, 3 deletions
diff --git a/ext/B/t/concise-xs.t b/ext/B/t/concise-xs.t
index 9082f61eed..efd0cf7788 100644
--- a/ext/B/t/concise-xs.t
+++ b/ext/B/t/concise-xs.t
@@ -205,7 +205,7 @@ my $testpkgs = {
fmod floor dup2 dup difftime cuserid ctime
ctermid cosh constant close clock ceil
bootstrap atan asin asctime acos access abort
- _exit
+ _exit sleep
/],
},
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 1bad5e10d9..ab30a1c496 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1885,6 +1885,14 @@ pause()
CLEANUP:
PERL_ASYNC_CHECK();
+unsigned int
+sleep(seconds)
+ unsigned int seconds
+ CODE:
+ RETVAL = PerlProc_sleep(seconds);
+ OUTPUT:
+ RETVAL
+
SysRet
setgid(gid)
Gid_t gid
diff --git a/ext/POSIX/lib/POSIX.pm b/ext/POSIX/lib/POSIX.pm
index 9840b766f3..b6997ffca9 100644
--- a/ext/POSIX/lib/POSIX.pm
+++ b/ext/POSIX/lib/POSIX.pm
@@ -179,7 +179,6 @@ my %reimpl = (
isatty => 'filehandle => -t $_[0]',
link => 'oldfilename, newfilename => CORE::link($_[0], $_[1])',
rmdir => 'directoryname => CORE::rmdir($_[0])',
- sleep => 'seconds => $_[0] - CORE::sleep($_[0])',
unlink => 'filename => CORE::unlink($_[0])',
utime => 'filename, atime, mtime => CORE::utime($_[1], $_[2], $_[0])',
);
@@ -391,7 +390,7 @@ our %EXPORT_TAGS = (
# @EXPORT are actually shared hash key scalars, which will save some memory.
our @EXPORT = keys %export;
- our @EXPORT_OK = (qw(close lchown nice open pipe read times write
+ our @EXPORT_OK = (qw(close lchown nice open pipe read sleep times write
printf sprintf),
grep {!exists $export{$_}} keys %reimpl, keys %replacement);
}