Skip to content

Commit cad8978

Browse files
authored
fold: '-' is not stdin (#447)
* GNU fold treats '-' as a special file argument but that is an extension * Standards document contains wording that stdin is only used if no arguments are given; OpenBSD follows this [1] * The pod manual also says stdin is only used as a default for no file arguments ('-' is not documented to have a special meaning) * This change was recently made to bin/head also 1. https://pubs.opengroup.org/onlinepubs/009695299/utilities/fold.html
1 parent 2dd3800 commit cad8978

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

bin/fold

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ if ($Space_Break && $Width < $Tabstop) {
9090
usage("width must be greater than $Tabstop with the -s option");
9191
}
9292

93-
unshift(@ARGV, '-') unless @ARGV;
9493
my $err = 0;
9594
for (@ARGV) {
9695
$err |= fold_file($_);
9796
}
97+
unless (@ARGV) {
98+
$err |= fold_file();
99+
}
98100
exit ($err ? EX_FAILURE : EX_SUCCESS);
99101

100102
########
@@ -121,17 +123,18 @@ sub fold_file {
121123
my($column, $char, $input, $output);
122124

123125
$column = 0;
124-
if (-d $filename) {
125-
warn "$Program: $filename: is a directory\n";
126-
return 1;
127-
}
128-
if ($filename eq '-') {
129-
$input = *STDIN;
130-
} else {
126+
if (defined $filename) {
127+
if (-d $filename) {
128+
warn "$Program: '$filename': is a directory\n";
129+
return 1;
130+
}
131131
unless (open $input, '<', $filename) {
132-
warn "$Program: $filename: $!\n";
132+
warn "$Program: '$filename': $!\n";
133133
return 1;
134134
}
135+
} else {
136+
$filename = '(stdin)';
137+
$input = *STDIN;
135138
}
136139

137140
# the following hack allows us to dispense with the

0 commit comments

Comments
 (0)