mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-07-04 02:41:20 -03:00
builtins to allow stdin to be closed
Prior to this fix, if stdin were explicitly closed, then builtins would
silently fail. For example:
count <&-
would just fail with status 1. Remove this limitation and allow each
builtin to handle a closed stdin how it sees fit.
This commit is contained in:
@@ -236,11 +236,17 @@ static maybe_t<int> builtin_count(parser_t &parser, io_streams_t &streams, wchar
|
||||
|
||||
// Count the newlines coming in via stdin like `wc -l`.
|
||||
if (streams.stdin_is_directly_redirected) {
|
||||
assert(streams.stdin_fd >= 0 &&
|
||||
"Should have a valid fd since stdin is directly redirected");
|
||||
char buf[COUNT_CHUNK_SIZE];
|
||||
while (true) {
|
||||
long n = read_blocked(streams.stdin_fd, buf, COUNT_CHUNK_SIZE);
|
||||
// Ignore all errors for now.
|
||||
if (n <= 0) break;
|
||||
if (n == 0) {
|
||||
break;
|
||||
} else if (n < 0) {
|
||||
wperror(L"read");
|
||||
return STATUS_CMD_ERROR;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (buf[i] == L'\n') {
|
||||
argc++;
|
||||
|
||||
Reference in New Issue
Block a user