Use proper function to read a line of input

This commit is contained in:
Jamie Cameron
2018-11-25 17:52:22 -08:00
parent 99d6684972
commit 0b2c65561b

View File

@@ -988,8 +988,7 @@ while(1) {
# this sub-process is asking about a password
local $infd = $passin[$i];
local $outfd = $passout[$i];
#local $inline = <$infd>;
local $inline = &sysread_line($infd);
local $inline = <$infd>;
if ($inline) {
print DEBUG "main: inline $inline";
}
@@ -3086,22 +3085,6 @@ else {
}
}
# sysread_line(fh)
# Read a line from a file handle, using sysread to get a byte at a time
sub sysread_line
{
local ($fh) = @_;
local $line;
while(1) {
local ($buf, $got);
$got = sysread($fh, $buf, 1);
last if ($got <= 0);
$line .= $buf;
last if ($buf eq "\n");
}
return $line;
}
# wait_for_data(secs)
# Waits at most the given amount of time for some data on SOCK, returning
# 0 if not found, 1 if some arrived.