From 31f905d64162e63b812474241a5e3b0ff4ac9150 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Thu, 16 Aug 2007 21:32:47 -0500 Subject: make read() consistent with the documentation --- lib/IO/Pty/Easy.pm | 13 +++++++------ 1 file 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 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, usually 8192). -Returns C 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 and L). +Returns C 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 and L). =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; } # }}} -- cgit v1.2.3-54-g00ecf