summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2007-08-16 21:32:47 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2007-08-16 21:32:47 -0500
commit31f905d64162e63b812474241a5e3b0ff4ac9150 (patch)
tree4913e1385c7db71afb2abc702fbb6c1176b9d71d
parentfe665b323186414e66de9b7107fe2533aa630795 (diff)
downloadio-pty-easy-31f905d64162e63b812474241a5e3b0ff4ac9150.tar.gz
io-pty-easy-31f905d64162e63b812474241a5e3b0ff4ac9150.zip
make read() consistent with the documentation
-rw-r--r--lib/IO/Pty/Easy.pm13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/IO/Pty/Easy.pm b/lib/IO/Pty/Easy.pm
index b2fae90..a7c10ec 100644
--- a/lib/IO/Pty/Easy.pm
+++ b/lib/IO/Pty/Easy.pm
@@ -183,24 +183,25 @@ Read data from the process running on the PTY.
C<read()> takes two optional arguments: the first is the amount of time to block for data (defaults to blocking forever, 0 means completely non-blocking), and the second is the maximum number of bytes to read (defaults to the value of C<def_max_read_chars>, usually 8192).
-Returns C<undef> on timeout, 0 on eof (including if no subprocess is currently running on the PTY), and a string of at least one character on success (this is consistent with C<sysread()> and L<Term::ReadKey>).
+Returns C<undef> on timeout, '' on eof (including if no subprocess is currently running on the PTY), and a string of at least one character on success (this is consistent with C<sysread()> and L<Term::ReadKey>).
=cut
sub read {
my $self = shift;
- return 0 unless $self->is_active;
- my ($buf, $timeout, $max_chars) = @_;
+ return '' unless $self->is_active;
+ my ($timeout, $max_chars) = @_;
$max_chars ||= $self->{def_max_read_chars};
my $rin = '';
vec($rin, fileno($self->{pty}), 1) = 1;
my $nfound = select($rin, undef, undef, $timeout);
- my $nchars;
+ my $buf;
if ($nfound > 0) {
- $nchars = sysread($self->{pty}, $_[0], $max_chars);
+ my $nchars = sysread($self->{pty}, $buf, $max_chars);
+ $buf = '' if defined($nchars) && $nchars == 0;
}
- return $nchars;
+ return $buf;
}
# }}}