mirror of
https://github.com/coreutils/coreutils.git
synced 2026-10-28 09:44:34 +08:00
global: convert indentation-TABs to spaces
Transformed via this shell code:
t=$'\t'
git ls-files \
| grep -vE '(^|/)((GNU)?[Mm]akefile|ChangeLog)|\.(am|mk)$' \
| grep -vE 'tests/pr/|help2man' \
| xargs grep -lE "^ *$t" \
| xargs perl -MText::Tabs -ni -le \
'$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
This commit is contained in:
1 parent
2bc0f3caaa
commit
5e778f7c8d
176 files changed
+18808
-18808
No files matched your search
+2
-2
@@ -1,3 +1,3 @@
|
||||
[submodule "gnulib"]
|
||||
path = gnulib
|
||||
url = git://git.sv.gnu.org/gnulib.git
|
||||
path = gnulib
|
||||
url = git://git.sv.gnu.org/gnulib.git
|
||||
@@ -437,8 +437,8 @@ Miscellaneous useful git commands
|
||||
its SHA1 and then tag it or cherry-pick it onto an existing branch.
|
||||
For example, run this:
|
||||
git fsck --lost-found HEAD && cd .git/lost-found/commit \
|
||||
&& for i in *; do git show $i|grep SOME_IDENTIFYING_STRING \
|
||||
&& echo $i; done
|
||||
&& for i in *; do git show $i|grep SOME_IDENTIFYING_STRING \
|
||||
&& echo $i; done
|
||||
The "git fsck ..." command creates the .git/lost-found/... hierarchy
|
||||
listing all unreachable objects. Then the for loop
|
||||
print SHA1s for commits that match via log or patch.
|
||||
|
||||
+221
-221
@@ -27,20 +27,20 @@ use Time::Local;
|
||||
use strict;
|
||||
|
||||
use vars qw($list_types %messages %options @batch_list $batch_cmd
|
||||
$no_recurse $explain_type $find_mode $short_print
|
||||
$no_cvsignore $nolinks $file $single_filename $curr_dir
|
||||
@common_ignores $ignore_rx %entries %subdirs %removed);
|
||||
$no_recurse $explain_type $find_mode $short_print
|
||||
$no_cvsignore $nolinks $file $single_filename $curr_dir
|
||||
@common_ignores $ignore_rx %entries %subdirs %removed);
|
||||
|
||||
use constant SUBDIR_FOUND => 1;
|
||||
use constant SUBDIR_CVS => 2;
|
||||
|
||||
# This list comes from the CVS manual.
|
||||
use constant STANDARD_IGNORES =>
|
||||
('RCS', 'SCCS', 'CVS', 'CVS.adm', 'RCSLOG', 'cvslog.*', 'tags',
|
||||
'TAGS', '.make.state', '.nse_depinfo', '*~', '#*', '.#*', ',*',
|
||||
"_\$*", "*\$", '*.old', '*.bak', '*.BAK', '*.orig', '*.rej',
|
||||
'.del-*', '*.a', '*.olb', '*.o', '*.obj', '*.so', '*.exe',
|
||||
'*.Z', '*.elc', '*.ln', 'core');
|
||||
('RCS', 'SCCS', 'CVS', 'CVS.adm', 'RCSLOG', 'cvslog.*', 'tags',
|
||||
'TAGS', '.make.state', '.nse_depinfo', '*~', '#*', '.#*', ',*',
|
||||
"_\$*", "*\$", '*.old', '*.bak', '*.BAK', '*.orig', '*.rej',
|
||||
'.del-*', '*.a', '*.olb', '*.o', '*.obj', '*.so', '*.exe',
|
||||
'*.Z', '*.elc', '*.ln', 'core');
|
||||
|
||||
# 3-letter month names in POSIX locale, for fast date decoding
|
||||
my %months = (
|
||||
@@ -62,20 +62,20 @@ my %months = (
|
||||
sub usage ()
|
||||
{
|
||||
print "Usage:\n" .
|
||||
" cvsu [OPTIONS] [FILE] ...\n" .
|
||||
"Options:\n" .
|
||||
" --local Disable recursion\n" .
|
||||
" --explain Verbosely print status of files\n" .
|
||||
" --find Emulate find - filenames only\n" .
|
||||
" --short Don't print paths\n" .
|
||||
" --ignore Don't read .cvsignore\n" .
|
||||
" --messages List known file types and long messages\n" .
|
||||
" --nolinks Disable recognizing hard and soft links\n" .
|
||||
" --types=[^]LIST Print only file types [not] from LIST\n" .
|
||||
" --batch=COMMAND Execute this command on files\n" .
|
||||
" --help Print this usage information\n" .
|
||||
" --version Print version number\n" .
|
||||
"Abbreviations and short options are supported\n";
|
||||
" cvsu [OPTIONS] [FILE] ...\n" .
|
||||
"Options:\n" .
|
||||
" --local Disable recursion\n" .
|
||||
" --explain Verbosely print status of files\n" .
|
||||
" --find Emulate find - filenames only\n" .
|
||||
" --short Don't print paths\n" .
|
||||
" --ignore Don't read .cvsignore\n" .
|
||||
" --messages List known file types and long messages\n" .
|
||||
" --nolinks Disable recognizing hard and soft links\n" .
|
||||
" --types=[^]LIST Print only file types [not] from LIST\n" .
|
||||
" --batch=COMMAND Execute this command on files\n" .
|
||||
" --help Print this usage information\n" .
|
||||
" --version Print version number\n" .
|
||||
"Abbreviations and short options are supported\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
@@ -90,11 +90,11 @@ sub version ()
|
||||
sub adjust_types ()
|
||||
{
|
||||
if ($list_types =~ m{^\^(.*)$}) {
|
||||
$list_types = "";
|
||||
foreach (keys %messages) {
|
||||
$list_types .= $_
|
||||
if (index ($1, $_) < 0);
|
||||
}
|
||||
$list_types = "";
|
||||
foreach (keys %messages) {
|
||||
$list_types .= $_
|
||||
if (index ($1, $_) < 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ sub list_messages ()
|
||||
my $default_mark;
|
||||
print "Recognizable file types are:\n";
|
||||
foreach (sort keys %messages) {
|
||||
if (index($list_types, $_) >= 0) {
|
||||
$default_mark = "*";
|
||||
} else {
|
||||
$default_mark = " ";
|
||||
}
|
||||
print " $default_mark $_ $messages{$_}\n";
|
||||
if (index($list_types, $_) >= 0) {
|
||||
$default_mark = "*";
|
||||
} else {
|
||||
$default_mark = " ";
|
||||
}
|
||||
print " $default_mark $_ $messages{$_}\n";
|
||||
}
|
||||
print "* indicates file types listed by default\n";
|
||||
exit 0;
|
||||
@@ -124,28 +124,28 @@ sub init_ignores ()
|
||||
push @common_ignores, STANDARD_IGNORES;
|
||||
|
||||
unless (defined($HOME)) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
my $home_cvsignore = "${HOME}/.cvsignore";
|
||||
|
||||
if (-f "$home_cvsignore") {
|
||||
|
||||
unless (open (CVSIGNORE, "< $home_cvsignore")) {
|
||||
error ("couldn't open $home_cvsignore: $!");
|
||||
}
|
||||
unless (open (CVSIGNORE, "< $home_cvsignore")) {
|
||||
error ("couldn't open $home_cvsignore: $!");
|
||||
}
|
||||
|
||||
while (<CVSIGNORE>) {
|
||||
push (@common_ignores, split);
|
||||
}
|
||||
while (<CVSIGNORE>) {
|
||||
push (@common_ignores, split);
|
||||
}
|
||||
|
||||
close (CVSIGNORE);
|
||||
close (CVSIGNORE);
|
||||
}
|
||||
|
||||
my $CVSIGNOREENV = $ENV{"CVSIGNORE"};
|
||||
|
||||
unless (defined($CVSIGNOREENV)) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
my @ignores_var = split (/ /, $CVSIGNOREENV);
|
||||
@@ -157,15 +157,15 @@ sub init_ignores ()
|
||||
# Newline is added at the end.
|
||||
sub error ($)
|
||||
{
|
||||
print STDERR "cvsu: ERROR: " . shift(@_) . "\n";
|
||||
exit 1;
|
||||
print STDERR "cvsu: ERROR: " . shift(@_) . "\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# execute commands from @exec_list with $exec_cmd
|
||||
sub do_batch ()
|
||||
{
|
||||
my @cmd_list = split (' ', $batch_cmd);
|
||||
system (@cmd_list, @batch_list);
|
||||
my @cmd_list = split (' ', $batch_cmd);
|
||||
system (@cmd_list, @batch_list);
|
||||
}
|
||||
|
||||
# print files status
|
||||
@@ -177,34 +177,34 @@ sub file_status ($)
|
||||
my $pathfile;
|
||||
|
||||
return
|
||||
if $ignore_rx ne '' && $type =~ /[?SLD]/ && $file =~ /$ignore_rx/;
|
||||
if $ignore_rx ne '' && $type =~ /[?SLD]/ && $file =~ /$ignore_rx/;
|
||||
|
||||
return
|
||||
if (index($list_types, $type) < 0);
|
||||
if (index($list_types, $type) < 0);
|
||||
|
||||
$pathfile = $curr_dir . $file;
|
||||
|
||||
if (defined($batch_cmd)) {
|
||||
push (@batch_list, $pathfile);
|
||||
# 1000 items in the command line might be too much for HP-UX
|
||||
if ($#batch_list > 1000) {
|
||||
do_batch();
|
||||
undef @batch_list;
|
||||
}
|
||||
push (@batch_list, $pathfile);
|
||||
# 1000 items in the command line might be too much for HP-UX
|
||||
if ($#batch_list > 1000) {
|
||||
do_batch();
|
||||
undef @batch_list;
|
||||
}
|
||||
}
|
||||
|
||||
if ($short_print) {
|
||||
$item = $file;
|
||||
$item = $file;
|
||||
} else {
|
||||
$item = $pathfile;
|
||||
$item = $pathfile;
|
||||
}
|
||||
|
||||
if ($find_mode) {
|
||||
print "$item\n";
|
||||
print "$item\n";
|
||||
} else {
|
||||
$type = $messages{$type}
|
||||
if ($explain_type);
|
||||
print "$type $item\n";
|
||||
$type = $messages{$type}
|
||||
if ($explain_type);
|
||||
print "$type $item\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,28 +219,28 @@ sub load_entries ($)
|
||||
my %ent = ();
|
||||
|
||||
unless (open (ENTRIES, "< $entries_file")) {
|
||||
error ("couldn't open $entries_file: $!");
|
||||
error ("couldn't open $entries_file: $!");
|
||||
}
|
||||
while (<ENTRIES>) {
|
||||
chomp;
|
||||
$ent{$_} = 1;
|
||||
chomp;
|
||||
$ent{$_} = 1;
|
||||
}
|
||||
close (ENTRIES);
|
||||
|
||||
if (open (ENTRIES, "< $entries_log_file")) {
|
||||
while (<ENTRIES>) {
|
||||
chomp;
|
||||
if ( m{^A (.+)} ) {
|
||||
$ent{$1} = 1;
|
||||
} elsif ( m{^R (.+)} ) {
|
||||
delete $ent{$1};
|
||||
} else {
|
||||
# Note: "cvs commit" helps even when you are offline
|
||||
error ("$entries_log_file:$.: unrecognizable line, " .
|
||||
"try \"cvs commit\"");
|
||||
}
|
||||
}
|
||||
close (ENTRIES);
|
||||
while (<ENTRIES>) {
|
||||
chomp;
|
||||
if ( m{^A (.+)} ) {
|
||||
$ent{$1} = 1;
|
||||
} elsif ( m{^R (.+)} ) {
|
||||
delete $ent{$1};
|
||||
} else {
|
||||
# Note: "cvs commit" helps even when you are offline
|
||||
error ("$entries_log_file:$.: unrecognizable line, " .
|
||||
"try \"cvs commit\"");
|
||||
}
|
||||
}
|
||||
close (ENTRIES);
|
||||
}
|
||||
|
||||
return keys %ent;
|
||||
@@ -260,28 +260,28 @@ sub process_arg ($)
|
||||
local $single_filename = 0;
|
||||
|
||||
if ( $arg eq "" or -d $arg ) {
|
||||
$curr_dir = $arg;
|
||||
my $real_curr_dir = $curr_dir eq "" ? "." : $curr_dir;
|
||||
$curr_dir = $arg;
|
||||
my $real_curr_dir = $curr_dir eq "" ? "." : $curr_dir;
|
||||
|
||||
error ("$real_curr_dir is not a directory")
|
||||
unless ( -d $real_curr_dir );
|
||||
error ("$real_curr_dir is not a directory")
|
||||
unless ( -d $real_curr_dir );
|
||||
|
||||
# Scan present files.
|
||||
file_status (".");
|
||||
opendir (DIR, $real_curr_dir) ||
|
||||
error ("couldn't open directory $real_curr_dir: $!");
|
||||
foreach (readdir (DIR)) {
|
||||
$found_files {$_} = 1;
|
||||
}
|
||||
closedir (DIR);
|
||||
# Scan present files.
|
||||
file_status (".");
|
||||
opendir (DIR, $real_curr_dir) ||
|
||||
error ("couldn't open directory $real_curr_dir: $!");
|
||||
foreach (readdir (DIR)) {
|
||||
$found_files {$_} = 1;
|
||||
}
|
||||
closedir (DIR);
|
||||
} else {
|
||||
$single_filename = basename $arg;
|
||||
$curr_dir = dirname $arg;
|
||||
$found_files{$single_filename} = 1 if lstat $arg;
|
||||
$single_filename = basename $arg;
|
||||
$curr_dir = dirname $arg;
|
||||
$found_files{$single_filename} = 1 if lstat $arg;
|
||||
}
|
||||
|
||||
$curr_dir .= "/"
|
||||
unless ( $curr_dir eq "" || $curr_dir =~ m{/$} );
|
||||
unless ( $curr_dir eq "" || $curr_dir =~ m{/$} );
|
||||
|
||||
# Scan CVS/Entries.
|
||||
my %entries = ();
|
||||
@@ -289,118 +289,118 @@ sub process_arg ($)
|
||||
my %removed = ();
|
||||
|
||||
foreach ( load_entries ("${curr_dir}CVS/Entries") ) {
|
||||
if ( m{^D/([^/]+)/} ) {
|
||||
$subdirs{$1} = SUBDIR_FOUND if !$single_filename;
|
||||
} elsif ( m{^/([^/]+)/([^/])[^/]*/([^/]*)/} ) {
|
||||
if ( !$single_filename or $single_filename eq $1 ) {
|
||||
$entries{$1} = $3;
|
||||
$removed{$1} = 1
|
||||
if $2 eq '-';
|
||||
}
|
||||
} elsif ( m{^D$} ) {
|
||||
next;
|
||||
} else {
|
||||
error ("${curr_dir}CVS/Entries: unrecognizable line");
|
||||
}
|
||||
if ( m{^D/([^/]+)/} ) {
|
||||
$subdirs{$1} = SUBDIR_FOUND if !$single_filename;
|
||||
} elsif ( m{^/([^/]+)/([^/])[^/]*/([^/]*)/} ) {
|
||||
if ( !$single_filename or $single_filename eq $1 ) {
|
||||
$entries{$1} = $3;
|
||||
$removed{$1} = 1
|
||||
if $2 eq '-';
|
||||
}
|
||||
} elsif ( m{^D$} ) {
|
||||
next;
|
||||
} else {
|
||||
error ("${curr_dir}CVS/Entries: unrecognizable line");
|
||||
}
|
||||
}
|
||||
|
||||
if ( $single_filename && !$entries{$single_filename} &&
|
||||
!$found_files{$single_filename} ) {
|
||||
error ("nothing known about $arg");
|
||||
!$found_files{$single_filename} ) {
|
||||
error ("nothing known about $arg");
|
||||
}
|
||||
|
||||
# Scan .cvsignore if any
|
||||
unless ($no_cvsignore) {
|
||||
my (@ignore_list) = ();
|
||||
my (@ignore_list) = ();
|
||||
|
||||
if (-f "${curr_dir}.cvsignore") {
|
||||
open (CVSIGNORE, "< ${curr_dir}.cvsignore")
|
||||
|| error ("couldn't open ${curr_dir}.cvsignore: $!");
|
||||
while (<CVSIGNORE>) {
|
||||
push (@ignore_list, split);
|
||||
}
|
||||
close (CVSIGNORE);
|
||||
}
|
||||
if (-f "${curr_dir}.cvsignore") {
|
||||
open (CVSIGNORE, "< ${curr_dir}.cvsignore")
|
||||
|| error ("couldn't open ${curr_dir}.cvsignore: $!");
|
||||
while (<CVSIGNORE>) {
|
||||
push (@ignore_list, split);
|
||||
}
|
||||
close (CVSIGNORE);
|
||||
}
|
||||
|
||||
my ($iter);
|
||||
foreach $iter (@ignore_list, @common_ignores) {
|
||||
if ($iter eq '!') {
|
||||
$ignore_rx = ''
|
||||
} else {
|
||||
if ($ignore_rx eq '') {
|
||||
$ignore_rx = '^(';
|
||||
} else {
|
||||
$ignore_rx .= '|';
|
||||
}
|
||||
$ignore_rx .= glob_to_rx ($iter);
|
||||
}
|
||||
}
|
||||
$ignore_rx .= ')$'
|
||||
if $ignore_rx ne '';
|
||||
my ($iter);
|
||||
foreach $iter (@ignore_list, @common_ignores) {
|
||||
if ($iter eq '!') {
|
||||
$ignore_rx = ''
|
||||
} else {
|
||||
if ($ignore_rx eq '') {
|
||||
$ignore_rx = '^(';
|
||||
} else {
|
||||
$ignore_rx .= '|';
|
||||
}
|
||||
$ignore_rx .= glob_to_rx ($iter);
|
||||
}
|
||||
}
|
||||
$ignore_rx .= ')$'
|
||||
if $ignore_rx ne '';
|
||||
}
|
||||
|
||||
# File is missing
|
||||
foreach $file (sort keys %entries) {
|
||||
unless ($found_files{$file}) {
|
||||
if ($removed{$file}) {
|
||||
file_status("R");
|
||||
} else {
|
||||
file_status("U");
|
||||
}
|
||||
}
|
||||
unless ($found_files{$file}) {
|
||||
if ($removed{$file}) {
|
||||
file_status("R");
|
||||
} else {
|
||||
file_status("U");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach $file (sort keys %found_files) {
|
||||
next if ($file eq '.' || $file eq '..');
|
||||
lstat ($curr_dir . $file) ||
|
||||
error ("lstat() failed on $curr_dir . $file");
|
||||
if (! $nolinks && -l _) {
|
||||
file_status ("L");
|
||||
} elsif (-d _) {
|
||||
if ($file eq 'CVS') {
|
||||
file_status ("C");
|
||||
} elsif ($subdirs{$file}) {
|
||||
$subdirs{$file} = SUBDIR_CVS;
|
||||
} else {
|
||||
file_status ("D"); # Unknown directory
|
||||
}
|
||||
} elsif (! (-f _) && ! (-l _)) {
|
||||
file_status ("S"); # This must be something very special
|
||||
} elsif (! $nolinks && (stat _) [3] > 1 ) {
|
||||
file_status ("H"); # Hard link
|
||||
} elsif (! $entries{$file}) {
|
||||
file_status ("?");
|
||||
} elsif ($entries{$file} =~ /^Initial |^dummy /) {
|
||||
file_status ("A");
|
||||
} elsif ($entries{$file} =~ /^Result of merge/) {
|
||||
file_status ("G");
|
||||
} elsif ($entries{$file} !~
|
||||
/^(...) (...) (..) (..):(..):(..) (....)$/) {
|
||||
error ("Invalid timestamp for $curr_dir$file: $entries{$file}");
|
||||
} else {
|
||||
my $cvtime = timegm($6, $5, $4, $3, $months{$2}, $7 - 1900);
|
||||
my $mtime = (stat _) [9];
|
||||
if ($cvtime == $mtime) {
|
||||
file_status ("F");
|
||||
} elsif ($cvtime < $mtime) {
|
||||
file_status ("M");
|
||||
} else {
|
||||
file_status ("O");
|
||||
}
|
||||
}
|
||||
next if ($file eq '.' || $file eq '..');
|
||||
lstat ($curr_dir . $file) ||
|
||||
error ("lstat() failed on $curr_dir . $file");
|
||||
if (! $nolinks && -l _) {
|
||||
file_status ("L");
|
||||
} elsif (-d _) {
|
||||
if ($file eq 'CVS') {
|
||||
file_status ("C");
|
||||
} elsif ($subdirs{$file}) {
|
||||
$subdirs{$file} = SUBDIR_CVS;
|
||||
} else {
|
||||
file_status ("D"); # Unknown directory
|
||||
}
|
||||
} elsif (! (-f _) && ! (-l _)) {
|
||||
file_status ("S"); # This must be something very special
|
||||
} elsif (! $nolinks && (stat _) [3] > 1 ) {
|
||||
file_status ("H"); # Hard link
|
||||
} elsif (! $entries{$file}) {
|
||||
file_status ("?");
|
||||
} elsif ($entries{$file} =~ /^Initial |^dummy /) {
|
||||
file_status ("A");
|
||||
} elsif ($entries{$file} =~ /^Result of merge/) {
|
||||
file_status ("G");
|
||||
} elsif ($entries{$file} !~
|
||||
/^(...) (...) (..) (..):(..):(..) (....)$/) {
|
||||
error ("Invalid timestamp for $curr_dir$file: $entries{$file}");
|
||||
} else {
|
||||
my $cvtime = timegm($6, $5, $4, $3, $months{$2}, $7 - 1900);
|
||||
my $mtime = (stat _) [9];
|
||||
if ($cvtime == $mtime) {
|
||||
file_status ("F");
|
||||
} elsif ($cvtime < $mtime) {
|
||||
file_status ("M");
|
||||
} else {
|
||||
file_status ("O");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Now do directories.
|
||||
unless ($no_recurse) {
|
||||
my $save_curr_dir = $curr_dir;
|
||||
foreach $file (sort keys %subdirs) {
|
||||
if ($subdirs{$file} == SUBDIR_FOUND) {
|
||||
$curr_dir = $save_curr_dir;
|
||||
file_status ("X");
|
||||
} elsif ($subdirs{$file} == SUBDIR_CVS) {
|
||||
process_arg ($save_curr_dir . $file)
|
||||
}
|
||||
}
|
||||
my $save_curr_dir = $curr_dir;
|
||||
foreach $file (sort keys %subdirs) {
|
||||
if ($subdirs{$file} == SUBDIR_FOUND) {
|
||||
$curr_dir = $save_curr_dir;
|
||||
file_status ("X");
|
||||
} elsif ($subdirs{$file} == SUBDIR_CVS) {
|
||||
process_arg ($save_curr_dir . $file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,13 +423,13 @@ sub glob_to_rx ($)
|
||||
# Find parts in square brackets and copy them literally
|
||||
# Text outside brackets is processed by glob_to_rx_simple()
|
||||
while ($expr ne '') {
|
||||
if ($expr =~ /^(.*?)(\[.*?\])(.*)/) {
|
||||
$expr = $3;
|
||||
$result .= glob_to_rx_simple ($1) . $2;
|
||||
} else {
|
||||
$result .= glob_to_rx_simple ($expr);
|
||||
last;
|
||||
}
|
||||
if ($expr =~ /^(.*?)(\[.*?\])(.*)/) {
|
||||
$expr = $3;
|
||||
$result .= glob_to_rx_simple ($1) . $2;
|
||||
} else {
|
||||
$result .= glob_to_rx_simple ($expr);
|
||||
last;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -441,21 +441,21 @@ sub Main ()
|
||||
|
||||
# long status messages
|
||||
%messages = (
|
||||
"?" => "Unlisted file",
|
||||
"." => "Known directory",
|
||||
"F" => "Up-to-date file",
|
||||
"C" => "CVS admin directory",
|
||||
"M" => "Modified file",
|
||||
"S" => "Special file",
|
||||
"D" => "Unlisted directory",
|
||||
"L" => "Symbolic link",
|
||||
"H" => "Hard link",
|
||||
"U" => "Lost file",
|
||||
"X" => "Lost directory",
|
||||
"A" => "Newly added",
|
||||
"O" => "Older copy",
|
||||
"G" => "Result of merge",
|
||||
"R" => "Removed file"
|
||||
"?" => "Unlisted file",
|
||||
"." => "Known directory",
|
||||
"F" => "Up-to-date file",
|
||||
"C" => "CVS admin directory",
|
||||
"M" => "Modified file",
|
||||
"S" => "Special file",
|
||||
"D" => "Unlisted directory",
|
||||
"L" => "Symbolic link",
|
||||
"H" => "Hard link",
|
||||
"U" => "Lost file",
|
||||
"X" => "Lost directory",
|
||||
"A" => "Newly added",
|
||||
"O" => "Older copy",
|
||||
"G" => "Result of merge",
|
||||
"R" => "Removed file"
|
||||
);
|
||||
|
||||
undef @batch_list; # List of files for batch processing
|
||||
@@ -471,17 +471,17 @@ sub Main ()
|
||||
my $want_ver = 0; # Print version and exit
|
||||
|
||||
my %options = (
|
||||
"types=s" => \$list_types,
|
||||
"batch=s" => \$batch_cmd,
|
||||
"local" => \$no_recurse,
|
||||
"explain" => \$explain_type,
|
||||
"find" => \$find_mode,
|
||||
"short" => \$short_print,
|
||||
"ignore" => \$no_cvsignore,
|
||||
"messages" => \$want_msg,
|
||||
"nolinks" => \$nolinks,
|
||||
"help" => \$want_help,
|
||||
"version" => \$want_ver
|
||||
"types=s" => \$list_types,
|
||||
"batch=s" => \$batch_cmd,
|
||||
"local" => \$no_recurse,
|
||||
"explain" => \$explain_type,
|
||||
"find" => \$find_mode,
|
||||
"short" => \$short_print,
|
||||
"ignore" => \$no_cvsignore,
|
||||
"messages" => \$want_msg,
|
||||
"nolinks" => \$nolinks,
|
||||
"help" => \$want_help,
|
||||
"version" => \$want_ver
|
||||
);
|
||||
|
||||
GetOptions(%options);
|
||||
@@ -493,19 +493,19 @@ sub Main ()
|
||||
version() if $want_ver;
|
||||
|
||||
unless ($no_cvsignore) {
|
||||
init_ignores();
|
||||
init_ignores();
|
||||
}
|
||||
|
||||
if ($#ARGV < 0) {
|
||||
@ARGV = ("");
|
||||
@ARGV = ("");
|
||||
}
|
||||
|
||||
foreach (@ARGV) {
|
||||
process_arg ($_);
|
||||
process_arg ($_);
|
||||
}
|
||||
|
||||
if ($#batch_list >= 0) {
|
||||
do_batch();
|
||||
do_batch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -24,8 +24,8 @@ AC_PREREQ([2.61])
|
||||
# indicates that it is built from the 219th delta (in _some_ repository)
|
||||
# following the v6.9 tag, and that 58ddd is a prefix of the commit SHA1.
|
||||
AC_INIT([GNU coreutils],
|
||||
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
|
||||
[bug-coreutils@gnu.org])
|
||||
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
|
||||
[bug-coreutils@gnu.org])
|
||||
|
||||
AC_CONFIG_SRCDIR([src/ls.c])
|
||||
|
||||
@@ -47,7 +47,7 @@ coreutils_MACROS
|
||||
|
||||
AC_ARG_ENABLE([gcc-warnings],
|
||||
[AS_HELP_STRING([--enable-gcc-warnings],
|
||||
[turn on lots of GCC warnings (for developers)])],
|
||||
[turn on lots of GCC warnings (for developers)])],
|
||||
[case $enableval in
|
||||
yes|no) ;;
|
||||
*) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
|
||||
@@ -122,11 +122,11 @@ AC_FUNC_FORK
|
||||
|
||||
optional_bin_progs=
|
||||
AC_CHECK_FUNCS([uname],
|
||||
gl_ADD_PROG([optional_bin_progs], [uname]))
|
||||
gl_ADD_PROG([optional_bin_progs], [uname]))
|
||||
AC_CHECK_FUNCS([chroot],
|
||||
gl_ADD_PROG([optional_bin_progs], [chroot]))
|
||||
gl_ADD_PROG([optional_bin_progs], [chroot]))
|
||||
AC_CHECK_FUNCS([gethostid],
|
||||
gl_ADD_PROG([optional_bin_progs], [hostid]))
|
||||
gl_ADD_PROG([optional_bin_progs], [hostid]))
|
||||
|
||||
gl_WINSIZE_IN_PTEM
|
||||
|
||||
@@ -168,9 +168,9 @@ int main()
|
||||
[# If we have tzset, assume the worst when cross-compiling.
|
||||
utils_cv_localtime_cache=yes])
|
||||
else
|
||||
# If we lack tzset, report that localtime does not cache TZ,
|
||||
# since we can't invalidate the cache if we don't have tzset.
|
||||
utils_cv_localtime_cache=no
|
||||
# If we lack tzset, report that localtime does not cache TZ,
|
||||
# since we can't invalidate the cache if we don't have tzset.
|
||||
utils_cv_localtime_cache=no
|
||||
fi])dnl
|
||||
AC_MSG_RESULT([$utils_cv_localtime_cache])
|
||||
if test $utils_cv_localtime_cache = yes; then
|
||||
@@ -197,7 +197,7 @@ AC_CACHE_CHECK([for 3-argument setpriority function],
|
||||
[AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/resource.h>
|
||||
]],
|
||||
[[setpriority (0, 0, 0);]])],
|
||||
[utils_cv_func_setpriority=yes],
|
||||
@@ -374,8 +374,8 @@ case $t in
|
||||
$no_install_progs_default) ;;
|
||||
*) AC_MSG_ERROR([[internal error: g'l_INCLUDE_EXCLUDE_PROG's 2nd arg, $t,
|
||||
does not match the list of default-not-installed programs
|
||||
($no_install_progs_default) also recorded in $mk]],
|
||||
1) ;;
|
||||
($no_install_progs_default) also recorded in $mk]],
|
||||
1) ;;
|
||||
esac
|
||||
|
||||
# Given the name of a variable containing a space-separated list of
|
||||
|
||||
+30
-30
@@ -76,45 +76,45 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T **groups)
|
||||
|
||||
g = realloc_groupbuf (NULL, max_n_groups);
|
||||
if (g == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
GETGROUPS_T *h;
|
||||
int last_n_groups = max_n_groups;
|
||||
{
|
||||
GETGROUPS_T *h;
|
||||
int last_n_groups = max_n_groups;
|
||||
|
||||
/* getgrouplist updates max_n_groups to num required. */
|
||||
ng = getgrouplist (username, gid, g, &max_n_groups);
|
||||
/* getgrouplist updates max_n_groups to num required. */
|
||||
ng = getgrouplist (username, gid, g, &max_n_groups);
|
||||
|
||||
/* Some systems (like Darwin) have a bug where they
|
||||
never increase max_n_groups. */
|
||||
if (ng < 0 && last_n_groups == max_n_groups)
|
||||
max_n_groups *= 2;
|
||||
/* Some systems (like Darwin) have a bug where they
|
||||
never increase max_n_groups. */
|
||||
if (ng < 0 && last_n_groups == max_n_groups)
|
||||
max_n_groups *= 2;
|
||||
|
||||
if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (g);
|
||||
errno = saved_errno;
|
||||
return -1;
|
||||
}
|
||||
g = h;
|
||||
if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (g);
|
||||
errno = saved_errno;
|
||||
return -1;
|
||||
}
|
||||
g = h;
|
||||
|
||||
if (0 <= ng)
|
||||
{
|
||||
*groups = g;
|
||||
/* On success some systems just return 0 from getgrouplist,
|
||||
so return max_n_groups rather than ng. */
|
||||
return max_n_groups;
|
||||
}
|
||||
}
|
||||
if (0 <= ng)
|
||||
{
|
||||
*groups = g;
|
||||
/* On success some systems just return 0 from getgrouplist,
|
||||
so return max_n_groups rather than ng. */
|
||||
return max_n_groups;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else no username, so fall through and use getgroups. */
|
||||
#endif
|
||||
|
||||
max_n_groups = (username
|
||||
? getugroups (0, NULL, username, gid)
|
||||
: getgroups (0, NULL));
|
||||
? getugroups (0, NULL, username, gid)
|
||||
: getgroups (0, NULL));
|
||||
|
||||
/* If we failed to count groups with NULL for a buffer,
|
||||
try again with a non-NULL one, just in case. */
|
||||
@@ -126,8 +126,8 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T **groups)
|
||||
return -1;
|
||||
|
||||
ng = (username
|
||||
? getugroups (max_n_groups, g, username, gid)
|
||||
: getgroups (max_n_groups, g));
|
||||
? getugroups (max_n_groups, g, username, gid)
|
||||
: getgroups (max_n_groups, g));
|
||||
|
||||
if (ng < 0)
|
||||
{
|
||||
|
||||
+9
-9
@@ -43,7 +43,7 @@
|
||||
/* This index operation is more efficient on many processors */
|
||||
#define ind(mm, x) \
|
||||
(* (uint32_t *) ((char *) (mm) \
|
||||
+ ((x) & (ISAAC_WORDS - 1) * sizeof (uint32_t))))
|
||||
+ ((x) & (ISAAC_WORDS - 1) * sizeof (uint32_t))))
|
||||
|
||||
/*
|
||||
* The central step. This uses two temporaries, x and y. mm is the
|
||||
@@ -191,18 +191,18 @@ isaac_init (struct isaac_state *s, uint32_t const *seed, size_t seedsize)
|
||||
isaac_mix (s, seed);
|
||||
/* Second and subsequent passes (extension to ISAAC) */
|
||||
while (seedsize -= ISAAC_BYTES)
|
||||
{
|
||||
seed += ISAAC_WORDS;
|
||||
for (i = 0; i < ISAAC_WORDS; i++)
|
||||
s->mm[i] += seed[i];
|
||||
isaac_mix (s, s->mm);
|
||||
}
|
||||
{
|
||||
seed += ISAAC_WORDS;
|
||||
for (i = 0; i < ISAAC_WORDS; i++)
|
||||
s->mm[i] += seed[i];
|
||||
isaac_mix (s, s->mm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The no seed case (as in reference ISAAC code) */
|
||||
for (i = 0; i < ISAAC_WORDS; i++)
|
||||
s->mm[i] = 0;
|
||||
s->mm[i] = 0;
|
||||
}
|
||||
|
||||
/* Final pass */
|
||||
@@ -252,7 +252,7 @@ isaac_seed_data (struct isaac_state *s, void const *buffer, size_t size)
|
||||
{
|
||||
p = (unsigned char *) s->mm + s->c;
|
||||
for (i = 0; i < avail; i++)
|
||||
p[i] ^= buf[i];
|
||||
p[i] ^= buf[i];
|
||||
buf += avail;
|
||||
size -= avail;
|
||||
isaac_mix (s, s->mm);
|
||||
|
||||
+56
-56
@@ -128,75 +128,75 @@ randint_genmax (struct randint_source *s, randint genmax)
|
||||
for (;;)
|
||||
{
|
||||
if (randmax < genmax)
|
||||
{
|
||||
/* Calculate how many input bytes will be needed, and read
|
||||
the bytes. */
|
||||
{
|
||||
/* Calculate how many input bytes will be needed, and read
|
||||
the bytes. */
|
||||
|
||||
size_t i = 0;
|
||||
randint rmax = randmax;
|
||||
unsigned char buf[sizeof randnum];
|
||||
size_t i = 0;
|
||||
randint rmax = randmax;
|
||||
unsigned char buf[sizeof randnum];
|
||||
|
||||
do
|
||||
{
|
||||
rmax = shift_left (rmax) + UCHAR_MAX;
|
||||
i++;
|
||||
}
|
||||
while (rmax < genmax);
|
||||
do
|
||||
{
|
||||
rmax = shift_left (rmax) + UCHAR_MAX;
|
||||
i++;
|
||||
}
|
||||
while (rmax < genmax);
|
||||
|
||||
randread (source, buf, i);
|
||||
randread (source, buf, i);
|
||||
|
||||
/* Increase RANDMAX by appending random bytes to RANDNUM and
|
||||
UCHAR_MAX to RANDMAX until RANDMAX is no less than
|
||||
GENMAX. This may lose up to CHAR_BIT bits of information
|
||||
if shift_right (RANDINT_MAX) < GENMAX, but it is not
|
||||
worth the programming hassle of saving these bits since
|
||||
GENMAX is rarely that large in practice. */
|
||||
/* Increase RANDMAX by appending random bytes to RANDNUM and
|
||||
UCHAR_MAX to RANDMAX until RANDMAX is no less than
|
||||
GENMAX. This may lose up to CHAR_BIT bits of information
|
||||
if shift_right (RANDINT_MAX) < GENMAX, but it is not
|
||||
worth the programming hassle of saving these bits since
|
||||
GENMAX is rarely that large in practice. */
|
||||
|
||||
i = 0;
|
||||
i = 0;
|
||||
|
||||
do
|
||||
{
|
||||
randnum = shift_left (randnum) + buf[i];
|
||||
randmax = shift_left (randmax) + UCHAR_MAX;
|
||||
i++;
|
||||
}
|
||||
while (randmax < genmax);
|
||||
}
|
||||
do
|
||||
{
|
||||
randnum = shift_left (randnum) + buf[i];
|
||||
randmax = shift_left (randmax) + UCHAR_MAX;
|
||||
i++;
|
||||
}
|
||||
while (randmax < genmax);
|
||||
}
|
||||
|
||||
if (randmax == genmax)
|
||||
{
|
||||
s->randnum = s->randmax = 0;
|
||||
return randnum;
|
||||
}
|
||||
{
|
||||
s->randnum = s->randmax = 0;
|
||||
return randnum;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* GENMAX < RANDMAX, so attempt to generate a random number
|
||||
by taking RANDNUM modulo GENMAX+1. This will choose
|
||||
fairly so long as RANDNUM falls within an integral
|
||||
multiple of GENMAX+1; otherwise, LAST_USABLE_CHOICE < RANDNUM,
|
||||
so discard this attempt and try again.
|
||||
{
|
||||
/* GENMAX < RANDMAX, so attempt to generate a random number
|
||||
by taking RANDNUM modulo GENMAX+1. This will choose
|
||||
fairly so long as RANDNUM falls within an integral
|
||||
multiple of GENMAX+1; otherwise, LAST_USABLE_CHOICE < RANDNUM,
|
||||
so discard this attempt and try again.
|
||||
|
||||
Since GENMAX cannot be RANDINT_MAX, CHOICES cannot be
|
||||
zero and there is no need to worry about dividing by
|
||||
zero. */
|
||||
Since GENMAX cannot be RANDINT_MAX, CHOICES cannot be
|
||||
zero and there is no need to worry about dividing by
|
||||
zero. */
|
||||
|
||||
randint excess_choices = randmax - genmax;
|
||||
randint unusable_choices = excess_choices % choices;
|
||||
randint last_usable_choice = randmax - unusable_choices;
|
||||
randint reduced_randnum = randnum % choices;
|
||||
randint excess_choices = randmax - genmax;
|
||||
randint unusable_choices = excess_choices % choices;
|
||||
randint last_usable_choice = randmax - unusable_choices;
|
||||
randint reduced_randnum = randnum % choices;
|
||||
|
||||
if (randnum <= last_usable_choice)
|
||||
{
|
||||
s->randnum = randnum / choices;
|
||||
s->randmax = excess_choices / choices;
|
||||
return reduced_randnum;
|
||||
}
|
||||
if (randnum <= last_usable_choice)
|
||||
{
|
||||
s->randnum = randnum / choices;
|
||||
s->randmax = excess_choices / choices;
|
||||
return reduced_randnum;
|
||||
}
|
||||
|
||||
/* Retry, but retain the randomness from the fact that RANDNUM fell
|
||||
into the range LAST_USABLE_CHOICE+1 .. RANDMAX. */
|
||||
randnum = reduced_randnum;
|
||||
randmax = unusable_choices - 1;
|
||||
}
|
||||
/* Retry, but retain the randomness from the fact that RANDNUM fell
|
||||
into the range LAST_USABLE_CHOICE+1 .. RANDMAX. */
|
||||
randnum = reduced_randnum;
|
||||
randmax = unusable_choices - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -79,21 +79,21 @@ randperm_new (struct randint_source *r, size_t h, size_t n)
|
||||
|
||||
default:
|
||||
{
|
||||
size_t i;
|
||||
size_t i;
|
||||
|
||||
v = xnmalloc (n, sizeof *v);
|
||||
for (i = 0; i < n; i++)
|
||||
v[i] = i;
|
||||
v = xnmalloc (n, sizeof *v);
|
||||
for (i = 0; i < n; i++)
|
||||
v[i] = i;
|
||||
|
||||
for (i = 0; i < h; i++)
|
||||
{
|
||||
size_t j = i + randint_choose (r, n - i);
|
||||
size_t t = v[i];
|
||||
v[i] = v[j];
|
||||
v[j] = t;
|
||||
}
|
||||
for (i = 0; i < h; i++)
|
||||
{
|
||||
size_t j = i + randint_choose (r, n - i);
|
||||
size_t t = v[i];
|
||||
v[i] = v[j];
|
||||
v[j] = t;
|
||||
}
|
||||
|
||||
v = xnrealloc (v, h, sizeof *v);
|
||||
v = xnrealloc (v, h, sizeof *v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+33
-33
@@ -100,8 +100,8 @@ struct randread_source
|
||||
/* Up to a buffer's worth of pseudorandom data. */
|
||||
union
|
||||
{
|
||||
uint32_t w[ISAAC_WORDS];
|
||||
unsigned char b[ISAAC_BYTES];
|
||||
uint32_t w[ISAAC_WORDS];
|
||||
unsigned char b[ISAAC_BYTES];
|
||||
} data;
|
||||
} isaac;
|
||||
} buf;
|
||||
@@ -115,8 +115,8 @@ randread_error (void const *file_name)
|
||||
{
|
||||
if (file_name)
|
||||
error (exit_failure, errno,
|
||||
_(errno == 0 ? "%s: end of file" : "%s: read error"),
|
||||
quotearg_colon (file_name));
|
||||
_(errno == 0 ? "%s: end of file" : "%s: read error"),
|
||||
quotearg_colon (file_name));
|
||||
abort ();
|
||||
}
|
||||
|
||||
@@ -155,18 +155,18 @@ randread_new (char const *name, size_t bytes_bound)
|
||||
struct randread_source *s;
|
||||
|
||||
if (name)
|
||||
if (! (source = fopen_safer (name, "rb")))
|
||||
return NULL;
|
||||
if (! (source = fopen_safer (name, "rb")))
|
||||
return NULL;
|
||||
|
||||
s = simple_new (source, name);
|
||||
|
||||
if (source)
|
||||
setvbuf (source, s->buf.c, _IOFBF, MIN (sizeof s->buf.c, bytes_bound));
|
||||
setvbuf (source, s->buf.c, _IOFBF, MIN (sizeof s->buf.c, bytes_bound));
|
||||
else
|
||||
{
|
||||
s->buf.isaac.buffered = 0;
|
||||
isaac_seed (&s->buf.isaac.state);
|
||||
}
|
||||
{
|
||||
s->buf.isaac.buffered = 0;
|
||||
isaac_seed (&s->buf.isaac.state);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ readsource (struct randread_source *s, unsigned char *p, size_t size)
|
||||
p += inbytes;
|
||||
size -= inbytes;
|
||||
if (size == 0)
|
||||
break;
|
||||
break;
|
||||
errno = (ferror (s->source) ? fread_errno : 0);
|
||||
s->handler (s->handler_arg);
|
||||
}
|
||||
@@ -224,34 +224,34 @@ readisaac (struct isaac *isaac, unsigned char *p, size_t size)
|
||||
for (;;)
|
||||
{
|
||||
if (size <= inbytes)
|
||||
{
|
||||
memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, size);
|
||||
isaac->buffered = inbytes - size;
|
||||
return;
|
||||
}
|
||||
{
|
||||
memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, size);
|
||||
isaac->buffered = inbytes - size;
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, inbytes);
|
||||
p += inbytes;
|
||||
size -= inbytes;
|
||||
|
||||
/* If P is aligned, write to *P directly to avoid the overhead
|
||||
of copying from the buffer. */
|
||||
of copying from the buffer. */
|
||||
if (ALIGNED_POINTER (p, uint32_t))
|
||||
{
|
||||
uint32_t *wp = (uint32_t *) p;
|
||||
while (ISAAC_BYTES <= size)
|
||||
{
|
||||
isaac_refill (&isaac->state, wp);
|
||||
wp += ISAAC_WORDS;
|
||||
size -= ISAAC_BYTES;
|
||||
if (size == 0)
|
||||
{
|
||||
isaac->buffered = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
p = (unsigned char *) wp;
|
||||
}
|
||||
{
|
||||
uint32_t *wp = (uint32_t *) p;
|
||||
while (ISAAC_BYTES <= size)
|
||||
{
|
||||
isaac_refill (&isaac->state, wp);
|
||||
wp += ISAAC_WORDS;
|
||||
size -= ISAAC_BYTES;
|
||||
if (size == 0)
|
||||
{
|
||||
isaac->buffered = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
p = (unsigned char *) wp;
|
||||
}
|
||||
|
||||
isaac_refill (&isaac->state, isaac->data.w);
|
||||
inbytes = ISAAC_BYTES;
|
||||
|
||||
@@ -34,12 +34,12 @@ get_root_dev_ino (struct dev_ino *root_d_i);
|
||||
do \
|
||||
{ \
|
||||
if (STREQ (Dirname, "/")) \
|
||||
error (0, 0, _("it is dangerous to operate recursively on %s"), \
|
||||
quote (Dirname)); \
|
||||
error (0, 0, _("it is dangerous to operate recursively on %s"), \
|
||||
quote (Dirname)); \
|
||||
else \
|
||||
error (0, 0, \
|
||||
_("it is dangerous to operate recursively on %s (same as %s)"), \
|
||||
quote_n (0, Dirname), quote_n (1, "/")); \
|
||||
error (0, 0, \
|
||||
_("it is dangerous to operate recursively on %s (same as %s)"), \
|
||||
quote_n (0, Dirname), quote_n (1, "/")); \
|
||||
error (0, 0, _("use --no-preserve-root to override this failsafe")); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
+59
-59
@@ -96,7 +96,7 @@ direxists (const char *dir)
|
||||
enough space in TMPL. */
|
||||
int
|
||||
__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
|
||||
int try_tmpdir)
|
||||
int try_tmpdir)
|
||||
{
|
||||
const char *d;
|
||||
size_t dlen, plen;
|
||||
@@ -110,30 +110,30 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
|
||||
{
|
||||
plen = strlen (pfx);
|
||||
if (plen > 5)
|
||||
plen = 5;
|
||||
plen = 5;
|
||||
}
|
||||
|
||||
if (try_tmpdir)
|
||||
{
|
||||
d = __secure_getenv ("TMPDIR");
|
||||
if (d != NULL && direxists (d))
|
||||
dir = d;
|
||||
dir = d;
|
||||
else if (dir != NULL && direxists (dir))
|
||||
/* nothing */ ;
|
||||
/* nothing */ ;
|
||||
else
|
||||
dir = NULL;
|
||||
dir = NULL;
|
||||
}
|
||||
if (dir == NULL)
|
||||
{
|
||||
if (direxists (P_tmpdir))
|
||||
dir = P_tmpdir;
|
||||
dir = P_tmpdir;
|
||||
else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
|
||||
dir = "/tmp";
|
||||
dir = "/tmp";
|
||||
else
|
||||
{
|
||||
__set_errno (ENOENT);
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
__set_errno (ENOENT);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dlen = strlen (dir);
|
||||
@@ -169,9 +169,9 @@ static const char letters[] =
|
||||
|
||||
KIND may be one of:
|
||||
__GT_NOCREATE: simply verify that the name does not exist
|
||||
at the time of the call.
|
||||
at the time of the call.
|
||||
__GT_FILE: create the file using open(O_CREAT|O_EXCL)
|
||||
and return a read-write fd. The file is mode 0600.
|
||||
and return a read-write fd. The file is mode 0600.
|
||||
__GT_BIGFILE: same as __GT_FILE but use open64().
|
||||
__GT_DIR: create a directory, which will be mode 0700.
|
||||
|
||||
@@ -205,7 +205,7 @@ gen_tempname_len (char *tmpl, int kind, size_t x_suffix_len)
|
||||
|
||||
len = strlen (tmpl);
|
||||
if (len < x_suffix_len || ! check_x_suffix (&tmpl[len - x_suffix_len],
|
||||
x_suffix_len))
|
||||
x_suffix_len))
|
||||
{
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
@@ -223,60 +223,60 @@ gen_tempname_len (char *tmpl, int kind, size_t x_suffix_len)
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < x_suffix_len; i++)
|
||||
{
|
||||
XXXXXX[i] = letters[randint_genmax (rand_src, sizeof letters - 2)];
|
||||
}
|
||||
{
|
||||
XXXXXX[i] = letters[randint_genmax (rand_src, sizeof letters - 2)];
|
||||
}
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
case __GT_FILE:
|
||||
fd = small_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
|
||||
break;
|
||||
{
|
||||
case __GT_FILE:
|
||||
fd = small_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
|
||||
break;
|
||||
|
||||
case __GT_BIGFILE:
|
||||
fd = large_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
|
||||
break;
|
||||
case __GT_BIGFILE:
|
||||
fd = large_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
|
||||
break;
|
||||
|
||||
case __GT_DIR:
|
||||
fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
break;
|
||||
case __GT_DIR:
|
||||
fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
break;
|
||||
|
||||
case __GT_NOCREATE:
|
||||
/* This case is backward from the other three. This function
|
||||
succeeds if __xstat fails because the name does not exist.
|
||||
Note the continue to bypass the common logic at the bottom
|
||||
of the loop. */
|
||||
if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
__set_errno (save_errno);
|
||||
fd = 0;
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Give up now. */
|
||||
fd = -1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case __GT_NOCREATE:
|
||||
/* This case is backward from the other three. This function
|
||||
succeeds if __xstat fails because the name does not exist.
|
||||
Note the continue to bypass the common logic at the bottom
|
||||
of the loop. */
|
||||
if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
__set_errno (save_errno);
|
||||
fd = 0;
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Give up now. */
|
||||
fd = -1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
default:
|
||||
assert (! "invalid KIND in __gen_tempname");
|
||||
}
|
||||
default:
|
||||
assert (! "invalid KIND in __gen_tempname");
|
||||
}
|
||||
|
||||
if (fd >= 0)
|
||||
{
|
||||
__set_errno (save_errno);
|
||||
goto done;
|
||||
}
|
||||
{
|
||||
__set_errno (save_errno);
|
||||
goto done;
|
||||
}
|
||||
else if (errno != EEXIST)
|
||||
{
|
||||
fd = -1;
|
||||
goto done;
|
||||
}
|
||||
{
|
||||
fd = -1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
randint_all_free (rand_src);
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@
|
||||
|
||||
KIND may be one of:
|
||||
GT_NOCREATE: simply verify that the name does not exist
|
||||
at the time of the call.
|
||||
at the time of the call.
|
||||
GT_FILE: create a large file using open(O_CREAT|O_EXCL)
|
||||
and return a read-write fd. The file is mode 0600.
|
||||
and return a read-write fd. The file is mode 0600.
|
||||
GT_DIR: create a directory, which will be mode 0700.
|
||||
|
||||
We use a clever algorithm to get hard-to-predict names. */
|
||||
|
||||
+5
-5
@@ -31,11 +31,11 @@ xfreopen (char const *filename, char const *mode, FILE *fp)
|
||||
if (!freopen (filename, mode, fp))
|
||||
{
|
||||
char const *f = (filename ? filename
|
||||
: (fp == stdin ? _("stdin")
|
||||
: (fp == stdout ? _("stdout")
|
||||
: (fp == stderr ? _("stderr")
|
||||
: _("unknown stream")))));
|
||||
: (fp == stdin ? _("stdin")
|
||||
: (fp == stdout ? _("stdout")
|
||||
: (fp == stderr ? _("stderr")
|
||||
: _("unknown stream")))));
|
||||
error (exit_failure, errno, _("failed to reopen %s with mode %s"),
|
||||
quote_n (0, f), quote_n (1, mode));
|
||||
quote_n (0, f), quote_n (1, mode));
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -34,22 +34,22 @@ buffer_lcm (size_t a, size_t b, size_t lcm_max)
|
||||
else
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
/* Return lcm (A, B) if it is in range; otherwise, fall back
|
||||
on A. */
|
||||
{
|
||||
/* Return lcm (A, B) if it is in range; otherwise, fall back
|
||||
on A. */
|
||||
|
||||
size_t lcm, m, n, q, r;
|
||||
size_t lcm, m, n, q, r;
|
||||
|
||||
/* N = gcd (A, B). */
|
||||
for (m = a, n = b; (r = m % n) != 0; m = n, n = r)
|
||||
continue;
|
||||
/* N = gcd (A, B). */
|
||||
for (m = a, n = b; (r = m % n) != 0; m = n, n = r)
|
||||
continue;
|
||||
|
||||
/* LCM = lcm (A, B), if in range. */
|
||||
q = a / n;
|
||||
lcm = q * b;
|
||||
if (lcm <= lcm_max && lcm / b == q)
|
||||
return lcm;
|
||||
}
|
||||
/* LCM = lcm (A, B), if in range. */
|
||||
q = a / n;
|
||||
lcm = q * b;
|
||||
if (lcm <= lcm_max && lcm / b == q)
|
||||
return lcm;
|
||||
}
|
||||
|
||||
size = a;
|
||||
}
|
||||
|
||||
+12
-12
@@ -57,8 +57,8 @@ euidaccess_stat (struct stat const *st, int mode)
|
||||
mode &= 7;
|
||||
else
|
||||
mode = ((mode & R_OK ? 4 : 0)
|
||||
+ (mode & W_OK ? 2 : 0)
|
||||
+ (mode & X_OK ? 1 : 0));
|
||||
+ (mode & W_OK ? 2 : 0)
|
||||
+ (mode & X_OK ? 1 : 0));
|
||||
|
||||
if (mode == 0)
|
||||
return true; /* The file exists. */
|
||||
@@ -68,7 +68,7 @@ euidaccess_stat (struct stat const *st, int mode)
|
||||
/* The super-user can read and write any file, and execute any file
|
||||
that anyone can execute. */
|
||||
if (euid == 0 && ((mode & X_OK) == 0
|
||||
|| (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
|
||||
|| (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
|
||||
return true;
|
||||
|
||||
/* Convert the file's permission bits to traditional form. */
|
||||
@@ -84,14 +84,14 @@ euidaccess_stat (struct stat const *st, int mode)
|
||||
granted = st->st_mode;
|
||||
else
|
||||
granted = ( (st->st_mode & S_IRUSR ? 4 << 6 : 0)
|
||||
+ (st->st_mode & S_IWUSR ? 2 << 6 : 0)
|
||||
+ (st->st_mode & S_IXUSR ? 1 << 6 : 0)
|
||||
+ (st->st_mode & S_IRGRP ? 4 << 3 : 0)
|
||||
+ (st->st_mode & S_IWGRP ? 2 << 3 : 0)
|
||||
+ (st->st_mode & S_IXGRP ? 1 << 3 : 0)
|
||||
+ (st->st_mode & S_IROTH ? 4 << 0 : 0)
|
||||
+ (st->st_mode & S_IWOTH ? 2 << 0 : 0)
|
||||
+ (st->st_mode & S_IXOTH ? 1 << 0 : 0));
|
||||
+ (st->st_mode & S_IWUSR ? 2 << 6 : 0)
|
||||
+ (st->st_mode & S_IXUSR ? 1 << 6 : 0)
|
||||
+ (st->st_mode & S_IRGRP ? 4 << 3 : 0)
|
||||
+ (st->st_mode & S_IWGRP ? 2 << 3 : 0)
|
||||
+ (st->st_mode & S_IXGRP ? 1 << 3 : 0)
|
||||
+ (st->st_mode & S_IROTH ? 4 << 0 : 0)
|
||||
+ (st->st_mode & S_IWOTH ? 2 << 0 : 0)
|
||||
+ (st->st_mode & S_IXOTH ? 1 << 0 : 0));
|
||||
|
||||
if (euid == st->st_uid)
|
||||
granted >>= 6;
|
||||
@@ -99,7 +99,7 @@ euidaccess_stat (struct stat const *st, int mode)
|
||||
{
|
||||
gid_t egid = getegid ();
|
||||
if (egid == st->st_gid || group_member (st->st_gid))
|
||||
granted >>= 3;
|
||||
granted >>= 3;
|
||||
}
|
||||
|
||||
if ((mode & ~granted) == 0)
|
||||
|
||||
@@ -77,12 +77,12 @@ __alloc_dir (int fd, bool close_fd)
|
||||
size_t allocation;
|
||||
#ifdef _STATBUF_ST_BLKSIZE
|
||||
if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64),
|
||||
1))
|
||||
1))
|
||||
allocation = statp->st_blksize;
|
||||
else
|
||||
#endif
|
||||
allocation = (BUFSIZ < sizeof (struct dirent64)
|
||||
? sizeof (struct dirent64) : BUFSIZ);
|
||||
? sizeof (struct dirent64) : BUFSIZ);
|
||||
|
||||
const int pad = -sizeof (DIR) % __alignof__ (struct dirent64);
|
||||
|
||||
@@ -91,11 +91,11 @@ __alloc_dir (int fd, bool close_fd)
|
||||
lose:
|
||||
{
|
||||
if (close_fd)
|
||||
{
|
||||
int save_errno = errno;
|
||||
close_not_cancel_no_status (fd);
|
||||
__set_errno (save_errno);
|
||||
}
|
||||
{
|
||||
int save_errno = errno;
|
||||
close_not_cancel_no_status (fd);
|
||||
__set_errno (save_errno);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
memset (dirp, '\0', sizeof (DIR));
|
||||
|
||||
+25
-25
@@ -40,7 +40,7 @@
|
||||
|
||||
size_t
|
||||
memxfrm (char *restrict dest, size_t destsize,
|
||||
char *restrict src, size_t srcsize)
|
||||
char *restrict src, size_t srcsize)
|
||||
{
|
||||
#if HAVE_STRXFRM
|
||||
|
||||
@@ -59,33 +59,33 @@ memxfrm (char *restrict dest, size_t destsize,
|
||||
errno = 0;
|
||||
result += strxfrm (dest + di, src + si, destsize - di) + 1;
|
||||
if (errno != 0)
|
||||
break;
|
||||
break;
|
||||
if (result <= result0)
|
||||
{
|
||||
errno = ERANGE;
|
||||
break;
|
||||
}
|
||||
{
|
||||
errno = ERANGE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == destsize + 1 && si + slen == srcsize)
|
||||
{
|
||||
/* The destination is exactly the right size, but strxfrm wants
|
||||
room for a trailing null. Work around the problem with a
|
||||
temporary buffer. */
|
||||
size_t bufsize = destsize - di + 1;
|
||||
char stackbuf[4000];
|
||||
char *buf = stackbuf;
|
||||
if (sizeof stackbuf < bufsize)
|
||||
{
|
||||
buf = malloc (bufsize);
|
||||
if (! buf)
|
||||
break;
|
||||
}
|
||||
strxfrm (buf, src + si, bufsize);
|
||||
memcpy (dest + di, buf, destsize - di);
|
||||
if (sizeof stackbuf < bufsize)
|
||||
free (buf);
|
||||
errno = 0;
|
||||
}
|
||||
{
|
||||
/* The destination is exactly the right size, but strxfrm wants
|
||||
room for a trailing null. Work around the problem with a
|
||||
temporary buffer. */
|
||||
size_t bufsize = destsize - di + 1;
|
||||
char stackbuf[4000];
|
||||
char *buf = stackbuf;
|
||||
if (sizeof stackbuf < bufsize)
|
||||
{
|
||||
buf = malloc (bufsize);
|
||||
if (! buf)
|
||||
break;
|
||||
}
|
||||
strxfrm (buf, src + si, bufsize);
|
||||
memcpy (dest + di, buf, destsize - di);
|
||||
if (sizeof stackbuf < bufsize)
|
||||
free (buf);
|
||||
errno = 0;
|
||||
}
|
||||
|
||||
di = (result < destsize ? result : destsize);
|
||||
si += slen + 1;
|
||||
|
||||
+72
-72
@@ -77,28 +77,28 @@ fraccompare (char const *a, char const *b, char decimal_point)
|
||||
if (*a == decimal_point && *b == decimal_point)
|
||||
{
|
||||
while (*++a == *++b)
|
||||
if (! ISDIGIT (*a))
|
||||
return 0;
|
||||
if (! ISDIGIT (*a))
|
||||
return 0;
|
||||
if (ISDIGIT (*a) && ISDIGIT (*b))
|
||||
return *a - *b;
|
||||
return *a - *b;
|
||||
if (ISDIGIT (*a))
|
||||
goto a_trailing_nonzero;
|
||||
goto a_trailing_nonzero;
|
||||
if (ISDIGIT (*b))
|
||||
goto b_trailing_nonzero;
|
||||
goto b_trailing_nonzero;
|
||||
return 0;
|
||||
}
|
||||
else if (*a++ == decimal_point)
|
||||
{
|
||||
a_trailing_nonzero:
|
||||
while (*a == NUMERIC_ZERO)
|
||||
a++;
|
||||
a++;
|
||||
return ISDIGIT (*a);
|
||||
}
|
||||
else if (*b++ == decimal_point)
|
||||
{
|
||||
b_trailing_nonzero:
|
||||
while (*b == NUMERIC_ZERO)
|
||||
b++;
|
||||
b++;
|
||||
return - ISDIGIT (*b);
|
||||
}
|
||||
return 0;
|
||||
@@ -113,7 +113,7 @@ fraccompare (char const *a, char const *b, char decimal_point)
|
||||
|
||||
static inline int
|
||||
numcompare (char const *a, char const *b,
|
||||
int decimal_point, int thousands_sep)
|
||||
int decimal_point, int thousands_sep)
|
||||
{
|
||||
unsigned char tmpa = *a;
|
||||
unsigned char tmpb = *b;
|
||||
@@ -124,119 +124,119 @@ numcompare (char const *a, char const *b,
|
||||
if (tmpa == NEGATION_SIGN)
|
||||
{
|
||||
do
|
||||
tmpa = *++a;
|
||||
tmpa = *++a;
|
||||
while (tmpa == NUMERIC_ZERO || tmpa == thousands_sep);
|
||||
if (tmpb != NEGATION_SIGN)
|
||||
{
|
||||
if (tmpa == decimal_point)
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == NUMERIC_ZERO);
|
||||
if (ISDIGIT (tmpa))
|
||||
return -1;
|
||||
while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep)
|
||||
tmpb = *++b;
|
||||
if (tmpb == decimal_point)
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == NUMERIC_ZERO);
|
||||
return - ISDIGIT (tmpb);
|
||||
}
|
||||
{
|
||||
if (tmpa == decimal_point)
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == NUMERIC_ZERO);
|
||||
if (ISDIGIT (tmpa))
|
||||
return -1;
|
||||
while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep)
|
||||
tmpb = *++b;
|
||||
if (tmpb == decimal_point)
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == NUMERIC_ZERO);
|
||||
return - ISDIGIT (tmpb);
|
||||
}
|
||||
do
|
||||
tmpb = *++b;
|
||||
tmpb = *++b;
|
||||
while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep);
|
||||
|
||||
while (tmpa == tmpb && ISDIGIT (tmpa))
|
||||
{
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
}
|
||||
{
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
}
|
||||
|
||||
if ((tmpa == decimal_point && !ISDIGIT (tmpb))
|
||||
|| (tmpb == decimal_point && !ISDIGIT (tmpa)))
|
||||
return fraccompare (b, a, decimal_point);
|
||||
|| (tmpb == decimal_point && !ISDIGIT (tmpa)))
|
||||
return fraccompare (b, a, decimal_point);
|
||||
|
||||
tmp = tmpb - tmpa;
|
||||
|
||||
for (log_a = 0; ISDIGIT (tmpa); ++log_a)
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
|
||||
for (log_b = 0; ISDIGIT (tmpb); ++log_b)
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
|
||||
if (log_a != log_b)
|
||||
return log_a < log_b ? 1 : -1;
|
||||
return log_a < log_b ? 1 : -1;
|
||||
|
||||
if (!log_a)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
else if (tmpb == NEGATION_SIGN)
|
||||
{
|
||||
do
|
||||
tmpb = *++b;
|
||||
tmpb = *++b;
|
||||
while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep);
|
||||
if (tmpb == decimal_point)
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == NUMERIC_ZERO);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == NUMERIC_ZERO);
|
||||
if (ISDIGIT (tmpb))
|
||||
return 1;
|
||||
return 1;
|
||||
while (tmpa == NUMERIC_ZERO || tmpa == thousands_sep)
|
||||
tmpa = *++a;
|
||||
tmpa = *++a;
|
||||
if (tmpa == decimal_point)
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == NUMERIC_ZERO);
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == NUMERIC_ZERO);
|
||||
return ISDIGIT (tmpa);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (tmpa == NUMERIC_ZERO || tmpa == thousands_sep)
|
||||
tmpa = *++a;
|
||||
tmpa = *++a;
|
||||
while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep)
|
||||
tmpb = *++b;
|
||||
tmpb = *++b;
|
||||
|
||||
while (tmpa == tmpb && ISDIGIT (tmpa))
|
||||
{
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
}
|
||||
{
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
}
|
||||
|
||||
if ((tmpa == decimal_point && !ISDIGIT (tmpb))
|
||||
|| (tmpb == decimal_point && !ISDIGIT (tmpa)))
|
||||
return fraccompare (a, b, decimal_point);
|
||||
|| (tmpb == decimal_point && !ISDIGIT (tmpa)))
|
||||
return fraccompare (a, b, decimal_point);
|
||||
|
||||
tmp = tmpa - tmpb;
|
||||
|
||||
for (log_a = 0; ISDIGIT (tmpa); ++log_a)
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
do
|
||||
tmpa = *++a;
|
||||
while (tmpa == thousands_sep);
|
||||
|
||||
for (log_b = 0; ISDIGIT (tmpb); ++log_b)
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
do
|
||||
tmpb = *++b;
|
||||
while (tmpb == thousands_sep);
|
||||
|
||||
if (log_a != log_b)
|
||||
return log_a < log_b ? -1 : 1;
|
||||
return log_a < log_b ? -1 : 1;
|
||||
|
||||
if (!log_a)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
|
||||
int
|
||||
strnumcmp (char const *a, char const *b,
|
||||
int decimal_point, int thousands_sep)
|
||||
int decimal_point, int thousands_sep)
|
||||
{
|
||||
return numcompare (a, b, decimal_point, thousands_sep);
|
||||
}
|
||||
+4
-4
@@ -38,10 +38,10 @@ function mkdir_len
|
||||
( cd $root &&
|
||||
perl -e 'my $len='$n'-length "'$root'";$i=100;$d="z"x$i;
|
||||
while ($i+2 < $len) {
|
||||
$len -= $i + 1;
|
||||
mkdir $d,0700 or die "$!\n";
|
||||
chdir $d} $d="z"x($len-1);
|
||||
mkdir $d or die "mkdir_len: $d: $!\n"' )
|
||||
$len -= $i + 1;
|
||||
mkdir $d,0700 or die "$!\n";
|
||||
chdir $d} $d="z"x($len-1);
|
||||
mkdir $d or die "mkdir_len: $d: $!\n"' )
|
||||
}
|
||||
|
||||
size_list=
|
||||
|
||||
+13
-13
@@ -35,28 +35,28 @@
|
||||
|
||||
FTS *
|
||||
xfts_open (char * const *argv, int options,
|
||||
int (*compar) (const FTSENT **, const FTSENT **))
|
||||
int (*compar) (const FTSENT **, const FTSENT **))
|
||||
{
|
||||
FTS *fts = fts_open (argv, options | FTS_CWDFD, compar);
|
||||
if (fts == NULL)
|
||||
{
|
||||
/* This can fail in three ways: out of memory, invalid bit_flags,
|
||||
and one or more of the FILES is an empty string. We could try
|
||||
to decipher that errno==EINVAL means invalid bit_flags and
|
||||
errno==ENOENT means there's an empty string, but that seems wrong.
|
||||
Ideally, fts_open would return a proper error indicator. For now,
|
||||
we'll presume that the bit_flags are valid and just check for
|
||||
empty strings. */
|
||||
and one or more of the FILES is an empty string. We could try
|
||||
to decipher that errno==EINVAL means invalid bit_flags and
|
||||
errno==ENOENT means there's an empty string, but that seems wrong.
|
||||
Ideally, fts_open would return a proper error indicator. For now,
|
||||
we'll presume that the bit_flags are valid and just check for
|
||||
empty strings. */
|
||||
bool invalid_arg = false;
|
||||
for (; *argv; ++argv)
|
||||
{
|
||||
if (**argv == '\0')
|
||||
invalid_arg = true;
|
||||
}
|
||||
{
|
||||
if (**argv == '\0')
|
||||
invalid_arg = true;
|
||||
}
|
||||
if (invalid_arg)
|
||||
error (EXIT_FAILURE, 0, _("invalid argument: %s"), quote (""));
|
||||
error (EXIT_FAILURE, 0, _("invalid argument: %s"), quote (""));
|
||||
else
|
||||
xalloc_die ();
|
||||
xalloc_die ();
|
||||
}
|
||||
|
||||
return fts;
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
FTS *
|
||||
xfts_open (char * const *, int options,
|
||||
int (*) (const FTSENT **, const FTSENT **));
|
||||
int (*) (const FTSENT **, const FTSENT **));
|
||||
+3
-3
@@ -45,7 +45,7 @@
|
||||
|
||||
size_t
|
||||
xmemxfrm (char *restrict dest, size_t destsize,
|
||||
char *restrict src, size_t srcsize)
|
||||
char *restrict src, size_t srcsize)
|
||||
{
|
||||
size_t translated_size = memxfrm (dest, destsize, src, srcsize);
|
||||
|
||||
@@ -54,8 +54,8 @@ xmemxfrm (char *restrict dest, size_t destsize,
|
||||
error (0, errno, _("string transformation failed"));
|
||||
error (0, 0, _("set LC_ALL='C' to work around the problem"));
|
||||
error (exit_failure, 0,
|
||||
_("the untransformed string was %s"),
|
||||
quotearg_n_style_mem (0, locale_quoting_style, src, srcsize));
|
||||
_("the untransformed string was %s"),
|
||||
quotearg_n_style_mem (0, locale_quoting_style, src, srcsize));
|
||||
}
|
||||
|
||||
return translated_size;
|
||||
|
||||
@@ -36,8 +36,8 @@ AC_DEFUN([gl_INCLUDE_EXCLUDE_PROG],
|
||||
gl_no_install_progs_default=`echo '$2'|sed 's/,/ /g'`
|
||||
AC_ARG_ENABLE([install-program],
|
||||
[AS_HELP_STRING([--enable-install-program=PROG_LIST],
|
||||
[install the programs in PROG_LIST (comma-separated,
|
||||
default: none)])],
|
||||
[install the programs in PROG_LIST (comma-separated,
|
||||
default: none)])],
|
||||
[gl_do_install_prog=$enableval],
|
||||
[gl_do_install_prog=]
|
||||
)
|
||||
@@ -46,8 +46,8 @@ AC_DEFUN([gl_INCLUDE_EXCLUDE_PROG],
|
||||
# use --enable-no-install-program=A,B
|
||||
AC_ARG_ENABLE([no-install-program],
|
||||
[AS_HELP_STRING([--enable-no-install-program=PROG_LIST],
|
||||
[do NOT install the programs in PROG_LIST
|
||||
(comma-separated, default: $2)])],
|
||||
[do NOT install the programs in PROG_LIST
|
||||
(comma-separated, default: $2)])],
|
||||
[gl_no_install_prog=$enableval],
|
||||
[gl_no_install_prog=]
|
||||
)
|
||||
@@ -78,7 +78,7 @@ AC_DEFUN([gl_INCLUDE_EXCLUDE_PROG],
|
||||
# Warn about a request not to install a program that is
|
||||
# already on the default-no-install list.
|
||||
case " $gl_no_install_progs_default " in
|
||||
*" $gl_i "*) gl_msg="by default, '$gl_i' is not installed" ;;
|
||||
*" $gl_i "*) gl_msg="by default, '$gl_i' is not installed" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
+14
-14
@@ -37,9 +37,9 @@ AC_DEFUN([coreutils_MACROS],
|
||||
|
||||
# By default, argmatch should fail calling usage (1).
|
||||
AC_DEFINE([ARGMATCH_DIE], [usage (1)],
|
||||
[Define to the function xargmatch calls on failures.])
|
||||
[Define to the function xargmatch calls on failures.])
|
||||
AC_DEFINE([ARGMATCH_DIE_DECL], [void usage (int _e)],
|
||||
[Define to the declaration of the xargmatch failure function.])
|
||||
[Define to the declaration of the xargmatch failure function.])
|
||||
|
||||
# used by ls
|
||||
AC_REQUIRE([gl_CLOCK_TIME])
|
||||
@@ -52,13 +52,13 @@ AC_DEFUN([coreutils_MACROS],
|
||||
AC_CHECK_FUNCS([matchpathcon_init_prefix], [],
|
||||
[
|
||||
case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
|
||||
no:*) # SELinux disabled
|
||||
;;
|
||||
*:no) # SELinux disabled
|
||||
;;
|
||||
*)
|
||||
AC_MSG_WARN([SELinux enabled, but matchpathcon_init_prefix not found])
|
||||
AC_MSG_WARN([The install utility may run slowly])
|
||||
no:*) # SELinux disabled
|
||||
;;
|
||||
*:no) # SELinux disabled
|
||||
;;
|
||||
*)
|
||||
AC_MSG_WARN([SELinux enabled, but matchpathcon_init_prefix not found])
|
||||
AC_MSG_WARN([The install utility may run slowly])
|
||||
esac
|
||||
])
|
||||
LIBS=$coreutils_saved_libs
|
||||
@@ -98,8 +98,8 @@ AC_DEFUN([coreutils_MACROS],
|
||||
# for dd.c and shred.c
|
||||
coreutils_saved_libs=$LIBS
|
||||
AC_SEARCH_LIBS([fdatasync], [rt posix4],
|
||||
[test "$ac_cv_search_fdatasync" = "none required" ||
|
||||
LIB_FDATASYNC=$ac_cv_search_fdatasync])
|
||||
[test "$ac_cv_search_fdatasync" = "none required" ||
|
||||
LIB_FDATASYNC=$ac_cv_search_fdatasync])
|
||||
AC_SUBST([LIB_FDATASYNC])
|
||||
AC_CHECK_FUNCS([fdatasync])
|
||||
LIBS=$coreutils_saved_libs
|
||||
@@ -110,9 +110,9 @@ AC_DEFUN([coreutils_MACROS],
|
||||
AC_MSG_WARN([libcap support disabled by user]),
|
||||
[AC_CHECK_LIB([cap], [cap_get_file],
|
||||
[AC_CHECK_HEADER([sys/capability.h],
|
||||
[LIB_CAP=-lcap
|
||||
AC_DEFINE([HAVE_CAP], [1], [libcap usability])],
|
||||
[AC_MSG_WARN([header sys/capability.h was not found, support for libcap will not be built])]
|
||||
[LIB_CAP=-lcap
|
||||
AC_DEFINE([HAVE_CAP], [1], [libcap usability])],
|
||||
[AC_MSG_WARN([header sys/capability.h was not found, support for libcap will not be built])]
|
||||
)],
|
||||
[AC_MSG_WARN([libcap library was not found or not usable, support for libcap will not be built])])
|
||||
])
|
||||
|
||||
+2
-2
@@ -53,8 +53,8 @@ $ac_includes_default
|
||||
# NetBSD needs -lcrypt for crypt.
|
||||
cu_saved_libs="$LIBS"
|
||||
AC_SEARCH_LIBS([crypt], [ufc crypt],
|
||||
[test "$ac_cv_search_crypt" = "none required" ||
|
||||
LIB_CRYPT="$ac_cv_search_crypt"])
|
||||
[test "$ac_cv_search_crypt" = "none required" ||
|
||||
LIB_CRYPT="$ac_cv_search_crypt"])
|
||||
LIBS="$cu_saved_libs"
|
||||
AC_SUBST([LIB_CRYPT])
|
||||
])
|
||||
+14
-14
@@ -57,30 +57,30 @@ AC_INCLUDES_DEFAULT
|
||||
{ AC_CHECK_MEMBERS([struct statvfs.f_basetype],,, [$statvfs_includes])
|
||||
test $ac_cv_member_struct_statvfs_f_basetype = yes ||
|
||||
{ AC_CHECK_MEMBERS([struct statvfs.f_fstypename],,, [$statvfs_includes])
|
||||
test $ac_cv_member_struct_statvfs_f_fstypename = yes ||
|
||||
{ test $ac_cv_member_struct_statfs_f_fstypename != yes &&
|
||||
{ AC_CHECK_MEMBERS([struct statvfs.f_type],,, [$statvfs_includes])
|
||||
test $ac_cv_member_struct_statvfs_f_type = yes; }; }; }; }
|
||||
test $ac_cv_member_struct_statvfs_f_fstypename = yes ||
|
||||
{ test $ac_cv_member_struct_statfs_f_fstypename != yes &&
|
||||
{ AC_CHECK_MEMBERS([struct statvfs.f_type],,, [$statvfs_includes])
|
||||
test $ac_cv_member_struct_statvfs_f_type = yes; }; }; }; }
|
||||
then
|
||||
AC_CHECK_MEMBERS([struct statvfs.f_namemax],,, [$statvfs_includes])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[$statvfs_includes],
|
||||
[static statvfs s;
|
||||
return (s.s_fsid ^ 0) == 0;])],
|
||||
[$statvfs_includes],
|
||||
[static statvfs s;
|
||||
return (s.s_fsid ^ 0) == 0;])],
|
||||
[AC_DEFINE([STRUCT_STATVFS_F_FSID_IS_INTEGER], [1],
|
||||
[Define to 1 if the f_fsid member of struct statvfs is an integer.])])
|
||||
[Define to 1 if the f_fsid member of struct statvfs is an integer.])])
|
||||
else
|
||||
AC_CHECK_MEMBERS([struct statfs.f_namelen, struct statfs.f_type],,,
|
||||
[$statfs_includes])
|
||||
if test $ac_cv_header_OS_h != yes; then
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[$statfs_includes],
|
||||
[static statfs s;
|
||||
return (s.s_fsid ^ 0) == 0;])],
|
||||
[AC_DEFINE([STRUCT_STATFS_F_FSID_IS_INTEGER], [1],
|
||||
[Define to 1 if the f_fsid member of struct statfs is an integer.])])
|
||||
[AC_LANG_PROGRAM(
|
||||
[$statfs_includes],
|
||||
[static statfs s;
|
||||
return (s.s_fsid ^ 0) == 0;])],
|
||||
[AC_DEFINE([STRUCT_STATFS_F_FSID_IS_INTEGER], [1],
|
||||
[Define to 1 if the f_fsid member of struct statfs is an integer.])])
|
||||
fi
|
||||
fi
|
||||
])
|
||||
+6
-6
@@ -11,9 +11,9 @@
|
||||
AC_DEFUN([gl_FUNC_XATTR],
|
||||
[
|
||||
AC_ARG_ENABLE([xattr],
|
||||
AC_HELP_STRING([--disable-xattr],
|
||||
[do not support extended attributes]),
|
||||
[use_xattr=$enableval], [use_xattr=yes])
|
||||
AC_HELP_STRING([--disable-xattr],
|
||||
[do not support extended attributes]),
|
||||
[use_xattr=$enableval], [use_xattr=yes])
|
||||
|
||||
if test "$use_xattr" = "yes"; then
|
||||
AC_CHECK_HEADERS([attr/error_context.h attr/libattr.h])
|
||||
@@ -24,11 +24,11 @@ AC_DEFUN([gl_FUNC_XATTR],
|
||||
use_xattr=0
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([USE_XATTR], [$use_xattr],
|
||||
[Define if you want extended attribute support.])
|
||||
[Define if you want extended attribute support.])
|
||||
xattr_saved_LIBS=$LIBS
|
||||
AC_SEARCH_LIBS([attr_copy_file], [attr],
|
||||
[test "$ac_cv_search_attr_copy_file" = "none required" ||
|
||||
LIB_XATTR=$ac_cv_search_attr_copy_file])
|
||||
[test "$ac_cv_search_attr_copy_file" = "none required" ||
|
||||
LIB_XATTR=$ac_cv_search_attr_copy_file])
|
||||
AC_CHECK_FUNCS([attr_copy_file])
|
||||
LIBS=$xattr_saved_LIBS
|
||||
AC_SUBST([LIB_XATTR])
|
||||
|
||||
+4
-4
@@ -504,17 +504,17 @@ Changes in release 4.0:
|
||||
* ls accepts new options:
|
||||
--indicator-style=none (no indicators, the default)
|
||||
--indicator-style=classify (all indicators)
|
||||
(equivalent to -F or --classify)
|
||||
(equivalent to -F or --classify)
|
||||
--indicator-style=file-type (file type indicators)
|
||||
(equivalent to -p or --file-type)
|
||||
(equivalent to -p or --file-type)
|
||||
|
||||
--quoting-style=literal (do not quote output)
|
||||
--quoting-style=shell (minimally quote output for the shell)
|
||||
--quoting-style=shell-always (always quote output with '' for the shell)
|
||||
--quoting-style=c (quote output as for a C-language string)
|
||||
(equivalent to -Q or --quote-name)
|
||||
(equivalent to -Q or --quote-name)
|
||||
--quoting-style=escape (like c but omit enclosing "")
|
||||
(equivalent to -b or --escape)
|
||||
(equivalent to -b or --escape)
|
||||
|
||||
--show-control-chars is the opposite of --hide-control-chars
|
||||
This option can be useful if output is to a terminal,
|
||||
|
||||
+74
-74
@@ -53,7 +53,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -80,7 +80,7 @@ The data are encoded as described for the base64 alphabet in RFC 3548.\n\
|
||||
When decoding, the input may contain newlines in addition to the bytes of\n\
|
||||
the formal base64 alphabet. Use --ignore-garbage to attempt to recover\n\
|
||||
from any other non-alphabet bytes in the encoded stream.\n"),
|
||||
stdout);
|
||||
stdout);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ from any other non-alphabet bytes in the encoded stream.\n"),
|
||||
|
||||
static void
|
||||
wrap_write (const char *buffer, size_t len,
|
||||
uintmax_t wrap_column, size_t *current_column, FILE *out)
|
||||
uintmax_t wrap_column, size_t *current_column, FILE *out)
|
||||
{
|
||||
size_t written;
|
||||
|
||||
@@ -107,28 +107,28 @@ wrap_write (const char *buffer, size_t len,
|
||||
{
|
||||
/* Simple write. */
|
||||
if (fwrite (buffer, 1, len, stdout) < len)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
}
|
||||
else
|
||||
for (written = 0; written < len;)
|
||||
{
|
||||
uintmax_t cols_remaining = wrap_column - *current_column;
|
||||
size_t to_write = MIN (cols_remaining, SIZE_MAX);
|
||||
to_write = MIN (to_write, len - written);
|
||||
uintmax_t cols_remaining = wrap_column - *current_column;
|
||||
size_t to_write = MIN (cols_remaining, SIZE_MAX);
|
||||
to_write = MIN (to_write, len - written);
|
||||
|
||||
if (to_write == 0)
|
||||
{
|
||||
if (fputs ("\n", out) < 0)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
*current_column = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fwrite (buffer + written, 1, to_write, stdout) < to_write)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
*current_column += to_write;
|
||||
written += to_write;
|
||||
}
|
||||
if (to_write == 0)
|
||||
{
|
||||
if (fputs ("\n", out) < 0)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
*current_column = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fwrite (buffer + written, 1, to_write, stdout) < to_write)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
*current_column += to_write;
|
||||
written += to_write;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,21 +146,21 @@ do_encode (FILE *in, FILE *out, uintmax_t wrap_column)
|
||||
|
||||
sum = 0;
|
||||
do
|
||||
{
|
||||
n = fread (inbuf + sum, 1, BLOCKSIZE - sum, in);
|
||||
sum += n;
|
||||
}
|
||||
{
|
||||
n = fread (inbuf + sum, 1, BLOCKSIZE - sum, in);
|
||||
sum += n;
|
||||
}
|
||||
while (!feof (in) && !ferror (in) && sum < BLOCKSIZE);
|
||||
|
||||
if (sum > 0)
|
||||
{
|
||||
/* Process input one block at a time. Note that BLOCKSIZE %
|
||||
3 == 0, so that no base64 pads will appear in output. */
|
||||
base64_encode (inbuf, sum, outbuf, BASE64_LENGTH (sum));
|
||||
{
|
||||
/* Process input one block at a time. Note that BLOCKSIZE %
|
||||
3 == 0, so that no base64 pads will appear in output. */
|
||||
base64_encode (inbuf, sum, outbuf, BASE64_LENGTH (sum));
|
||||
|
||||
wrap_write (outbuf, BASE64_LENGTH (sum), wrap_column,
|
||||
¤t_column, out);
|
||||
}
|
||||
wrap_write (outbuf, BASE64_LENGTH (sum), wrap_column,
|
||||
¤t_column, out);
|
||||
}
|
||||
}
|
||||
while (!feof (in) && !ferror (in) && sum == BLOCKSIZE);
|
||||
|
||||
@@ -190,43 +190,43 @@ do_decode (FILE *in, FILE *out, bool ignore_garbage)
|
||||
|
||||
sum = 0;
|
||||
do
|
||||
{
|
||||
n = fread (inbuf + sum, 1, B64BLOCKSIZE - sum, in);
|
||||
{
|
||||
n = fread (inbuf + sum, 1, B64BLOCKSIZE - sum, in);
|
||||
|
||||
if (ignore_garbage)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; n > 0 && i < n;)
|
||||
if (isbase64 (inbuf[sum + i]) || inbuf[sum + i] == '=')
|
||||
i++;
|
||||
else
|
||||
memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
|
||||
}
|
||||
if (ignore_garbage)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; n > 0 && i < n;)
|
||||
if (isbase64 (inbuf[sum + i]) || inbuf[sum + i] == '=')
|
||||
i++;
|
||||
else
|
||||
memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
|
||||
}
|
||||
|
||||
sum += n;
|
||||
sum += n;
|
||||
|
||||
if (ferror (in))
|
||||
error (EXIT_FAILURE, errno, _("read error"));
|
||||
}
|
||||
if (ferror (in))
|
||||
error (EXIT_FAILURE, errno, _("read error"));
|
||||
}
|
||||
while (sum < B64BLOCKSIZE && !feof (in));
|
||||
|
||||
/* The following "loop" is usually iterated just once.
|
||||
However, when it processes the final input buffer, we want
|
||||
to iterate it one additional time, but with an indicator
|
||||
telling it to flush what is in CTX. */
|
||||
However, when it processes the final input buffer, we want
|
||||
to iterate it one additional time, but with an indicator
|
||||
telling it to flush what is in CTX. */
|
||||
for (k = 0; k < 1 + !!feof (in); k++)
|
||||
{
|
||||
if (k == 1 && ctx.i == 0)
|
||||
break;
|
||||
n = BLOCKSIZE;
|
||||
ok = base64_decode_ctx (&ctx, inbuf, (k == 0 ? sum : 0), outbuf, &n);
|
||||
{
|
||||
if (k == 1 && ctx.i == 0)
|
||||
break;
|
||||
n = BLOCKSIZE;
|
||||
ok = base64_decode_ctx (&ctx, inbuf, (k == 0 ? sum : 0), outbuf, &n);
|
||||
|
||||
if (fwrite (outbuf, 1, n, out) < n)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
if (fwrite (outbuf, 1, n, out) < n)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
|
||||
if (!ok)
|
||||
error (EXIT_FAILURE, 0, _("invalid input"));
|
||||
}
|
||||
if (!ok)
|
||||
error (EXIT_FAILURE, 0, _("invalid input"));
|
||||
}
|
||||
}
|
||||
while (!feof (in));
|
||||
}
|
||||
@@ -257,26 +257,26 @@ main (int argc, char **argv)
|
||||
switch (opt)
|
||||
{
|
||||
case 'd':
|
||||
decode = true;
|
||||
break;
|
||||
decode = true;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
if (xstrtoumax (optarg, NULL, 0, &wrap_column, NULL) != LONGINT_OK)
|
||||
error (EXIT_FAILURE, 0, _("invalid wrap size: %s"),
|
||||
quotearg (optarg));
|
||||
break;
|
||||
if (xstrtoumax (optarg, NULL, 0, &wrap_column, NULL) != LONGINT_OK)
|
||||
error (EXIT_FAILURE, 0, _("invalid wrap size: %s"),
|
||||
quotearg (optarg));
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
ignore_garbage = true;
|
||||
break;
|
||||
ignore_garbage = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc - optind > 1)
|
||||
@@ -296,7 +296,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
input_fh = fopen (infile, "r");
|
||||
if (input_fh == NULL)
|
||||
error (EXIT_FAILURE, errno, "%s", infile);
|
||||
error (EXIT_FAILURE, errno, "%s", infile);
|
||||
}
|
||||
|
||||
if (decode)
|
||||
@@ -307,9 +307,9 @@ main (int argc, char **argv)
|
||||
if (fclose (input_fh) == EOF)
|
||||
{
|
||||
if (STREQ (infile, "-"))
|
||||
error (EXIT_FAILURE, errno, _("closing standard input"));
|
||||
error (EXIT_FAILURE, errno, _("closing standard input"));
|
||||
else
|
||||
error (EXIT_FAILURE, errno, "%s", infile);
|
||||
error (EXIT_FAILURE, errno, "%s", infile);
|
||||
}
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
|
||||
+4
-4
@@ -44,14 +44,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s NAME [SUFFIX]\n\
|
||||
or: %s OPTION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Print NAME with any leading directory components removed.\n\
|
||||
If specified, also remove a trailing SUFFIX.\n\
|
||||
@@ -65,7 +65,7 @@ Examples:\n\
|
||||
%s /usr/bin/sort Output \"sort\".\n\
|
||||
%s include/stdio.h .h Output \"stdio\".\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -104,7 +104,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
|
||||
+36
-36
@@ -43,21 +43,21 @@ diff -upr src/remove.c src/remove.c
|
||||
&& ((x->interactive == RMI_ALWAYS) || x->stdin_tty)
|
||||
&& dirent_type != DT_LNK)
|
||||
@@ -889,6 +890,7 @@ prompt (int fd_cwd, Dirstack_state const
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+ {
|
||||
char const *quoted_name = quote (full_filename (filename));
|
||||
|
||||
if (write_protected < 0)
|
||||
@@ -928,6 +930,7 @@ prompt (int fd_cwd, Dirstack_state const
|
||||
: _("%s: remove %s %s? ")),
|
||||
program_name, file_type (sbuf), quoted_name);
|
||||
}
|
||||
: _("%s: remove %s %s? ")),
|
||||
program_name, file_type (sbuf), quoted_name);
|
||||
}
|
||||
+ }
|
||||
|
||||
if (!yesno ())
|
||||
return RM_USER_DECLINED;
|
||||
return RM_USER_DECLINED;
|
||||
@@ -1547,6 +1550,7 @@ rm_1 (Dirstack_state *ds, char const *fi
|
||||
return RM_ERROR;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ diff -upr src/remove.c src/remove.c
|
||||
|
||||
+ {
|
||||
enum RM_status status = remove_entry (AT_FDCWD, ds, filename,
|
||||
DT_UNKNOWN, &st, x);
|
||||
DT_UNKNOWN, &st, x);
|
||||
if (status == RM_NONEMPTY_DIR)
|
||||
@@ -1587,6 +1592,8 @@ rm_1 (Dirstack_state *ds, char const *fi
|
||||
ds_clear (ds);
|
||||
@@ -87,7 +87,7 @@ diff -upr src/rm.c src/rm.c
|
||||
--- src/rm.c 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ src/rm.c 1970-01-01 00:00:00.000000000 +0000
|
||||
@@ -354,6 +354,7 @@ main (int argc, char **argv)
|
||||
quote ("/"));
|
||||
quote ("/"));
|
||||
}
|
||||
|
||||
+ {
|
||||
@@ -96,7 +96,7 @@ diff -upr src/rm.c src/rm.c
|
||||
|
||||
@@ -367,7 +368,10 @@ main (int argc, char **argv)
|
||||
if (!yesno ())
|
||||
exit (EXIT_SUCCESS);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
+ {
|
||||
enum RM_status status = rm (n_files, file, &x);
|
||||
@@ -109,37 +109,37 @@ diff -upr src/seq.c src/seq.c
|
||||
--- src/seq.c 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ src/seq.c 1970-01-01 00:00:00.000000000 +0000
|
||||
@@ -163,6 +163,7 @@ scan_arg (const char *arg)
|
||||
: (decimal_point == arg /* .# -> 0.# */
|
||||
|| ! ISDIGIT (decimal_point[-1]))); /* -.# -> 0.# */
|
||||
}
|
||||
: (decimal_point == arg /* .# -> 0.# */
|
||||
|| ! ISDIGIT (decimal_point[-1]))); /* -.# -> 0.# */
|
||||
}
|
||||
+ {
|
||||
char const *e = strchr (arg, 'e');
|
||||
if (! e)
|
||||
e = strchr (arg, 'E');
|
||||
e = strchr (arg, 'E');
|
||||
@@ -171,6 +172,7 @@ scan_arg (const char *arg)
|
||||
long exponent = strtol (e + 1, NULL, 10);
|
||||
ret.precision += exponent < 0 ? -exponent : 0;
|
||||
}
|
||||
long exponent = strtol (e + 1, NULL, 10);
|
||||
ret.precision += exponent < 0 ? -exponent : 0;
|
||||
}
|
||||
+ }
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -346,6 +348,7 @@ get_default_format (operand first, opera
|
||||
size_t last_width = last.width + (prec - last.precision);
|
||||
if (last.precision && prec == 0)
|
||||
last_width--; /* don't include space for '.' */
|
||||
size_t last_width = last.width + (prec - last.precision);
|
||||
if (last.precision && prec == 0)
|
||||
last_width--; /* don't include space for '.' */
|
||||
+ {
|
||||
size_t width = MAX (first_width, last_width);
|
||||
if (width <= INT_MAX)
|
||||
{
|
||||
size_t width = MAX (first_width, last_width);
|
||||
if (width <= INT_MAX)
|
||||
{
|
||||
@@ -353,6 +356,7 @@ get_default_format (operand first, opera
|
||||
sprintf (format_buf, "%%0%d.%dLf", w, prec);
|
||||
return format_buf;
|
||||
}
|
||||
sprintf (format_buf, "%%0%d.%dLf", w, prec);
|
||||
return format_buf;
|
||||
}
|
||||
+ }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
@@ -441,6 +445,7 @@ main (int argc, char **argv)
|
||||
if (format_str)
|
||||
{
|
||||
@@ -147,10 +147,10 @@ diff -upr src/seq.c src/seq.c
|
||||
+ {
|
||||
char const *f = long_double_format (format_str, &layout);
|
||||
if (! f)
|
||||
{
|
||||
{
|
||||
@@ -448,6 +453,7 @@ main (int argc, char **argv)
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
format_str = f;
|
||||
+ }
|
||||
}
|
||||
@@ -160,11 +160,11 @@ diff -upr src/shred.c src/shred.c
|
||||
--- src/shred.c 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ src/shred.c 1970-01-01 00:00:00.000000000 +0000
|
||||
@@ -468,7 +468,7 @@ dopass (int fd, char const *qname, off_t
|
||||
out. Thus, it shouldn't give up on bad blocks. This
|
||||
code works because lim is always a multiple of
|
||||
SECTOR_SIZE, except at the end. */
|
||||
out. Thus, it shouldn't give up on bad blocks. This
|
||||
code works because lim is always a multiple of
|
||||
SECTOR_SIZE, except at the end. */
|
||||
- verify (sizeof r % SECTOR_SIZE == 0);
|
||||
+ { verify (sizeof r % SECTOR_SIZE == 0); }
|
||||
if (errnum == EIO && 0 <= size && (soff | SECTOR_MASK) < lim)
|
||||
{
|
||||
size_t soff1 = (soff | SECTOR_MASK) + 1;
|
||||
if (errnum == EIO && 0 <= size && (soff | SECTOR_MASK) < lim)
|
||||
{
|
||||
size_t soff1 = (soff | SECTOR_MASK) + 1;
|
||||
@@ -83,13 +83,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Concatenate FILE(s), or standard input, to standard output.\n\
|
||||
\n\
|
||||
@@ -118,7 +118,7 @@ Examples:\n\
|
||||
%s f - g Output f's contents, then standard input, then g's contents.\n\
|
||||
%s Copy standard input to standard output.\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -133,7 +133,7 @@ next_line_num (void)
|
||||
do
|
||||
{
|
||||
if ((*endp)++ < '9')
|
||||
return;
|
||||
return;
|
||||
*endp-- = '0';
|
||||
}
|
||||
while (endp >= line_num_start);
|
||||
@@ -168,23 +168,23 @@ simple_cat (
|
||||
|
||||
n_read = safe_read (input_desc, buf, bufsize);
|
||||
if (n_read == SAFE_READ_ERROR)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* End of this file? */
|
||||
|
||||
if (n_read == 0)
|
||||
return true;
|
||||
return true;
|
||||
|
||||
/* Write this block out. */
|
||||
|
||||
{
|
||||
/* The following is ok, since we know that 0 < n_read. */
|
||||
size_t n = n_read;
|
||||
if (full_write (STDOUT_FILENO, buf, n) != n)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
/* The following is ok, since we know that 0 < n_read. */
|
||||
size_t n = n_read;
|
||||
if (full_write (STDOUT_FILENO, buf, n) != n)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,227 +274,227 @@ cat (
|
||||
for (;;)
|
||||
{
|
||||
do
|
||||
{
|
||||
/* Write if there are at least OUTSIZE bytes in OUTBUF. */
|
||||
{
|
||||
/* Write if there are at least OUTSIZE bytes in OUTBUF. */
|
||||
|
||||
if (outbuf + outsize <= bpout)
|
||||
{
|
||||
char *wp = outbuf;
|
||||
size_t remaining_bytes;
|
||||
do
|
||||
{
|
||||
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
wp += outsize;
|
||||
remaining_bytes = bpout - wp;
|
||||
}
|
||||
while (outsize <= remaining_bytes);
|
||||
if (outbuf + outsize <= bpout)
|
||||
{
|
||||
char *wp = outbuf;
|
||||
size_t remaining_bytes;
|
||||
do
|
||||
{
|
||||
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
wp += outsize;
|
||||
remaining_bytes = bpout - wp;
|
||||
}
|
||||
while (outsize <= remaining_bytes);
|
||||
|
||||
/* Move the remaining bytes to the beginning of the
|
||||
buffer. */
|
||||
/* Move the remaining bytes to the beginning of the
|
||||
buffer. */
|
||||
|
||||
memmove (outbuf, wp, remaining_bytes);
|
||||
bpout = outbuf + remaining_bytes;
|
||||
}
|
||||
memmove (outbuf, wp, remaining_bytes);
|
||||
bpout = outbuf + remaining_bytes;
|
||||
}
|
||||
|
||||
/* Is INBUF empty? */
|
||||
/* Is INBUF empty? */
|
||||
|
||||
if (bpin > eob)
|
||||
{
|
||||
bool input_pending = false;
|
||||
if (bpin > eob)
|
||||
{
|
||||
bool input_pending = false;
|
||||
#ifdef FIONREAD
|
||||
int n_to_read = 0;
|
||||
int n_to_read = 0;
|
||||
|
||||
/* Is there any input to read immediately?
|
||||
If not, we are about to wait,
|
||||
so write all buffered output before waiting. */
|
||||
/* Is there any input to read immediately?
|
||||
If not, we are about to wait,
|
||||
so write all buffered output before waiting. */
|
||||
|
||||
if (use_fionread
|
||||
&& ioctl (input_desc, FIONREAD, &n_to_read) < 0)
|
||||
{
|
||||
/* Ultrix returns EOPNOTSUPP on NFS;
|
||||
HP-UX returns ENOTTY on pipes.
|
||||
SunOS returns EINVAL and
|
||||
More/BSD returns ENODEV on special files
|
||||
like /dev/null.
|
||||
Irix-5 returns ENOSYS on pipes. */
|
||||
if (errno == EOPNOTSUPP || errno == ENOTTY
|
||||
|| errno == EINVAL || errno == ENODEV
|
||||
|| errno == ENOSYS)
|
||||
use_fionread = false;
|
||||
else
|
||||
{
|
||||
error (0, errno, _("cannot do ioctl on %s"), quote (infile));
|
||||
newlines2 = newlines;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (n_to_read != 0)
|
||||
input_pending = true;
|
||||
if (use_fionread
|
||||
&& ioctl (input_desc, FIONREAD, &n_to_read) < 0)
|
||||
{
|
||||
/* Ultrix returns EOPNOTSUPP on NFS;
|
||||
HP-UX returns ENOTTY on pipes.
|
||||
SunOS returns EINVAL and
|
||||
More/BSD returns ENODEV on special files
|
||||
like /dev/null.
|
||||
Irix-5 returns ENOSYS on pipes. */
|
||||
if (errno == EOPNOTSUPP || errno == ENOTTY
|
||||
|| errno == EINVAL || errno == ENODEV
|
||||
|| errno == ENOSYS)
|
||||
use_fionread = false;
|
||||
else
|
||||
{
|
||||
error (0, errno, _("cannot do ioctl on %s"), quote (infile));
|
||||
newlines2 = newlines;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (n_to_read != 0)
|
||||
input_pending = true;
|
||||
#endif
|
||||
|
||||
if (!input_pending)
|
||||
write_pending (outbuf, &bpout);
|
||||
if (!input_pending)
|
||||
write_pending (outbuf, &bpout);
|
||||
|
||||
/* Read more input into INBUF. */
|
||||
/* Read more input into INBUF. */
|
||||
|
||||
n_read = safe_read (input_desc, inbuf, insize);
|
||||
if (n_read == SAFE_READ_ERROR)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
write_pending (outbuf, &bpout);
|
||||
newlines2 = newlines;
|
||||
return false;
|
||||
}
|
||||
if (n_read == 0)
|
||||
{
|
||||
write_pending (outbuf, &bpout);
|
||||
newlines2 = newlines;
|
||||
return true;
|
||||
}
|
||||
n_read = safe_read (input_desc, inbuf, insize);
|
||||
if (n_read == SAFE_READ_ERROR)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
write_pending (outbuf, &bpout);
|
||||
newlines2 = newlines;
|
||||
return false;
|
||||
}
|
||||
if (n_read == 0)
|
||||
{
|
||||
write_pending (outbuf, &bpout);
|
||||
newlines2 = newlines;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Update the pointers and insert a sentinel at the buffer
|
||||
end. */
|
||||
/* Update the pointers and insert a sentinel at the buffer
|
||||
end. */
|
||||
|
||||
bpin = inbuf;
|
||||
eob = bpin + n_read;
|
||||
*eob = '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* It was a real (not a sentinel) newline. */
|
||||
bpin = inbuf;
|
||||
eob = bpin + n_read;
|
||||
*eob = '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* It was a real (not a sentinel) newline. */
|
||||
|
||||
/* Was the last line empty?
|
||||
(i.e. have two or more consecutive newlines been read?) */
|
||||
/* Was the last line empty?
|
||||
(i.e. have two or more consecutive newlines been read?) */
|
||||
|
||||
if (++newlines > 0)
|
||||
{
|
||||
if (newlines >= 2)
|
||||
{
|
||||
/* Limit this to 2 here. Otherwise, with lots of
|
||||
consecutive newlines, the counter could wrap
|
||||
around at INT_MAX. */
|
||||
newlines = 2;
|
||||
if (++newlines > 0)
|
||||
{
|
||||
if (newlines >= 2)
|
||||
{
|
||||
/* Limit this to 2 here. Otherwise, with lots of
|
||||
consecutive newlines, the counter could wrap
|
||||
around at INT_MAX. */
|
||||
newlines = 2;
|
||||
|
||||
/* Are multiple adjacent empty lines to be substituted
|
||||
by single ditto (-s), and this was the second empty
|
||||
line? */
|
||||
if (squeeze_blank)
|
||||
{
|
||||
ch = *bpin++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* Are multiple adjacent empty lines to be substituted
|
||||
by single ditto (-s), and this was the second empty
|
||||
line? */
|
||||
if (squeeze_blank)
|
||||
{
|
||||
ch = *bpin++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Are line numbers to be written at empty lines (-n)? */
|
||||
/* Are line numbers to be written at empty lines (-n)? */
|
||||
|
||||
if (number & !number_nonblank)
|
||||
{
|
||||
next_line_num ();
|
||||
bpout = stpcpy (bpout, line_num_print);
|
||||
}
|
||||
}
|
||||
if (number & !number_nonblank)
|
||||
{
|
||||
next_line_num ();
|
||||
bpout = stpcpy (bpout, line_num_print);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output a currency symbol if requested (-e). */
|
||||
/* Output a currency symbol if requested (-e). */
|
||||
|
||||
if (show_ends)
|
||||
*bpout++ = '$';
|
||||
if (show_ends)
|
||||
*bpout++ = '$';
|
||||
|
||||
/* Output the newline. */
|
||||
/* Output the newline. */
|
||||
|
||||
*bpout++ = '\n';
|
||||
}
|
||||
ch = *bpin++;
|
||||
}
|
||||
*bpout++ = '\n';
|
||||
}
|
||||
ch = *bpin++;
|
||||
}
|
||||
while (ch == '\n');
|
||||
|
||||
/* Are we at the beginning of a line, and line numbers are requested? */
|
||||
|
||||
if (newlines >= 0 && number)
|
||||
{
|
||||
next_line_num ();
|
||||
bpout = stpcpy (bpout, line_num_print);
|
||||
}
|
||||
{
|
||||
next_line_num ();
|
||||
bpout = stpcpy (bpout, line_num_print);
|
||||
}
|
||||
|
||||
/* Here CH cannot contain a newline character. */
|
||||
|
||||
/* The loops below continue until a newline character is found,
|
||||
which means that the buffer is empty or that a proper newline
|
||||
has been found. */
|
||||
which means that the buffer is empty or that a proper newline
|
||||
has been found. */
|
||||
|
||||
/* If quoting, i.e. at least one of -v, -e, or -t specified,
|
||||
scan for chars that need conversion. */
|
||||
scan for chars that need conversion. */
|
||||
if (show_nonprinting)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (ch >= 32)
|
||||
{
|
||||
if (ch < 127)
|
||||
*bpout++ = ch;
|
||||
else if (ch == 127)
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
*bpout++ = 'M';
|
||||
*bpout++ = '-';
|
||||
if (ch >= 128 + 32)
|
||||
{
|
||||
if (ch < 128 + 127)
|
||||
*bpout++ = ch - 128;
|
||||
else
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = '?';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch - 128 + 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ch == '\t' && !show_tabs)
|
||||
*bpout++ = '\t';
|
||||
else if (ch == '\n')
|
||||
{
|
||||
newlines = -1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch + 64;
|
||||
}
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (ch >= 32)
|
||||
{
|
||||
if (ch < 127)
|
||||
*bpout++ = ch;
|
||||
else if (ch == 127)
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
*bpout++ = 'M';
|
||||
*bpout++ = '-';
|
||||
if (ch >= 128 + 32)
|
||||
{
|
||||
if (ch < 128 + 127)
|
||||
*bpout++ = ch - 128;
|
||||
else
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = '?';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch - 128 + 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ch == '\t' && !show_tabs)
|
||||
*bpout++ = '\t';
|
||||
else if (ch == '\n')
|
||||
{
|
||||
newlines = -1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch + 64;
|
||||
}
|
||||
|
||||
ch = *bpin++;
|
||||
}
|
||||
}
|
||||
ch = *bpin++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not quoting, neither of -v, -e, or -t specified. */
|
||||
for (;;)
|
||||
{
|
||||
if (ch == '\t' && show_tabs)
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch + 64;
|
||||
}
|
||||
else if (ch != '\n')
|
||||
*bpout++ = ch;
|
||||
else
|
||||
{
|
||||
newlines = -1;
|
||||
break;
|
||||
}
|
||||
{
|
||||
/* Not quoting, neither of -v, -e, or -t specified. */
|
||||
for (;;)
|
||||
{
|
||||
if (ch == '\t' && show_tabs)
|
||||
{
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch + 64;
|
||||
}
|
||||
else if (ch != '\n')
|
||||
*bpout++ = ch;
|
||||
else
|
||||
{
|
||||
newlines = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
ch = *bpin++;
|
||||
}
|
||||
}
|
||||
ch = *bpin++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,62 +573,62 @@ main (int argc, char **argv)
|
||||
/* Parse command line options. */
|
||||
|
||||
while ((c = getopt_long (argc, argv, "benstuvAET", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
number = true;
|
||||
number_nonblank = true;
|
||||
break;
|
||||
{
|
||||
case 'b':
|
||||
number = true;
|
||||
number_nonblank = true;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
show_ends = true;
|
||||
show_nonprinting = true;
|
||||
break;
|
||||
case 'e':
|
||||
show_ends = true;
|
||||
show_nonprinting = true;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
number = true;
|
||||
break;
|
||||
case 'n':
|
||||
number = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
squeeze_blank = true;
|
||||
break;
|
||||
case 's':
|
||||
squeeze_blank = true;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
show_tabs = true;
|
||||
show_nonprinting = true;
|
||||
break;
|
||||
case 't':
|
||||
show_tabs = true;
|
||||
show_nonprinting = true;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
/* We provide the -u feature unconditionally. */
|
||||
break;
|
||||
case 'u':
|
||||
/* We provide the -u feature unconditionally. */
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
show_nonprinting = true;
|
||||
break;
|
||||
case 'v':
|
||||
show_nonprinting = true;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
show_nonprinting = true;
|
||||
show_ends = true;
|
||||
show_tabs = true;
|
||||
break;
|
||||
case 'A':
|
||||
show_nonprinting = true;
|
||||
show_ends = true;
|
||||
show_tabs = true;
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
show_ends = true;
|
||||
break;
|
||||
case 'E':
|
||||
show_ends = true;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
show_tabs = true;
|
||||
break;
|
||||
case 'T':
|
||||
show_tabs = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get device, i-node number, and optimal blocksize of output. */
|
||||
@@ -661,7 +661,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
file_open_mode |= O_BINARY;
|
||||
if (O_BINARY && ! isatty (STDOUT_FILENO))
|
||||
xfreopen (NULL, "wb", stdout);
|
||||
xfreopen (NULL, "wb", stdout);
|
||||
}
|
||||
|
||||
/* Check if any of the input files are the same as the output file. */
|
||||
@@ -674,104 +674,104 @@ main (int argc, char **argv)
|
||||
do
|
||||
{
|
||||
if (argind < argc)
|
||||
infile = argv[argind];
|
||||
infile = argv[argind];
|
||||
|
||||
if (STREQ (infile, "-"))
|
||||
{
|
||||
have_read_stdin = true;
|
||||
input_desc = STDIN_FILENO;
|
||||
if ((file_open_mode & O_BINARY) && ! isatty (STDIN_FILENO))
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
{
|
||||
have_read_stdin = true;
|
||||
input_desc = STDIN_FILENO;
|
||||
if ((file_open_mode & O_BINARY) && ! isatty (STDIN_FILENO))
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
input_desc = open (infile, file_open_mode);
|
||||
if (input_desc < 0)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
{
|
||||
input_desc = open (infile, file_open_mode);
|
||||
if (input_desc < 0)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (fstat (input_desc, &stat_buf) < 0)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
ok = false;
|
||||
goto contin;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
ok = false;
|
||||
goto contin;
|
||||
}
|
||||
insize = io_blksize (stat_buf);
|
||||
|
||||
/* Compare the device and i-node numbers of this input file with
|
||||
the corresponding values of the (output file associated with)
|
||||
stdout, and skip this input file if they coincide. Input
|
||||
files cannot be redirected to themselves. */
|
||||
the corresponding values of the (output file associated with)
|
||||
stdout, and skip this input file if they coincide. Input
|
||||
files cannot be redirected to themselves. */
|
||||
|
||||
if (check_redirection
|
||||
&& stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino
|
||||
&& (input_desc != STDIN_FILENO))
|
||||
{
|
||||
error (0, 0, _("%s: input file is output file"), infile);
|
||||
ok = false;
|
||||
goto contin;
|
||||
}
|
||||
&& stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino
|
||||
&& (input_desc != STDIN_FILENO))
|
||||
{
|
||||
error (0, 0, _("%s: input file is output file"), infile);
|
||||
ok = false;
|
||||
goto contin;
|
||||
}
|
||||
|
||||
/* Select which version of `cat' to use. If any format-oriented
|
||||
options were given use `cat'; otherwise use `simple_cat'. */
|
||||
options were given use `cat'; otherwise use `simple_cat'. */
|
||||
|
||||
if (! (number | show_ends | show_nonprinting
|
||||
| show_tabs | squeeze_blank))
|
||||
{
|
||||
insize = MAX (insize, outsize);
|
||||
inbuf = xmalloc (insize + page_size - 1);
|
||||
| show_tabs | squeeze_blank))
|
||||
{
|
||||
insize = MAX (insize, outsize);
|
||||
inbuf = xmalloc (insize + page_size - 1);
|
||||
|
||||
ok &= simple_cat (ptr_align (inbuf, page_size), insize);
|
||||
}
|
||||
ok &= simple_cat (ptr_align (inbuf, page_size), insize);
|
||||
}
|
||||
else
|
||||
{
|
||||
inbuf = xmalloc (insize + 1 + page_size - 1);
|
||||
{
|
||||
inbuf = xmalloc (insize + 1 + page_size - 1);
|
||||
|
||||
/* Why are
|
||||
(OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN + PAGE_SIZE - 1)
|
||||
bytes allocated for the output buffer?
|
||||
/* Why are
|
||||
(OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN + PAGE_SIZE - 1)
|
||||
bytes allocated for the output buffer?
|
||||
|
||||
A test whether output needs to be written is done when the input
|
||||
buffer empties or when a newline appears in the input. After
|
||||
output is written, at most (OUTSIZE - 1) bytes will remain in the
|
||||
buffer. Now INSIZE bytes of input is read. Each input character
|
||||
may grow by a factor of 4 (by the prepending of M-^). If all
|
||||
characters do, and no newlines appear in this block of input, we
|
||||
will have at most (OUTSIZE - 1 + INSIZE * 4) bytes in the buffer.
|
||||
If the last character in the preceding block of input was a
|
||||
newline, a line number may be written (according to the given
|
||||
options) as the first thing in the output buffer. (Done after the
|
||||
new input is read, but before processing of the input begins.)
|
||||
A line number requires seldom more than LINE_COUNTER_BUF_LEN
|
||||
positions.
|
||||
A test whether output needs to be written is done when the input
|
||||
buffer empties or when a newline appears in the input. After
|
||||
output is written, at most (OUTSIZE - 1) bytes will remain in the
|
||||
buffer. Now INSIZE bytes of input is read. Each input character
|
||||
may grow by a factor of 4 (by the prepending of M-^). If all
|
||||
characters do, and no newlines appear in this block of input, we
|
||||
will have at most (OUTSIZE - 1 + INSIZE * 4) bytes in the buffer.
|
||||
If the last character in the preceding block of input was a
|
||||
newline, a line number may be written (according to the given
|
||||
options) as the first thing in the output buffer. (Done after the
|
||||
new input is read, but before processing of the input begins.)
|
||||
A line number requires seldom more than LINE_COUNTER_BUF_LEN
|
||||
positions.
|
||||
|
||||
Align the output buffer to a page size boundary, for efficency on
|
||||
some paging implementations, so add PAGE_SIZE - 1 bytes to the
|
||||
request to make room for the alignment. */
|
||||
Align the output buffer to a page size boundary, for efficency on
|
||||
some paging implementations, so add PAGE_SIZE - 1 bytes to the
|
||||
request to make room for the alignment. */
|
||||
|
||||
outbuf = xmalloc (outsize - 1 + insize * 4 + LINE_COUNTER_BUF_LEN
|
||||
+ page_size - 1);
|
||||
outbuf = xmalloc (outsize - 1 + insize * 4 + LINE_COUNTER_BUF_LEN
|
||||
+ page_size - 1);
|
||||
|
||||
ok &= cat (ptr_align (inbuf, page_size), insize,
|
||||
ptr_align (outbuf, page_size), outsize, show_nonprinting,
|
||||
show_tabs, number, number_nonblank, show_ends,
|
||||
squeeze_blank);
|
||||
ok &= cat (ptr_align (inbuf, page_size), insize,
|
||||
ptr_align (outbuf, page_size), outsize, show_nonprinting,
|
||||
show_tabs, number, number_nonblank, show_ends,
|
||||
squeeze_blank);
|
||||
|
||||
free (outbuf);
|
||||
}
|
||||
free (outbuf);
|
||||
}
|
||||
|
||||
free (inbuf);
|
||||
|
||||
contin:
|
||||
if (!STREQ (infile, "-") && close (input_desc) < 0)
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", infile);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
while (++argind < argc);
|
||||
|
||||
|
||||
+146
-146
@@ -97,7 +97,7 @@ compute_context_from_mask (security_context_t context, context_t *ret)
|
||||
if (!new_context)
|
||||
{
|
||||
error (0, errno, _("failed to create security context: %s"),
|
||||
quotearg_colon (context));
|
||||
quotearg_colon (context));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -105,13 +105,13 @@ compute_context_from_mask (security_context_t context, context_t *ret)
|
||||
do \
|
||||
{ \
|
||||
if (specified_ ## comp \
|
||||
&& context_ ## comp ## _set ((C), specified_ ## comp)) \
|
||||
&& context_ ## comp ## _set ((C), specified_ ## comp)) \
|
||||
{ \
|
||||
error (0, errno, \
|
||||
_("failed to set %s security context component to %s"), \
|
||||
#comp, quote (specified_ ## comp)); \
|
||||
error (0, errno, \
|
||||
_("failed to set %s security context component to %s"), \
|
||||
#comp, quote (specified_ ## comp)); \
|
||||
ok = false; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -147,35 +147,35 @@ change_file_context (int fd, char const *file)
|
||||
if (specified_context == NULL)
|
||||
{
|
||||
int status = (affect_symlink_referent
|
||||
? getfileconat (fd, file, &file_context)
|
||||
: lgetfileconat (fd, file, &file_context));
|
||||
? getfileconat (fd, file, &file_context)
|
||||
: lgetfileconat (fd, file, &file_context));
|
||||
|
||||
if (status < 0 && errno != ENODATA)
|
||||
{
|
||||
error (0, errno, _("failed to get security context of %s"),
|
||||
quote (file));
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("failed to get security context of %s"),
|
||||
quote (file));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* If the file doesn't have a context, and we're not setting all of
|
||||
the context components, there isn't really an obvious default.
|
||||
Thus, we just give up. */
|
||||
the context components, there isn't really an obvious default.
|
||||
Thus, we just give up. */
|
||||
if (file_context == NULL)
|
||||
{
|
||||
error (0, 0, _("can't apply partial context to unlabeled file %s"),
|
||||
quote (file));
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("can't apply partial context to unlabeled file %s"),
|
||||
quote (file));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (compute_context_from_mask (file_context, &context))
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* FIXME: this should be done exactly once, in main. */
|
||||
context = context_new (specified_context);
|
||||
if (!context)
|
||||
abort ();
|
||||
abort ();
|
||||
}
|
||||
|
||||
context_string = context_str (context);
|
||||
@@ -183,15 +183,15 @@ change_file_context (int fd, char const *file)
|
||||
if (file_context == NULL || ! STREQ (context_string, file_context))
|
||||
{
|
||||
int fail = (affect_symlink_referent
|
||||
? setfileconat (fd, file, context_string)
|
||||
: lsetfileconat (fd, file, context_string));
|
||||
? setfileconat (fd, file, context_string)
|
||||
: lsetfileconat (fd, file, context_string));
|
||||
|
||||
if (fail)
|
||||
{
|
||||
errors = 1;
|
||||
error (0, errno, _("failed to change context of %s to %s"),
|
||||
quote_n (0, file), quote_n (1, context_string));
|
||||
}
|
||||
{
|
||||
errors = 1;
|
||||
error (0, errno, _("failed to change context of %s to %s"),
|
||||
quote_n (0, file), quote_n (1, context_string));
|
||||
}
|
||||
}
|
||||
|
||||
context_free (context);
|
||||
@@ -216,41 +216,41 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
{
|
||||
case FTS_D:
|
||||
if (recurse)
|
||||
{
|
||||
if (ROOT_DEV_INO_CHECK (root_dev_ino, ent->fts_statp))
|
||||
{
|
||||
/* This happens e.g., with "chcon -R --preserve-root ... /"
|
||||
and with "chcon -RH --preserve-root ... symlink-to-root". */
|
||||
ROOT_DEV_INO_WARN (file_full_name);
|
||||
/* Tell fts not to traverse into this hierarchy. */
|
||||
fts_set (fts, ent, FTS_SKIP);
|
||||
/* Ensure that we do not process "/" on the second visit. */
|
||||
ent = fts_read (fts);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
{
|
||||
if (ROOT_DEV_INO_CHECK (root_dev_ino, ent->fts_statp))
|
||||
{
|
||||
/* This happens e.g., with "chcon -R --preserve-root ... /"
|
||||
and with "chcon -RH --preserve-root ... symlink-to-root". */
|
||||
ROOT_DEV_INO_WARN (file_full_name);
|
||||
/* Tell fts not to traverse into this hierarchy. */
|
||||
fts_set (fts, ent, FTS_SKIP);
|
||||
/* Ensure that we do not process "/" on the second visit. */
|
||||
ent = fts_read (fts);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FTS_DP:
|
||||
if (! recurse)
|
||||
return true;
|
||||
return true;
|
||||
break;
|
||||
|
||||
case FTS_NS:
|
||||
/* For a top-level file or directory, this FTS_NS (stat failed)
|
||||
indicator is determined at the time of the initial fts_open call.
|
||||
With programs like chmod, chown, and chgrp, that modify
|
||||
permissions, it is possible that the file in question is
|
||||
accessible when control reaches this point. So, if this is
|
||||
the first time we've seen the FTS_NS for this file, tell
|
||||
fts_read to stat it "again". */
|
||||
indicator is determined at the time of the initial fts_open call.
|
||||
With programs like chmod, chown, and chgrp, that modify
|
||||
permissions, it is possible that the file in question is
|
||||
accessible when control reaches this point. So, if this is
|
||||
the first time we've seen the FTS_NS for this file, tell
|
||||
fts_read to stat it "again". */
|
||||
if (ent->fts_level == 0 && ent->fts_number == 0)
|
||||
{
|
||||
ent->fts_number = 1;
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
ent->fts_number = 1;
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
error (0, ent->fts_errno, _("cannot access %s"), quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
@@ -262,7 +262,7 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
|
||||
case FTS_DNR:
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
@@ -280,11 +280,11 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
if (ok)
|
||||
{
|
||||
if (verbose)
|
||||
printf (_("changing security context of %s\n"),
|
||||
quote (file_full_name));
|
||||
printf (_("changing security context of %s\n"),
|
||||
quote (file_full_name));
|
||||
|
||||
if (change_file_context (fts->fts_cwd_fd, file) != 0)
|
||||
ok = false;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if ( ! recurse)
|
||||
@@ -310,15 +310,15 @@ process_files (char **files, int bit_flags)
|
||||
|
||||
ent = fts_read (fts);
|
||||
if (ent == NULL)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ok &= process_file (fts, ent);
|
||||
}
|
||||
@@ -336,7 +336,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -344,7 +344,7 @@ Usage: %s [OPTION]... CONTEXT FILE...\n\
|
||||
or: %s [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE...\n\
|
||||
or: %s [OPTION]... --reference=RFILE FILE...\n\
|
||||
"),
|
||||
program_name, program_name, program_name);
|
||||
program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
Change the security context of each FILE to CONTEXT.\n\
|
||||
With --reference, change the security context of each FILE to that of RFILE.\n\
|
||||
@@ -410,97 +410,97 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "HLPRhvu:r:t:l:", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'H': /* Traverse command-line symlinks-to-directories. */
|
||||
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
{
|
||||
case 'H': /* Traverse command-line symlinks-to-directories. */
|
||||
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'L': /* Traverse all symlinks-to-directories. */
|
||||
bit_flags = FTS_LOGICAL;
|
||||
break;
|
||||
case 'L': /* Traverse all symlinks-to-directories. */
|
||||
bit_flags = FTS_LOGICAL;
|
||||
break;
|
||||
|
||||
case 'P': /* Traverse no symlinks-to-directories. */
|
||||
bit_flags = FTS_PHYSICAL;
|
||||
break;
|
||||
case 'P': /* Traverse no symlinks-to-directories. */
|
||||
bit_flags = FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'h': /* --no-dereference: affect symlinks */
|
||||
dereference = 0;
|
||||
break;
|
||||
case 'h': /* --no-dereference: affect symlinks */
|
||||
dereference = 0;
|
||||
break;
|
||||
|
||||
case DEREFERENCE_OPTION: /* --dereference: affect the referent
|
||||
of each symlink */
|
||||
dereference = 1;
|
||||
break;
|
||||
case DEREFERENCE_OPTION: /* --dereference: affect the referent
|
||||
of each symlink */
|
||||
dereference = 1;
|
||||
break;
|
||||
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
recurse = true;
|
||||
break;
|
||||
case 'R':
|
||||
recurse = true;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
/* ignore */
|
||||
break;
|
||||
case 'f':
|
||||
/* ignore */
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
specified_user = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
case 'u':
|
||||
specified_user = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
specified_role = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
case 'r':
|
||||
specified_role = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
specified_type = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
case 't':
|
||||
specified_type = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
specified_range = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
case 'l':
|
||||
specified_range = optarg;
|
||||
component_specified = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (recurse)
|
||||
{
|
||||
if (bit_flags == FTS_PHYSICAL)
|
||||
{
|
||||
if (dereference == 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("-R --dereference requires either -H or -L"));
|
||||
affect_symlink_referent = false;
|
||||
}
|
||||
{
|
||||
if (dereference == 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("-R --dereference requires either -H or -L"));
|
||||
affect_symlink_referent = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dereference == 0)
|
||||
error (EXIT_FAILURE, 0, _("-R -h requires -P"));
|
||||
affect_symlink_referent = true;
|
||||
}
|
||||
{
|
||||
if (dereference == 0)
|
||||
error (EXIT_FAILURE, 0, _("-R -h requires -P"));
|
||||
affect_symlink_referent = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -511,17 +511,17 @@ main (int argc, char **argv)
|
||||
if (argc - optind < (reference_file || component_specified ? 1 : 2))
|
||||
{
|
||||
if (argc <= optind)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (reference_file)
|
||||
{
|
||||
if (getfilecon (reference_file, &ref_context) < 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to get security context of %s"),
|
||||
quote (reference_file));
|
||||
error (EXIT_FAILURE, errno, _("failed to get security context of %s"),
|
||||
quote (reference_file));
|
||||
|
||||
specified_context = ref_context;
|
||||
}
|
||||
@@ -536,8 +536,8 @@ main (int argc, char **argv)
|
||||
specified_context = argv[optind++];
|
||||
context = context_new (specified_context);
|
||||
if (!context)
|
||||
error (EXIT_FAILURE, 0, _("invalid context: %s"),
|
||||
quotearg_colon (specified_context));
|
||||
error (EXIT_FAILURE, 0, _("invalid context: %s"),
|
||||
quotearg_colon (specified_context));
|
||||
context_free (context);
|
||||
}
|
||||
|
||||
@@ -552,8 +552,8 @@ main (int argc, char **argv)
|
||||
static struct dev_ino dev_ino_buf;
|
||||
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
|
||||
if (root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+69
-69
@@ -84,15 +84,15 @@ parse_group (const char *name)
|
||||
{
|
||||
struct group *grp = getgrnam (name);
|
||||
if (grp)
|
||||
gid = grp->gr_gid;
|
||||
gid = grp->gr_gid;
|
||||
else
|
||||
{
|
||||
unsigned long int tmp;
|
||||
if (! (xstrtoul (name, NULL, 10, &tmp, "") == LONGINT_OK
|
||||
&& tmp <= GID_T_MAX))
|
||||
error (EXIT_FAILURE, 0, _("invalid group: %s"), quote (name));
|
||||
gid = tmp;
|
||||
}
|
||||
{
|
||||
unsigned long int tmp;
|
||||
if (! (xstrtoul (name, NULL, 10, &tmp, "") == LONGINT_OK
|
||||
&& tmp <= GID_T_MAX))
|
||||
error (EXIT_FAILURE, 0, _("invalid group: %s"), quote (name));
|
||||
gid = tmp;
|
||||
}
|
||||
endgrent (); /* Save a file descriptor. */
|
||||
}
|
||||
|
||||
@@ -104,14 +104,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... GROUP FILE...\n\
|
||||
or: %s [OPTION]... --reference=RFILE FILE...\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Change the group of each FILE to GROUP.\n\
|
||||
With --reference, change the group of each FILE to that of RFILE.\n\
|
||||
@@ -157,7 +157,7 @@ Examples:\n\
|
||||
%s staff /u Change the group of /u to \"staff\".\n\
|
||||
%s -hR staff /u Change the group of /u and subfiles to \"staff\".\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -191,75 +191,75 @@ main (int argc, char **argv)
|
||||
chopt_init (&chopt);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'H': /* Traverse command-line symlinks-to-directories. */
|
||||
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
{
|
||||
case 'H': /* Traverse command-line symlinks-to-directories. */
|
||||
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'L': /* Traverse all symlinks-to-directories. */
|
||||
bit_flags = FTS_LOGICAL;
|
||||
break;
|
||||
case 'L': /* Traverse all symlinks-to-directories. */
|
||||
bit_flags = FTS_LOGICAL;
|
||||
break;
|
||||
|
||||
case 'P': /* Traverse no symlinks-to-directories. */
|
||||
bit_flags = FTS_PHYSICAL;
|
||||
break;
|
||||
case 'P': /* Traverse no symlinks-to-directories. */
|
||||
bit_flags = FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'h': /* --no-dereference: affect symlinks */
|
||||
dereference = 0;
|
||||
break;
|
||||
case 'h': /* --no-dereference: affect symlinks */
|
||||
dereference = 0;
|
||||
break;
|
||||
|
||||
case DEREFERENCE_OPTION: /* --dereference: affect the referent
|
||||
of each symlink */
|
||||
dereference = 1;
|
||||
break;
|
||||
case DEREFERENCE_OPTION: /* --dereference: affect the referent
|
||||
of each symlink */
|
||||
dereference = 1;
|
||||
break;
|
||||
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
chopt.recurse = true;
|
||||
break;
|
||||
case 'R':
|
||||
chopt.recurse = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
chopt.verbosity = V_changes_only;
|
||||
break;
|
||||
case 'c':
|
||||
chopt.verbosity = V_changes_only;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
chopt.force_silent = true;
|
||||
break;
|
||||
case 'f':
|
||||
chopt.force_silent = true;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
chopt.verbosity = V_high;
|
||||
break;
|
||||
case 'v':
|
||||
chopt.verbosity = V_high;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (chopt.recurse)
|
||||
{
|
||||
if (bit_flags == FTS_PHYSICAL)
|
||||
{
|
||||
if (dereference == 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("-R --dereference requires either -H or -L"));
|
||||
dereference = 0;
|
||||
}
|
||||
{
|
||||
if (dereference == 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("-R --dereference requires either -H or -L"));
|
||||
dereference = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -270,9 +270,9 @@ main (int argc, char **argv)
|
||||
if (argc - optind < (reference_file ? 1 : 2))
|
||||
{
|
||||
if (argc <= optind)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -280,8 +280,8 @@ main (int argc, char **argv)
|
||||
{
|
||||
struct stat ref_stats;
|
||||
if (stat (reference_file, &ref_stats))
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote (reference_file));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote (reference_file));
|
||||
|
||||
gid = ref_stats.st_gid;
|
||||
chopt.group_name = gid_to_name (ref_stats.st_gid);
|
||||
@@ -298,14 +298,14 @@ main (int argc, char **argv)
|
||||
static struct dev_ino dev_ino_buf;
|
||||
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
|
||||
if (chopt.root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
}
|
||||
|
||||
bit_flags |= FTS_DEFER_STAT;
|
||||
ok = chown_files (argv + optind, bit_flags,
|
||||
(uid_t) -1, gid,
|
||||
(uid_t) -1, (gid_t) -1, &chopt);
|
||||
(uid_t) -1, gid,
|
||||
(uid_t) -1, (gid_t) -1, &chopt);
|
||||
|
||||
chopt_free (&chopt);
|
||||
|
||||
|
||||
+152
-152
@@ -115,16 +115,16 @@ mode_changed (char const *file, mode_t old_mode, mode_t new_mode)
|
||||
if (new_mode & (S_ISUID | S_ISGID | S_ISVTX))
|
||||
{
|
||||
/* The new mode contains unusual bits that the call to chmod may
|
||||
have silently cleared. Check whether they actually changed. */
|
||||
have silently cleared. Check whether they actually changed. */
|
||||
|
||||
struct stat new_stats;
|
||||
|
||||
if (stat (file, &new_stats) != 0)
|
||||
{
|
||||
if (! force_silent)
|
||||
error (0, errno, _("getting new attributes of %s"), quote (file));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
if (! force_silent)
|
||||
error (0, errno, _("getting new attributes of %s"), quote (file));
|
||||
return false;
|
||||
}
|
||||
|
||||
new_mode = new_stats.st_mode;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ mode_changed (char const *file, mode_t old_mode, mode_t new_mode)
|
||||
|
||||
static void
|
||||
describe_change (const char *file, mode_t mode,
|
||||
enum Change_status changed)
|
||||
enum Change_status changed)
|
||||
{
|
||||
char perms[12]; /* "-rwxrwxrwx" ls-style modes. */
|
||||
const char *fmt;
|
||||
@@ -145,7 +145,7 @@ describe_change (const char *file, mode_t mode,
|
||||
if (changed == CH_NOT_APPLIED)
|
||||
{
|
||||
printf (_("neither symbolic link %s nor referent has been changed\n"),
|
||||
quote (file));
|
||||
quote (file));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ describe_change (const char *file, mode_t mode,
|
||||
abort ();
|
||||
}
|
||||
printf (fmt, quote (file),
|
||||
(unsigned long int) (mode & CHMOD_MODE_BITS), &perms[1]);
|
||||
(unsigned long int) (mode & CHMOD_MODE_BITS), &perms[1]);
|
||||
}
|
||||
|
||||
/* Change the mode of FILE.
|
||||
@@ -191,21 +191,21 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
|
||||
case FTS_NS:
|
||||
/* For a top-level file or directory, this FTS_NS (stat failed)
|
||||
indicator is determined at the time of the initial fts_open call.
|
||||
With programs like chmod, chown, and chgrp, that modify
|
||||
permissions, it is possible that the file in question is
|
||||
accessible when control reaches this point. So, if this is
|
||||
the first time we've seen the FTS_NS for this file, tell
|
||||
fts_read to stat it "again". */
|
||||
indicator is determined at the time of the initial fts_open call.
|
||||
With programs like chmod, chown, and chgrp, that modify
|
||||
permissions, it is possible that the file in question is
|
||||
accessible when control reaches this point. So, if this is
|
||||
the first time we've seen the FTS_NS for this file, tell
|
||||
fts_read to stat it "again". */
|
||||
if (ent->fts_level == 0 && ent->fts_number == 0)
|
||||
{
|
||||
ent->fts_number = 1;
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
ent->fts_number = 1;
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
if (! force_silent)
|
||||
error (0, ent->fts_errno, _("cannot access %s"),
|
||||
quote (file_full_name));
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
@@ -218,14 +218,14 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
case FTS_DNR:
|
||||
if (! force_silent)
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case FTS_SLNONE:
|
||||
if (! force_silent)
|
||||
error (0, 0, _("cannot operate on dangling symlink %s"),
|
||||
quote (file_full_name));
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
|
||||
default:
|
||||
@@ -246,55 +246,55 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
{
|
||||
old_mode = file_stats->st_mode;
|
||||
new_mode = mode_adjust (old_mode, S_ISDIR (old_mode) != 0, umask_value,
|
||||
change, NULL);
|
||||
change, NULL);
|
||||
|
||||
if (! S_ISLNK (old_mode))
|
||||
{
|
||||
if (chmodat (fts->fts_cwd_fd, file, new_mode) == 0)
|
||||
chmod_succeeded = true;
|
||||
else
|
||||
{
|
||||
if (! force_silent)
|
||||
error (0, errno, _("changing permissions of %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (chmodat (fts->fts_cwd_fd, file, new_mode) == 0)
|
||||
chmod_succeeded = true;
|
||||
else
|
||||
{
|
||||
if (! force_silent)
|
||||
error (0, errno, _("changing permissions of %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity != V_off)
|
||||
{
|
||||
bool changed = (chmod_succeeded
|
||||
&& mode_changed (file, old_mode, new_mode));
|
||||
&& mode_changed (file, old_mode, new_mode));
|
||||
|
||||
if (changed || verbosity == V_high)
|
||||
{
|
||||
enum Change_status ch_status =
|
||||
(!ok ? CH_FAILED
|
||||
: !chmod_succeeded ? CH_NOT_APPLIED
|
||||
: !changed ? CH_NO_CHANGE_REQUESTED
|
||||
: CH_SUCCEEDED);
|
||||
describe_change (file_full_name, new_mode, ch_status);
|
||||
}
|
||||
{
|
||||
enum Change_status ch_status =
|
||||
(!ok ? CH_FAILED
|
||||
: !chmod_succeeded ? CH_NOT_APPLIED
|
||||
: !changed ? CH_NO_CHANGE_REQUESTED
|
||||
: CH_SUCCEEDED);
|
||||
describe_change (file_full_name, new_mode, ch_status);
|
||||
}
|
||||
}
|
||||
|
||||
if (chmod_succeeded & diagnose_surprises)
|
||||
{
|
||||
mode_t naively_expected_mode =
|
||||
mode_adjust (old_mode, S_ISDIR (old_mode) != 0, 0, change, NULL);
|
||||
mode_adjust (old_mode, S_ISDIR (old_mode) != 0, 0, change, NULL);
|
||||
if (new_mode & ~naively_expected_mode)
|
||||
{
|
||||
char new_perms[12];
|
||||
char naively_expected_perms[12];
|
||||
strmode (new_mode, new_perms);
|
||||
strmode (naively_expected_mode, naively_expected_perms);
|
||||
new_perms[10] = naively_expected_perms[10] = '\0';
|
||||
error (0, 0,
|
||||
_("%s: new permissions are %s, not %s"),
|
||||
quotearg_colon (file_full_name),
|
||||
new_perms + 1, naively_expected_perms + 1);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
char new_perms[12];
|
||||
char naively_expected_perms[12];
|
||||
strmode (new_mode, new_perms);
|
||||
strmode (naively_expected_mode, naively_expected_perms);
|
||||
new_perms[10] = naively_expected_perms[10] = '\0';
|
||||
error (0, 0,
|
||||
_("%s: new permissions are %s, not %s"),
|
||||
quotearg_colon (file_full_name),
|
||||
new_perms + 1, naively_expected_perms + 1);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! recurse)
|
||||
@@ -320,16 +320,16 @@ process_files (char **files, int bit_flags)
|
||||
|
||||
ent = fts_read (fts);
|
||||
if (ent == NULL)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
if (! force_silent)
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
if (! force_silent)
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ok &= process_file (fts, ent);
|
||||
}
|
||||
@@ -347,7 +347,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -355,7 +355,7 @@ Usage: %s [OPTION]... MODE[,MODE]... FILE...\n\
|
||||
or: %s [OPTION]... OCTAL-MODE FILE...\n\
|
||||
or: %s [OPTION]... --reference=RFILE FILE...\n\
|
||||
"),
|
||||
program_name, program_name, program_name);
|
||||
program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
Change the mode of each FILE to MODE.\n\
|
||||
\n\
|
||||
@@ -407,99 +407,99 @@ main (int argc, char **argv)
|
||||
recurse = force_silent = diagnose_surprises = false;
|
||||
|
||||
while ((c = getopt_long (argc, argv,
|
||||
"Rcfvr::w::x::X::s::t::u::g::o::a::,::+::=::",
|
||||
long_options, NULL))
|
||||
!= -1)
|
||||
"Rcfvr::w::x::X::s::t::u::g::o::a::,::+::=::",
|
||||
long_options, NULL))
|
||||
!= -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'r':
|
||||
case 'w':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 's':
|
||||
case 't':
|
||||
case 'u':
|
||||
case 'g':
|
||||
case 'o':
|
||||
case 'a':
|
||||
case ',':
|
||||
case '+':
|
||||
case '=':
|
||||
/* Support nonportable uses like "chmod -w", but diagnose
|
||||
surprises due to umask confusion. Even though "--", "--r",
|
||||
etc., are valid modes, there is no "case '-'" here since
|
||||
getopt_long reserves leading "--" for long options. */
|
||||
{
|
||||
/* Allocate a mode string (e.g., "-rwx") by concatenating
|
||||
the argument containing this option. If a previous mode
|
||||
string was given, concatenate the previous string, a
|
||||
comma, and the new string (e.g., "-s,-rwx"). */
|
||||
{
|
||||
case 'r':
|
||||
case 'w':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 's':
|
||||
case 't':
|
||||
case 'u':
|
||||
case 'g':
|
||||
case 'o':
|
||||
case 'a':
|
||||
case ',':
|
||||
case '+':
|
||||
case '=':
|
||||
/* Support nonportable uses like "chmod -w", but diagnose
|
||||
surprises due to umask confusion. Even though "--", "--r",
|
||||
etc., are valid modes, there is no "case '-'" here since
|
||||
getopt_long reserves leading "--" for long options. */
|
||||
{
|
||||
/* Allocate a mode string (e.g., "-rwx") by concatenating
|
||||
the argument containing this option. If a previous mode
|
||||
string was given, concatenate the previous string, a
|
||||
comma, and the new string (e.g., "-s,-rwx"). */
|
||||
|
||||
char const *arg = argv[optind - 1];
|
||||
size_t arg_len = strlen (arg);
|
||||
size_t mode_comma_len = mode_len + !!mode_len;
|
||||
size_t new_mode_len = mode_comma_len + arg_len;
|
||||
if (mode_alloc <= new_mode_len)
|
||||
{
|
||||
mode_alloc = new_mode_len + 1;
|
||||
mode = X2REALLOC (mode, &mode_alloc);
|
||||
}
|
||||
mode[mode_len] = ',';
|
||||
strcpy (mode + mode_comma_len, arg);
|
||||
mode_len = new_mode_len;
|
||||
char const *arg = argv[optind - 1];
|
||||
size_t arg_len = strlen (arg);
|
||||
size_t mode_comma_len = mode_len + !!mode_len;
|
||||
size_t new_mode_len = mode_comma_len + arg_len;
|
||||
if (mode_alloc <= new_mode_len)
|
||||
{
|
||||
mode_alloc = new_mode_len + 1;
|
||||
mode = X2REALLOC (mode, &mode_alloc);
|
||||
}
|
||||
mode[mode_len] = ',';
|
||||
strcpy (mode + mode_comma_len, arg);
|
||||
mode_len = new_mode_len;
|
||||
|
||||
diagnose_surprises = true;
|
||||
}
|
||||
break;
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
case 'R':
|
||||
recurse = true;
|
||||
break;
|
||||
case 'c':
|
||||
verbosity = V_changes_only;
|
||||
break;
|
||||
case 'f':
|
||||
force_silent = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbosity = V_high;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
diagnose_surprises = true;
|
||||
}
|
||||
break;
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
case 'R':
|
||||
recurse = true;
|
||||
break;
|
||||
case 'c':
|
||||
verbosity = V_changes_only;
|
||||
break;
|
||||
case 'f':
|
||||
force_silent = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbosity = V_high;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (reference_file)
|
||||
{
|
||||
if (mode)
|
||||
{
|
||||
error (0, 0, _("cannot combine mode and --reference options"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("cannot combine mode and --reference options"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mode)
|
||||
mode = argv[optind++];
|
||||
mode = argv[optind++];
|
||||
}
|
||||
|
||||
if (optind >= argc)
|
||||
{
|
||||
if (!mode || mode != argv[optind - 1])
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -507,17 +507,17 @@ main (int argc, char **argv)
|
||||
{
|
||||
change = mode_create_from_ref (reference_file);
|
||||
if (!change)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote (reference_file));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote (reference_file));
|
||||
}
|
||||
else
|
||||
{
|
||||
change = mode_compile (mode);
|
||||
if (!change)
|
||||
{
|
||||
error (0, 0, _("invalid mode: %s"), quote (mode));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("invalid mode: %s"), quote (mode));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
umask_value = umask (0);
|
||||
}
|
||||
|
||||
@@ -526,8 +526,8 @@ main (int argc, char **argv)
|
||||
static struct dev_ino dev_ino_buf;
|
||||
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
|
||||
if (root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -535,7 +535,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
ok = process_files (argv + optind,
|
||||
FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
|
||||
FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
|
||||
|
||||
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
+168
-168
@@ -83,8 +83,8 @@ gid_to_name (gid_t gid)
|
||||
char buf[INT_BUFSIZE_BOUND (intmax_t)];
|
||||
struct group *grp = getgrgid (gid);
|
||||
return xstrdup (grp ? grp->gr_name
|
||||
: TYPE_SIGNED (gid_t) ? imaxtostr (gid, buf)
|
||||
: umaxtostr (gid, buf));
|
||||
: TYPE_SIGNED (gid_t) ? imaxtostr (gid, buf)
|
||||
: umaxtostr (gid, buf));
|
||||
}
|
||||
|
||||
/* Convert the numeric user-id, UID, to a string stored in xmalloc'd memory,
|
||||
@@ -97,8 +97,8 @@ uid_to_name (uid_t uid)
|
||||
char buf[INT_BUFSIZE_BOUND (intmax_t)];
|
||||
struct passwd *pwd = getpwuid (uid);
|
||||
return xstrdup (pwd ? pwd->pw_name
|
||||
: TYPE_SIGNED (uid_t) ? imaxtostr (uid, buf)
|
||||
: umaxtostr (uid, buf));
|
||||
: TYPE_SIGNED (uid_t) ? imaxtostr (uid, buf)
|
||||
: umaxtostr (uid, buf));
|
||||
}
|
||||
|
||||
/* Tell the user how/if the user and group of FILE have been changed.
|
||||
@@ -107,7 +107,7 @@ uid_to_name (uid_t uid)
|
||||
|
||||
static void
|
||||
describe_change (const char *file, enum Change_status changed,
|
||||
char const *user, char const *group)
|
||||
char const *user, char const *group)
|
||||
{
|
||||
const char *fmt;
|
||||
char const *spec;
|
||||
@@ -116,22 +116,22 @@ describe_change (const char *file, enum Change_status changed,
|
||||
if (changed == CH_NOT_APPLIED)
|
||||
{
|
||||
printf (_("neither symbolic link %s nor referent has been changed\n"),
|
||||
quote (file));
|
||||
quote (file));
|
||||
return;
|
||||
}
|
||||
|
||||
if (user)
|
||||
{
|
||||
if (group)
|
||||
{
|
||||
spec_allocated = xmalloc (strlen (user) + 1 + strlen (group) + 1);
|
||||
stpcpy (stpcpy (stpcpy (spec_allocated, user), ":"), group);
|
||||
spec = spec_allocated;
|
||||
}
|
||||
{
|
||||
spec_allocated = xmalloc (strlen (user) + 1 + strlen (group) + 1);
|
||||
stpcpy (stpcpy (stpcpy (spec_allocated, user), ":"), group);
|
||||
spec = spec_allocated;
|
||||
}
|
||||
else
|
||||
{
|
||||
spec = user;
|
||||
}
|
||||
{
|
||||
spec = user;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -142,18 +142,18 @@ describe_change (const char *file, enum Change_status changed,
|
||||
{
|
||||
case CH_SUCCEEDED:
|
||||
fmt = (user ? _("changed ownership of %s to %s\n")
|
||||
: group ? _("changed group of %s to %s\n")
|
||||
: _("no change to ownership of %s\n"));
|
||||
: group ? _("changed group of %s to %s\n")
|
||||
: _("no change to ownership of %s\n"));
|
||||
break;
|
||||
case CH_FAILED:
|
||||
fmt = (user ? _("failed to change ownership of %s to %s\n")
|
||||
: group ? _("failed to change group of %s to %s\n")
|
||||
: _("failed to change ownership of %s\n"));
|
||||
: group ? _("failed to change group of %s to %s\n")
|
||||
: _("failed to change ownership of %s\n"));
|
||||
break;
|
||||
case CH_NO_CHANGE_REQUESTED:
|
||||
fmt = (user ? _("ownership of %s retained as %s\n")
|
||||
: group ? _("group of %s retained as %s\n")
|
||||
: _("ownership of %s retained\n"));
|
||||
: group ? _("group of %s retained as %s\n")
|
||||
: _("ownership of %s retained\n"));
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
@@ -184,9 +184,9 @@ describe_change (const char *file, enum Change_status changed,
|
||||
|
||||
static enum RCH_status
|
||||
restricted_chown (int cwd_fd, char const *file,
|
||||
struct stat const *orig_st,
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid)
|
||||
struct stat const *orig_st,
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid)
|
||||
{
|
||||
enum RCH_status status = RC_ok;
|
||||
struct stat st;
|
||||
@@ -199,15 +199,15 @@ restricted_chown (int cwd_fd, char const *file,
|
||||
if (! S_ISREG (orig_st->st_mode))
|
||||
{
|
||||
if (S_ISDIR (orig_st->st_mode))
|
||||
open_flags |= O_DIRECTORY;
|
||||
open_flags |= O_DIRECTORY;
|
||||
else
|
||||
return RC_do_ordinary_chown;
|
||||
return RC_do_ordinary_chown;
|
||||
}
|
||||
|
||||
fd = openat (cwd_fd, file, O_RDONLY | open_flags);
|
||||
if (! (0 <= fd
|
||||
|| (errno == EACCES && S_ISREG (orig_st->st_mode)
|
||||
&& 0 <= (fd = openat (cwd_fd, file, O_WRONLY | open_flags)))))
|
||||
|| (errno == EACCES && S_ISREG (orig_st->st_mode)
|
||||
&& 0 <= (fd = openat (cwd_fd, file, O_WRONLY | open_flags)))))
|
||||
return (errno == EACCES ? RC_do_ordinary_chown : RC_error);
|
||||
|
||||
if (fstat (fd, &st) != 0)
|
||||
@@ -215,18 +215,18 @@ restricted_chown (int cwd_fd, char const *file,
|
||||
else if (! SAME_INODE (*orig_st, st))
|
||||
status = RC_inode_changed;
|
||||
else if ((required_uid == (uid_t) -1 || required_uid == st.st_uid)
|
||||
&& (required_gid == (gid_t) -1 || required_gid == st.st_gid))
|
||||
&& (required_gid == (gid_t) -1 || required_gid == st.st_gid))
|
||||
{
|
||||
if (fchown (fd, uid, gid) == 0)
|
||||
{
|
||||
status = (close (fd) == 0
|
||||
? RC_ok : RC_error);
|
||||
return status;
|
||||
}
|
||||
{
|
||||
status = (close (fd) == 0
|
||||
? RC_ok : RC_error);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = RC_error;
|
||||
}
|
||||
{
|
||||
status = RC_error;
|
||||
}
|
||||
}
|
||||
|
||||
{ /* FIXME: remove these curly braces when we assume C99. */
|
||||
@@ -245,9 +245,9 @@ restricted_chown (int cwd_fd, char const *file,
|
||||
Return true if successful. */
|
||||
static bool
|
||||
change_file_owner (FTS *fts, FTSENT *ent,
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid,
|
||||
struct Chown_option const *chopt)
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid,
|
||||
struct Chown_option const *chopt)
|
||||
{
|
||||
char const *file_full_name = ent->fts_path;
|
||||
char const *file = ent->fts_accpath;
|
||||
@@ -261,44 +261,44 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
{
|
||||
case FTS_D:
|
||||
if (chopt->recurse)
|
||||
{
|
||||
if (ROOT_DEV_INO_CHECK (chopt->root_dev_ino, ent->fts_statp))
|
||||
{
|
||||
/* This happens e.g., with "chown -R --preserve-root 0 /"
|
||||
and with "chown -RH --preserve-root 0 symlink-to-root". */
|
||||
ROOT_DEV_INO_WARN (file_full_name);
|
||||
/* Tell fts not to traverse into this hierarchy. */
|
||||
fts_set (fts, ent, FTS_SKIP);
|
||||
/* Ensure that we do not process "/" on the second visit. */
|
||||
ent = fts_read (fts);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
{
|
||||
if (ROOT_DEV_INO_CHECK (chopt->root_dev_ino, ent->fts_statp))
|
||||
{
|
||||
/* This happens e.g., with "chown -R --preserve-root 0 /"
|
||||
and with "chown -RH --preserve-root 0 symlink-to-root". */
|
||||
ROOT_DEV_INO_WARN (file_full_name);
|
||||
/* Tell fts not to traverse into this hierarchy. */
|
||||
fts_set (fts, ent, FTS_SKIP);
|
||||
/* Ensure that we do not process "/" on the second visit. */
|
||||
ent = fts_read (fts);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FTS_DP:
|
||||
if (! chopt->recurse)
|
||||
return true;
|
||||
return true;
|
||||
break;
|
||||
|
||||
case FTS_NS:
|
||||
/* For a top-level file or directory, this FTS_NS (stat failed)
|
||||
indicator is determined at the time of the initial fts_open call.
|
||||
With programs like chmod, chown, and chgrp, that modify
|
||||
permissions, it is possible that the file in question is
|
||||
accessible when control reaches this point. So, if this is
|
||||
the first time we've seen the FTS_NS for this file, tell
|
||||
fts_read to stat it "again". */
|
||||
indicator is determined at the time of the initial fts_open call.
|
||||
With programs like chmod, chown, and chgrp, that modify
|
||||
permissions, it is possible that the file in question is
|
||||
accessible when control reaches this point. So, if this is
|
||||
the first time we've seen the FTS_NS for this file, tell
|
||||
fts_read to stat it "again". */
|
||||
if (ent->fts_level == 0 && ent->fts_number == 0)
|
||||
{
|
||||
ent->fts_number = 1;
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
ent->fts_number = 1;
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
if (! chopt->force_silent)
|
||||
error (0, ent->fts_errno, _("cannot access %s"),
|
||||
quote (file_full_name));
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
@@ -311,7 +311,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
case FTS_DNR:
|
||||
if (! chopt->force_silent)
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
@@ -325,9 +325,9 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
file_stats = NULL;
|
||||
}
|
||||
else if (required_uid == (uid_t) -1 && required_gid == (gid_t) -1
|
||||
&& chopt->verbosity == V_off
|
||||
&& ! chopt->root_dev_ino
|
||||
&& ! chopt->affect_symlink_referent)
|
||||
&& chopt->verbosity == V_off
|
||||
&& ! chopt->root_dev_ino
|
||||
&& ! chopt->affect_symlink_referent)
|
||||
{
|
||||
do_chown = true;
|
||||
file_stats = ent->fts_statp;
|
||||
@@ -337,25 +337,25 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
file_stats = ent->fts_statp;
|
||||
|
||||
/* If this is a symlink and we're dereferencing them,
|
||||
stat it to get info on the referent. */
|
||||
stat it to get info on the referent. */
|
||||
if (chopt->affect_symlink_referent && S_ISLNK (file_stats->st_mode))
|
||||
{
|
||||
if (fstatat (fts->fts_cwd_fd, file, &stat_buf, 0) != 0)
|
||||
{
|
||||
if (! chopt->force_silent)
|
||||
error (0, errno, _("cannot dereference %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
if (fstatat (fts->fts_cwd_fd, file, &stat_buf, 0) != 0)
|
||||
{
|
||||
if (! chopt->force_silent)
|
||||
error (0, errno, _("cannot dereference %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
}
|
||||
|
||||
file_stats = &stat_buf;
|
||||
}
|
||||
file_stats = &stat_buf;
|
||||
}
|
||||
|
||||
do_chown = (ok
|
||||
&& (required_uid == (uid_t) -1
|
||||
|| required_uid == file_stats->st_uid)
|
||||
&& (required_gid == (gid_t) -1
|
||||
|| required_gid == file_stats->st_gid));
|
||||
&& (required_uid == (uid_t) -1
|
||||
|| required_uid == file_stats->st_uid)
|
||||
&& (required_gid == (gid_t) -1
|
||||
|| required_gid == file_stats->st_gid));
|
||||
}
|
||||
|
||||
/* This happens when chown -LR --preserve-root encounters a symlink-to-/. */
|
||||
@@ -370,89 +370,89 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
if (do_chown)
|
||||
{
|
||||
if ( ! chopt->affect_symlink_referent)
|
||||
{
|
||||
ok = (lchownat (fts->fts_cwd_fd, file, uid, gid) == 0);
|
||||
{
|
||||
ok = (lchownat (fts->fts_cwd_fd, file, uid, gid) == 0);
|
||||
|
||||
/* Ignore any error due to lack of support; POSIX requires
|
||||
this behavior for top-level symbolic links with -h, and
|
||||
implies that it's required for all symbolic links. */
|
||||
if (!ok && errno == EOPNOTSUPP)
|
||||
{
|
||||
ok = true;
|
||||
symlink_changed = false;
|
||||
}
|
||||
}
|
||||
/* Ignore any error due to lack of support; POSIX requires
|
||||
this behavior for top-level symbolic links with -h, and
|
||||
implies that it's required for all symbolic links. */
|
||||
if (!ok && errno == EOPNOTSUPP)
|
||||
{
|
||||
ok = true;
|
||||
symlink_changed = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If possible, avoid a race condition with --from=O:G and without the
|
||||
(-h) --no-dereference option. If fts's stat call determined
|
||||
that the uid/gid of FILE matched the --from=O:G-selected
|
||||
owner and group IDs, blindly using chown(2) here could lead
|
||||
chown(1) or chgrp(1) mistakenly to dereference a *symlink*
|
||||
to an arbitrary file that an attacker had moved into the
|
||||
place of FILE during the window between the stat and
|
||||
chown(2) calls. If FILE is a regular file or a directory
|
||||
that can be opened, this race condition can be avoided safely. */
|
||||
{
|
||||
/* If possible, avoid a race condition with --from=O:G and without the
|
||||
(-h) --no-dereference option. If fts's stat call determined
|
||||
that the uid/gid of FILE matched the --from=O:G-selected
|
||||
owner and group IDs, blindly using chown(2) here could lead
|
||||
chown(1) or chgrp(1) mistakenly to dereference a *symlink*
|
||||
to an arbitrary file that an attacker had moved into the
|
||||
place of FILE during the window between the stat and
|
||||
chown(2) calls. If FILE is a regular file or a directory
|
||||
that can be opened, this race condition can be avoided safely. */
|
||||
|
||||
enum RCH_status err
|
||||
= restricted_chown (fts->fts_cwd_fd, file, file_stats, uid, gid,
|
||||
required_uid, required_gid);
|
||||
switch (err)
|
||||
{
|
||||
case RC_ok:
|
||||
break;
|
||||
enum RCH_status err
|
||||
= restricted_chown (fts->fts_cwd_fd, file, file_stats, uid, gid,
|
||||
required_uid, required_gid);
|
||||
switch (err)
|
||||
{
|
||||
case RC_ok:
|
||||
break;
|
||||
|
||||
case RC_do_ordinary_chown:
|
||||
ok = (chownat (fts->fts_cwd_fd, file, uid, gid) == 0);
|
||||
break;
|
||||
case RC_do_ordinary_chown:
|
||||
ok = (chownat (fts->fts_cwd_fd, file, uid, gid) == 0);
|
||||
break;
|
||||
|
||||
case RC_error:
|
||||
ok = false;
|
||||
break;
|
||||
case RC_error:
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case RC_inode_changed:
|
||||
/* FIXME: give a diagnostic in this case? */
|
||||
case RC_excluded:
|
||||
do_chown = false;
|
||||
ok = false;
|
||||
break;
|
||||
case RC_inode_changed:
|
||||
/* FIXME: give a diagnostic in this case? */
|
||||
case RC_excluded:
|
||||
do_chown = false;
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* On some systems (e.g., GNU/Linux 2.4.x),
|
||||
the chown function resets the `special' permission bits.
|
||||
Do *not* restore those bits; doing so would open a window in
|
||||
which a malicious user, M, could subvert a chown command run
|
||||
by some other user and operating on files in a directory
|
||||
where M has write access. */
|
||||
the chown function resets the `special' permission bits.
|
||||
Do *not* restore those bits; doing so would open a window in
|
||||
which a malicious user, M, could subvert a chown command run
|
||||
by some other user and operating on files in a directory
|
||||
where M has write access. */
|
||||
|
||||
if (do_chown && !ok && ! chopt->force_silent)
|
||||
error (0, errno, (uid != (uid_t) -1
|
||||
? _("changing ownership of %s")
|
||||
: _("changing group of %s")),
|
||||
quote (file_full_name));
|
||||
error (0, errno, (uid != (uid_t) -1
|
||||
? _("changing ownership of %s")
|
||||
: _("changing group of %s")),
|
||||
quote (file_full_name));
|
||||
}
|
||||
|
||||
if (chopt->verbosity != V_off)
|
||||
{
|
||||
bool changed =
|
||||
((do_chown & ok & symlink_changed)
|
||||
&& ! ((uid == (uid_t) -1 || uid == file_stats->st_uid)
|
||||
&& (gid == (gid_t) -1 || gid == file_stats->st_gid)));
|
||||
((do_chown & ok & symlink_changed)
|
||||
&& ! ((uid == (uid_t) -1 || uid == file_stats->st_uid)
|
||||
&& (gid == (gid_t) -1 || gid == file_stats->st_gid)));
|
||||
|
||||
if (changed || chopt->verbosity == V_high)
|
||||
{
|
||||
enum Change_status ch_status =
|
||||
(!ok ? CH_FAILED
|
||||
: !symlink_changed ? CH_NOT_APPLIED
|
||||
: !changed ? CH_NO_CHANGE_REQUESTED
|
||||
: CH_SUCCEEDED);
|
||||
describe_change (file_full_name, ch_status,
|
||||
chopt->user_name, chopt->group_name);
|
||||
}
|
||||
{
|
||||
enum Change_status ch_status =
|
||||
(!ok ? CH_FAILED
|
||||
: !symlink_changed ? CH_NOT_APPLIED
|
||||
: !changed ? CH_NO_CHANGE_REQUESTED
|
||||
: CH_SUCCEEDED);
|
||||
describe_change (file_full_name, ch_status,
|
||||
chopt->user_name, chopt->group_name);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! chopt->recurse)
|
||||
@@ -472,18 +472,18 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
Return true if successful. */
|
||||
extern bool
|
||||
chown_files (char **files, int bit_flags,
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid,
|
||||
struct Chown_option const *chopt)
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid,
|
||||
struct Chown_option const *chopt)
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
/* Use lstat and stat only if they're needed. */
|
||||
int stat_flags = ((required_uid != (uid_t) -1 || required_gid != (gid_t) -1
|
||||
|| chopt->affect_symlink_referent
|
||||
|| chopt->verbosity != V_off)
|
||||
? 0
|
||||
: FTS_NOSTAT);
|
||||
|| chopt->affect_symlink_referent
|
||||
|| chopt->verbosity != V_off)
|
||||
? 0
|
||||
: FTS_NOSTAT);
|
||||
|
||||
FTS *fts = xfts_open (files, bit_flags | stat_flags, NULL);
|
||||
|
||||
@@ -493,19 +493,19 @@ chown_files (char **files, int bit_flags,
|
||||
|
||||
ent = fts_read (fts);
|
||||
if (ent == NULL)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
if (! chopt->force_silent)
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
if (! chopt->force_silent)
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ok &= change_file_owner (fts, ent, uid, gid,
|
||||
required_uid, required_gid, chopt);
|
||||
required_uid, required_gid, chopt);
|
||||
}
|
||||
|
||||
/* Ignore failure, since the only way it can do so is in failing to
|
||||
|
||||
+3
-3
@@ -79,8 +79,8 @@ uid_to_name (uid_t);
|
||||
|
||||
bool
|
||||
chown_files (char **files, int bit_flags,
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid,
|
||||
struct Chown_option const *chopt);
|
||||
uid_t uid, gid_t gid,
|
||||
uid_t required_uid, gid_t required_gid,
|
||||
struct Chown_option const *chopt);
|
||||
|
||||
#endif /* CHOWN_CORE_H */
|
||||
+74
-74
@@ -85,14 +85,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [OWNER][:[GROUP]] FILE...\n\
|
||||
or: %s [OPTION]... --reference=RFILE FILE...\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Change the owner and/or group of each FILE to OWNER and/or GROUP.\n\
|
||||
With --reference, change the owner and group of each FILE to those of RFILE.\n\
|
||||
@@ -152,7 +152,7 @@ Examples:\n\
|
||||
%s root:staff /u Likewise, but also change its group to \"staff\".\n\
|
||||
%s -hR root /u Change the owner of /u and subfiles to \"root\".\n\
|
||||
"),
|
||||
program_name, program_name, program_name);
|
||||
program_name, program_name, program_name);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -193,86 +193,86 @@ main (int argc, char **argv)
|
||||
chopt_init (&chopt);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'H': /* Traverse command-line symlinks-to-directories. */
|
||||
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
{
|
||||
case 'H': /* Traverse command-line symlinks-to-directories. */
|
||||
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'L': /* Traverse all symlinks-to-directories. */
|
||||
bit_flags = FTS_LOGICAL;
|
||||
break;
|
||||
case 'L': /* Traverse all symlinks-to-directories. */
|
||||
bit_flags = FTS_LOGICAL;
|
||||
break;
|
||||
|
||||
case 'P': /* Traverse no symlinks-to-directories. */
|
||||
bit_flags = FTS_PHYSICAL;
|
||||
break;
|
||||
case 'P': /* Traverse no symlinks-to-directories. */
|
||||
bit_flags = FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'h': /* --no-dereference: affect symlinks */
|
||||
dereference = 0;
|
||||
break;
|
||||
case 'h': /* --no-dereference: affect symlinks */
|
||||
dereference = 0;
|
||||
break;
|
||||
|
||||
case DEREFERENCE_OPTION: /* --dereference: affect the referent
|
||||
of each symlink */
|
||||
dereference = 1;
|
||||
break;
|
||||
case DEREFERENCE_OPTION: /* --dereference: affect the referent
|
||||
of each symlink */
|
||||
dereference = 1;
|
||||
break;
|
||||
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
case REFERENCE_FILE_OPTION:
|
||||
reference_file = optarg;
|
||||
break;
|
||||
|
||||
case FROM_OPTION:
|
||||
{
|
||||
char *u_dummy, *g_dummy;
|
||||
const char *e = parse_user_spec (optarg,
|
||||
&required_uid, &required_gid,
|
||||
&u_dummy, &g_dummy);
|
||||
if (e)
|
||||
error (EXIT_FAILURE, 0, "%s: %s", e, quote (optarg));
|
||||
break;
|
||||
}
|
||||
case FROM_OPTION:
|
||||
{
|
||||
char *u_dummy, *g_dummy;
|
||||
const char *e = parse_user_spec (optarg,
|
||||
&required_uid, &required_gid,
|
||||
&u_dummy, &g_dummy);
|
||||
if (e)
|
||||
error (EXIT_FAILURE, 0, "%s: %s", e, quote (optarg));
|
||||
break;
|
||||
}
|
||||
|
||||
case 'R':
|
||||
chopt.recurse = true;
|
||||
break;
|
||||
case 'R':
|
||||
chopt.recurse = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
chopt.verbosity = V_changes_only;
|
||||
break;
|
||||
case 'c':
|
||||
chopt.verbosity = V_changes_only;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
chopt.force_silent = true;
|
||||
break;
|
||||
case 'f':
|
||||
chopt.force_silent = true;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
chopt.verbosity = V_high;
|
||||
break;
|
||||
case 'v':
|
||||
chopt.verbosity = V_high;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (chopt.recurse)
|
||||
{
|
||||
if (bit_flags == FTS_PHYSICAL)
|
||||
{
|
||||
if (dereference == 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("-R --dereference requires either -H or -L"));
|
||||
dereference = 0;
|
||||
}
|
||||
{
|
||||
if (dereference == 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("-R --dereference requires either -H or -L"));
|
||||
dereference = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -283,9 +283,9 @@ main (int argc, char **argv)
|
||||
if (argc - optind < (reference_file ? 1 : 2))
|
||||
{
|
||||
if (argc <= optind)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -293,8 +293,8 @@ main (int argc, char **argv)
|
||||
{
|
||||
struct stat ref_stats;
|
||||
if (stat (reference_file, &ref_stats))
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote (reference_file));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote (reference_file));
|
||||
|
||||
uid = ref_stats.st_uid;
|
||||
gid = ref_stats.st_gid;
|
||||
@@ -304,13 +304,13 @@ main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
const char *e = parse_user_spec (argv[optind], &uid, &gid,
|
||||
&chopt.user_name, &chopt.group_name);
|
||||
&chopt.user_name, &chopt.group_name);
|
||||
if (e)
|
||||
error (EXIT_FAILURE, 0, "%s: %s", e, quote (argv[optind]));
|
||||
|
||||
/* If a group is specified but no user, set the user name to the
|
||||
empty string so that diagnostics say "ownership :GROUP"
|
||||
rather than "group GROUP". */
|
||||
empty string so that diagnostics say "ownership :GROUP"
|
||||
rather than "group GROUP". */
|
||||
if (!chopt.user_name && chopt.group_name)
|
||||
chopt.user_name = bad_cast ("");
|
||||
|
||||
@@ -322,14 +322,14 @@ main (int argc, char **argv)
|
||||
static struct dev_ino dev_ino_buf;
|
||||
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
|
||||
if (chopt.root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
}
|
||||
|
||||
bit_flags |= FTS_DEFER_STAT;
|
||||
ok = chown_files (argv + optind, bit_flags,
|
||||
uid, gid,
|
||||
required_uid, required_gid, &chopt);
|
||||
uid, gid,
|
||||
required_uid, required_gid, &chopt);
|
||||
|
||||
chopt_free (&chopt);
|
||||
|
||||
|
||||
+4
-4
@@ -118,7 +118,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -164,7 +164,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
|
||||
while ((c = getopt_long (argc, argv, "+", long_opts, NULL)) != -1)
|
||||
{
|
||||
@@ -189,7 +189,7 @@ main (int argc, char **argv)
|
||||
|
||||
if (chroot (argv[optind]) != 0)
|
||||
error (EXIT_FAILURE, errno, _("cannot change root directory to %s"),
|
||||
argv[optind]);
|
||||
argv[optind]);
|
||||
|
||||
if (chdir ("/"))
|
||||
error (EXIT_FAILURE, errno, _("cannot chdir to root directory"));
|
||||
@@ -199,7 +199,7 @@ main (int argc, char **argv)
|
||||
/* No command. Run an interactive shell. */
|
||||
char *shell = getenv ("SHELL");
|
||||
if (shell == NULL)
|
||||
shell = bad_cast ("/bin/sh");
|
||||
shell = bad_cast ("/bin/sh");
|
||||
argv[0] = shell;
|
||||
argv[1] = bad_cast ("-i");
|
||||
argv[2] = NULL;
|
||||
|
||||
+18
-18
@@ -58,8 +58,8 @@
|
||||
The i bit in GEN is set if X^i is a summand of G(X) except X^32. */
|
||||
|
||||
# define GEN (BIT (26) | BIT (23) | BIT (22) | BIT (16) | BIT (12) \
|
||||
| BIT (11) | BIT (10) | BIT (8) | BIT (7) | BIT (5) \
|
||||
| BIT (4) | BIT (2) | BIT (1) | BIT (0))
|
||||
| BIT (11) | BIT (10) | BIT (8) | BIT (7) | BIT (5) \
|
||||
| BIT (4) | BIT (2) | BIT (1) | BIT (0))
|
||||
|
||||
static uint_fast32_t r[8];
|
||||
|
||||
@@ -96,9 +96,9 @@ main (void)
|
||||
for (i = 0; i < 51; i++)
|
||||
{
|
||||
printf (",\n 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x",
|
||||
crc_remainder (i * 5 + 1), crc_remainder (i * 5 + 2),
|
||||
crc_remainder (i * 5 + 3), crc_remainder (i * 5 + 4),
|
||||
crc_remainder (i * 5 + 5));
|
||||
crc_remainder (i * 5 + 1), crc_remainder (i * 5 + 2),
|
||||
crc_remainder (i * 5 + 3), crc_remainder (i * 5 + 4),
|
||||
crc_remainder (i * 5 + 5));
|
||||
}
|
||||
printf ("\n};\n");
|
||||
exit (EXIT_SUCCESS);
|
||||
@@ -193,16 +193,16 @@ cksum (const char *file, bool print_name)
|
||||
fp = stdin;
|
||||
have_read_stdin = true;
|
||||
if (O_BINARY && ! isatty (STDIN_FILENO))
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = fopen (file, (O_BINARY ? "rb" : "r"));
|
||||
if (fp == NULL)
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
while ((bytes_read = fread (buf, 1, BUFLEN, fp)) > 0)
|
||||
@@ -210,19 +210,19 @@ cksum (const char *file, bool print_name)
|
||||
unsigned char *cp = buf;
|
||||
|
||||
if (length + bytes_read < length)
|
||||
error (EXIT_FAILURE, 0, _("%s: file too long"), file);
|
||||
error (EXIT_FAILURE, 0, _("%s: file too long"), file);
|
||||
length += bytes_read;
|
||||
while (bytes_read--)
|
||||
crc = (crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];
|
||||
crc = (crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];
|
||||
if (feof (fp))
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
if (!STREQ (file, "-"))
|
||||
fclose (fp);
|
||||
fclose (fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -255,14 +255,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [FILE]...\n\
|
||||
or: %s [OPTION]\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Print CRC checksum and byte counts of each FILE.\n\
|
||||
\n\
|
||||
@@ -289,7 +289,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
@@ -301,7 +301,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
ok = true;
|
||||
for (i = optind; i < argc; i++)
|
||||
ok &= cksum (argv[i], true);
|
||||
ok &= cksum (argv[i], true);
|
||||
}
|
||||
|
||||
if (have_read_stdin && fclose (stdin) == EOF)
|
||||
|
||||
+103
-103
@@ -96,13 +96,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... FILE1 FILE2\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Compare sorted files FILE1 and FILE2 line by line.\n\
|
||||
"), stdout);
|
||||
@@ -139,7 +139,7 @@ Examples:\n\
|
||||
%s -12 file1 file2 Print only lines present in both file1 and file2.\n\
|
||||
%s -3 file1 file2 Print lines in file1 not in file2, and vice versa.\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -157,26 +157,26 @@ writeline (struct linebuffer const *line, FILE *stream, int class)
|
||||
{
|
||||
case 1:
|
||||
if (!only_file_1)
|
||||
return;
|
||||
return;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (!only_file_2)
|
||||
return;
|
||||
return;
|
||||
/* Print a delimiter if we are printing lines from file 1. */
|
||||
if (only_file_1)
|
||||
fputs (delimiter, stream);
|
||||
fputs (delimiter, stream);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (!both)
|
||||
return;
|
||||
return;
|
||||
/* Print a delimiter if we are printing lines from file 1. */
|
||||
if (only_file_1)
|
||||
fputs (delimiter, stream);
|
||||
fputs (delimiter, stream);
|
||||
/* Print a delimiter if we are printing lines from file 2. */
|
||||
if (only_file_2)
|
||||
fputs (delimiter, stream);
|
||||
fputs (delimiter, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -196,35 +196,35 @@ writeline (struct linebuffer const *line, FILE *stream, int class)
|
||||
|
||||
static void
|
||||
check_order (struct linebuffer const *prev,
|
||||
struct linebuffer const *current,
|
||||
int whatfile)
|
||||
struct linebuffer const *current,
|
||||
int whatfile)
|
||||
{
|
||||
|
||||
if (check_input_order != CHECK_ORDER_DISABLED
|
||||
&& ((check_input_order == CHECK_ORDER_ENABLED) || seen_unpairable))
|
||||
{
|
||||
if (!issued_disorder_warning[whatfile - 1])
|
||||
{
|
||||
int order;
|
||||
{
|
||||
int order;
|
||||
|
||||
if (hard_LC_COLLATE)
|
||||
order = xmemcoll (prev->buffer, prev->length - 1,
|
||||
current->buffer, current->length - 1);
|
||||
else
|
||||
order = memcmp2 (prev->buffer, prev->length - 1,
|
||||
current->buffer, current->length - 1);
|
||||
if (hard_LC_COLLATE)
|
||||
order = xmemcoll (prev->buffer, prev->length - 1,
|
||||
current->buffer, current->length - 1);
|
||||
else
|
||||
order = memcmp2 (prev->buffer, prev->length - 1,
|
||||
current->buffer, current->length - 1);
|
||||
|
||||
if (0 < order)
|
||||
{
|
||||
error ((check_input_order == CHECK_ORDER_ENABLED
|
||||
? EXIT_FAILURE : 0),
|
||||
0, _("file %d is not in sorted order"), whatfile);
|
||||
if (0 < order)
|
||||
{
|
||||
error ((check_input_order == CHECK_ORDER_ENABLED
|
||||
? EXIT_FAILURE : 0),
|
||||
0, _("file %d is not in sorted order"), whatfile);
|
||||
|
||||
/* If we get to here, the message was just a warning, but we
|
||||
want only to issue it once. */
|
||||
issued_disorder_warning[whatfile - 1] = true;
|
||||
}
|
||||
}
|
||||
/* If we get to here, the message was just a warning, but we
|
||||
want only to issue it once. */
|
||||
issued_disorder_warning[whatfile - 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,20 +260,20 @@ compare_files (char **infiles)
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
initbuffer (&lba[i][j]);
|
||||
all_line[i][j] = &lba[i][j];
|
||||
}
|
||||
{
|
||||
initbuffer (&lba[i][j]);
|
||||
all_line[i][j] = &lba[i][j];
|
||||
}
|
||||
alt[i][0] = 0;
|
||||
alt[i][1] = 0;
|
||||
alt[i][2] = 0;
|
||||
streams[i] = (STREQ (infiles[i], "-") ? stdin : fopen (infiles[i], "r"));
|
||||
if (!streams[i])
|
||||
error (EXIT_FAILURE, errno, "%s", infiles[i]);
|
||||
error (EXIT_FAILURE, errno, "%s", infiles[i]);
|
||||
|
||||
thisline[i] = readlinebuffer (all_line[i][alt[i][0]], streams[i]);
|
||||
if (ferror (streams[i]))
|
||||
error (EXIT_FAILURE, errno, "%s", infiles[i]);
|
||||
error (EXIT_FAILURE, errno, "%s", infiles[i]);
|
||||
}
|
||||
|
||||
while (thisline[0] || thisline[1])
|
||||
@@ -284,69 +284,69 @@ compare_files (char **infiles)
|
||||
/* Compare the next available lines of the two files. */
|
||||
|
||||
if (!thisline[0])
|
||||
order = 1;
|
||||
order = 1;
|
||||
else if (!thisline[1])
|
||||
order = -1;
|
||||
order = -1;
|
||||
else
|
||||
{
|
||||
if (hard_LC_COLLATE)
|
||||
order = xmemcoll (thisline[0]->buffer, thisline[0]->length - 1,
|
||||
thisline[1]->buffer, thisline[1]->length - 1);
|
||||
else
|
||||
{
|
||||
size_t len = min (thisline[0]->length, thisline[1]->length) - 1;
|
||||
order = memcmp (thisline[0]->buffer, thisline[1]->buffer, len);
|
||||
if (order == 0)
|
||||
order = (thisline[0]->length < thisline[1]->length
|
||||
? -1
|
||||
: thisline[0]->length != thisline[1]->length);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (hard_LC_COLLATE)
|
||||
order = xmemcoll (thisline[0]->buffer, thisline[0]->length - 1,
|
||||
thisline[1]->buffer, thisline[1]->length - 1);
|
||||
else
|
||||
{
|
||||
size_t len = min (thisline[0]->length, thisline[1]->length) - 1;
|
||||
order = memcmp (thisline[0]->buffer, thisline[1]->buffer, len);
|
||||
if (order == 0)
|
||||
order = (thisline[0]->length < thisline[1]->length
|
||||
? -1
|
||||
: thisline[0]->length != thisline[1]->length);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the line that is lesser. */
|
||||
if (order == 0)
|
||||
writeline (thisline[1], stdout, 3);
|
||||
writeline (thisline[1], stdout, 3);
|
||||
else
|
||||
{
|
||||
seen_unpairable = true;
|
||||
if (order <= 0)
|
||||
writeline (thisline[0], stdout, 1);
|
||||
else
|
||||
writeline (thisline[1], stdout, 2);
|
||||
}
|
||||
{
|
||||
seen_unpairable = true;
|
||||
if (order <= 0)
|
||||
writeline (thisline[0], stdout, 1);
|
||||
else
|
||||
writeline (thisline[1], stdout, 2);
|
||||
}
|
||||
|
||||
/* Step the file the line came from.
|
||||
If the files match, step both files. */
|
||||
If the files match, step both files. */
|
||||
if (0 <= order)
|
||||
fill_up[1] = true;
|
||||
fill_up[1] = true;
|
||||
if (order <= 0)
|
||||
fill_up[0] = true;
|
||||
fill_up[0] = true;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
if (fill_up[i])
|
||||
{
|
||||
/* Rotate the buffers for this file. */
|
||||
alt[i][2] = alt[i][1];
|
||||
alt[i][1] = alt[i][0];
|
||||
alt[i][0] = (alt[i][0] + 1) & 0x03;
|
||||
if (fill_up[i])
|
||||
{
|
||||
/* Rotate the buffers for this file. */
|
||||
alt[i][2] = alt[i][1];
|
||||
alt[i][1] = alt[i][0];
|
||||
alt[i][0] = (alt[i][0] + 1) & 0x03;
|
||||
|
||||
thisline[i] = readlinebuffer (all_line[i][alt[i][0]], streams[i]);
|
||||
thisline[i] = readlinebuffer (all_line[i][alt[i][0]], streams[i]);
|
||||
|
||||
if (thisline[i])
|
||||
check_order (all_line[i][alt[i][1]], thisline[i], i + 1);
|
||||
if (thisline[i])
|
||||
check_order (all_line[i][alt[i][1]], thisline[i], i + 1);
|
||||
|
||||
/* If this is the end of the file we may need to re-check
|
||||
the order of the previous two lines, since we might have
|
||||
discovered an unpairable match since we checked before. */
|
||||
else if (all_line[i][alt[i][2]]->buffer)
|
||||
check_order (all_line[i][alt[i][2]],
|
||||
all_line[i][alt[i][1]], i + 1);
|
||||
/* If this is the end of the file we may need to re-check
|
||||
the order of the previous two lines, since we might have
|
||||
discovered an unpairable match since we checked before. */
|
||||
else if (all_line[i][alt[i][2]]->buffer)
|
||||
check_order (all_line[i][alt[i][2]],
|
||||
all_line[i][alt[i][1]], i + 1);
|
||||
|
||||
if (ferror (streams[i]))
|
||||
error (EXIT_FAILURE, errno, "%s", infiles[i]);
|
||||
if (ferror (streams[i]))
|
||||
error (EXIT_FAILURE, errno, "%s", infiles[i]);
|
||||
|
||||
fill_up[i] = false;
|
||||
}
|
||||
fill_up[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
@@ -380,50 +380,50 @@ main (int argc, char **argv)
|
||||
switch (c)
|
||||
{
|
||||
case '1':
|
||||
only_file_1 = false;
|
||||
break;
|
||||
only_file_1 = false;
|
||||
break;
|
||||
|
||||
case '2':
|
||||
only_file_2 = false;
|
||||
break;
|
||||
only_file_2 = false;
|
||||
break;
|
||||
|
||||
case '3':
|
||||
both = false;
|
||||
break;
|
||||
both = false;
|
||||
break;
|
||||
|
||||
case NOCHECK_ORDER_OPTION:
|
||||
check_input_order = CHECK_ORDER_DISABLED;
|
||||
break;
|
||||
check_input_order = CHECK_ORDER_DISABLED;
|
||||
break;
|
||||
|
||||
case CHECK_ORDER_OPTION:
|
||||
check_input_order = CHECK_ORDER_ENABLED;
|
||||
break;
|
||||
check_input_order = CHECK_ORDER_ENABLED;
|
||||
break;
|
||||
|
||||
case OUTPUT_DELIMITER_OPTION:
|
||||
if (delimiter && !STREQ (delimiter, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple delimiters specified"));
|
||||
delimiter = optarg;
|
||||
if (!*delimiter)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, _("empty %s not allowed"),
|
||||
quote ("--output-delimiter"));
|
||||
}
|
||||
break;
|
||||
if (delimiter && !STREQ (delimiter, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple delimiters specified"));
|
||||
delimiter = optarg;
|
||||
if (!*delimiter)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, _("empty %s not allowed"),
|
||||
quote ("--output-delimiter"));
|
||||
}
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (argc - optind < 2)
|
||||
{
|
||||
if (argc <= optind)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
+995
-995
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -252,8 +252,8 @@ int rpl_rename (const char *, const char *);
|
||||
# endif
|
||||
|
||||
bool copy (char const *src_name, char const *dst_name,
|
||||
bool nonexistent_dst, const struct cp_options *options,
|
||||
bool *copy_into_self, bool *rename_succeeded);
|
||||
bool nonexistent_dst, const struct cp_options *options,
|
||||
bool *copy_into_self, bool *rename_succeeded);
|
||||
|
||||
void dest_info_init (struct cp_options *);
|
||||
void src_info_init (struct cp_options *);
|
||||
|
||||
+3
-3
@@ -148,9 +148,9 @@ extern void
|
||||
hash_init (void)
|
||||
{
|
||||
src_to_dest = hash_initialize (INITIAL_TABLE_SIZE, NULL,
|
||||
src_to_dest_hash,
|
||||
src_to_dest_compare,
|
||||
src_to_dest_free);
|
||||
src_to_dest_hash,
|
||||
src_to_dest_compare,
|
||||
src_to_dest_free);
|
||||
if (src_to_dest == NULL)
|
||||
xalloc_die ();
|
||||
}
|
||||
|
||||
+257
-257
@@ -346,7 +346,7 @@ record_line_starts (struct buffer_record *b)
|
||||
{
|
||||
line_end = memchr (line_start, '\n', bytes_left);
|
||||
if (line_end == NULL)
|
||||
break;
|
||||
break;
|
||||
line_length = line_end - line_start + 1;
|
||||
keep_new_line (b, line_start, line_length);
|
||||
bytes_left -= line_length;
|
||||
@@ -358,12 +358,12 @@ record_line_starts (struct buffer_record *b)
|
||||
if (bytes_left)
|
||||
{
|
||||
if (have_read_eof)
|
||||
{
|
||||
keep_new_line (b, line_start, bytes_left);
|
||||
lines++;
|
||||
}
|
||||
{
|
||||
keep_new_line (b, line_start, bytes_left);
|
||||
lines++;
|
||||
}
|
||||
else
|
||||
save_to_hold_area (xmemdup (line_start, bytes_left), bytes_left);
|
||||
save_to_hold_area (xmemdup (line_start, bytes_left), bytes_left);
|
||||
}
|
||||
|
||||
b->num_lines = lines;
|
||||
@@ -438,7 +438,7 @@ save_buffer (struct buffer_record *buf)
|
||||
else
|
||||
{
|
||||
for (p = head; p->next; p = p->next)
|
||||
/* Do nothing. */ ;
|
||||
/* Do nothing. */ ;
|
||||
p->next = buf;
|
||||
}
|
||||
}
|
||||
@@ -481,25 +481,25 @@ load_buffer (void)
|
||||
|
||||
/* First check the `holding' area for a partial line. */
|
||||
if (hold_count)
|
||||
{
|
||||
memcpy (p, hold_area, hold_count);
|
||||
p += hold_count;
|
||||
b->bytes_used += hold_count;
|
||||
bytes_avail -= hold_count;
|
||||
hold_count = 0;
|
||||
}
|
||||
{
|
||||
memcpy (p, hold_area, hold_count);
|
||||
p += hold_count;
|
||||
b->bytes_used += hold_count;
|
||||
bytes_avail -= hold_count;
|
||||
hold_count = 0;
|
||||
}
|
||||
|
||||
b->bytes_used += read_input (p, bytes_avail);
|
||||
|
||||
lines_found = record_line_starts (b);
|
||||
if (!lines_found)
|
||||
free_buffer (b);
|
||||
free_buffer (b);
|
||||
|
||||
if (lines_found || have_read_eof)
|
||||
break;
|
||||
break;
|
||||
|
||||
if (xalloc_oversized (2, b->bytes_alloc))
|
||||
xalloc_die ();
|
||||
xalloc_die ();
|
||||
bytes_wanted = 2 * b->bytes_alloc;
|
||||
free_buffer (b);
|
||||
free (b);
|
||||
@@ -563,13 +563,13 @@ remove_line (void)
|
||||
/* Go on to the next line record. */
|
||||
head->curr_line = l->next;
|
||||
if (head->curr_line == NULL || head->curr_line->used == 0)
|
||||
{
|
||||
/* Go on to the next data block.
|
||||
but first record the current one so we can free it
|
||||
once the line we're returning has been processed. */
|
||||
prev_buf = head;
|
||||
head = head->next;
|
||||
}
|
||||
{
|
||||
/* Go on to the next data block.
|
||||
but first record the current one so we can free it
|
||||
once the line we're returning has been processed. */
|
||||
prev_buf = head;
|
||||
head = head->next;
|
||||
}
|
||||
}
|
||||
|
||||
return line;
|
||||
@@ -592,23 +592,23 @@ find_line (uintmax_t linenum)
|
||||
for (b = head;;)
|
||||
{
|
||||
if (linenum < b->start_line + b->num_lines)
|
||||
{
|
||||
/* The line is in this buffer. */
|
||||
struct line *l;
|
||||
size_t offset; /* How far into the buffer the line is. */
|
||||
{
|
||||
/* The line is in this buffer. */
|
||||
struct line *l;
|
||||
size_t offset; /* How far into the buffer the line is. */
|
||||
|
||||
l = b->line_start;
|
||||
offset = linenum - b->start_line;
|
||||
/* Find the control record. */
|
||||
while (offset >= CTRL_SIZE)
|
||||
{
|
||||
l = l->next;
|
||||
offset -= CTRL_SIZE;
|
||||
}
|
||||
return &l->starts[offset];
|
||||
}
|
||||
l = b->line_start;
|
||||
offset = linenum - b->start_line;
|
||||
/* Find the control record. */
|
||||
while (offset >= CTRL_SIZE)
|
||||
{
|
||||
l = l->next;
|
||||
offset -= CTRL_SIZE;
|
||||
}
|
||||
return &l->starts[offset];
|
||||
}
|
||||
if (b->next == NULL && !load_buffer ())
|
||||
return NULL;
|
||||
return NULL;
|
||||
b = b->next; /* Try the next data block. */
|
||||
}
|
||||
}
|
||||
@@ -657,12 +657,12 @@ write_to_file (uintmax_t last_line, bool ignore, int argnum)
|
||||
{
|
||||
line = remove_line ();
|
||||
if (line == NULL)
|
||||
{
|
||||
error (0, 0, _("%s: line number out of range"), global_argv[argnum]);
|
||||
cleanup_fatal ();
|
||||
}
|
||||
{
|
||||
error (0, 0, _("%s: line number out of range"), global_argv[argnum]);
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (!ignore)
|
||||
save_line_to_file (line);
|
||||
save_line_to_file (line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ handle_line_error (const struct control *p, uintmax_t repetition)
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
|
||||
fprintf (stderr, _("%s: %s: line number out of range"),
|
||||
program_name, quote (umaxtostr (p->lines_required, buf)));
|
||||
program_name, quote (umaxtostr (p->lines_required, buf)));
|
||||
if (repetition)
|
||||
fprintf (stderr, _(" on repetition %s\n"), umaxtostr (repetition, buf));
|
||||
else
|
||||
@@ -717,7 +717,7 @@ process_line_count (const struct control *p, uintmax_t repetition)
|
||||
{
|
||||
line = remove_line ();
|
||||
if (line == NULL)
|
||||
handle_line_error (p, repetition);
|
||||
handle_line_error (p, repetition);
|
||||
save_line_to_file (line);
|
||||
}
|
||||
|
||||
@@ -734,7 +734,7 @@ static void
|
||||
regexp_error (struct control *p, uintmax_t repetition, bool ignore)
|
||||
{
|
||||
fprintf (stderr, _("%s: %s: match not found"),
|
||||
program_name, quote (global_argv[p->argnum]));
|
||||
program_name, quote (global_argv[p->argnum]));
|
||||
|
||||
if (repetition)
|
||||
{
|
||||
@@ -774,75 +774,75 @@ process_regexp (struct control *p, uintmax_t repetition)
|
||||
if (p->offset >= 0)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
line = find_line (++current_line);
|
||||
if (line == NULL)
|
||||
{
|
||||
if (p->repeat_forever)
|
||||
{
|
||||
if (!ignore)
|
||||
{
|
||||
dump_rest_of_file ();
|
||||
close_output_file ();
|
||||
}
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else
|
||||
regexp_error (p, repetition, ignore);
|
||||
}
|
||||
line_len = line->len;
|
||||
if (line->str[line_len - 1] == '\n')
|
||||
line_len--;
|
||||
ret = re_search (&p->re_compiled, line->str, line_len,
|
||||
0, line_len, NULL);
|
||||
if (ret == -2)
|
||||
{
|
||||
error (0, 0, _("error in regular expression search"));
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (ret == -1)
|
||||
{
|
||||
line = remove_line ();
|
||||
if (!ignore)
|
||||
save_line_to_file (line);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
{
|
||||
line = find_line (++current_line);
|
||||
if (line == NULL)
|
||||
{
|
||||
if (p->repeat_forever)
|
||||
{
|
||||
if (!ignore)
|
||||
{
|
||||
dump_rest_of_file ();
|
||||
close_output_file ();
|
||||
}
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else
|
||||
regexp_error (p, repetition, ignore);
|
||||
}
|
||||
line_len = line->len;
|
||||
if (line->str[line_len - 1] == '\n')
|
||||
line_len--;
|
||||
ret = re_search (&p->re_compiled, line->str, line_len,
|
||||
0, line_len, NULL);
|
||||
if (ret == -2)
|
||||
{
|
||||
error (0, 0, _("error in regular expression search"));
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (ret == -1)
|
||||
{
|
||||
line = remove_line ();
|
||||
if (!ignore)
|
||||
save_line_to_file (line);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Buffer the lines. */
|
||||
for (;;)
|
||||
{
|
||||
line = find_line (++current_line);
|
||||
if (line == NULL)
|
||||
{
|
||||
if (p->repeat_forever)
|
||||
{
|
||||
if (!ignore)
|
||||
{
|
||||
dump_rest_of_file ();
|
||||
close_output_file ();
|
||||
}
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else
|
||||
regexp_error (p, repetition, ignore);
|
||||
}
|
||||
line_len = line->len;
|
||||
if (line->str[line_len - 1] == '\n')
|
||||
line_len--;
|
||||
ret = re_search (&p->re_compiled, line->str, line_len,
|
||||
0, line_len, NULL);
|
||||
if (ret == -2)
|
||||
{
|
||||
error (0, 0, _("error in regular expression search"));
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (ret != -1)
|
||||
break;
|
||||
}
|
||||
{
|
||||
line = find_line (++current_line);
|
||||
if (line == NULL)
|
||||
{
|
||||
if (p->repeat_forever)
|
||||
{
|
||||
if (!ignore)
|
||||
{
|
||||
dump_rest_of_file ();
|
||||
close_output_file ();
|
||||
}
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else
|
||||
regexp_error (p, repetition, ignore);
|
||||
}
|
||||
line_len = line->len;
|
||||
if (line->str[line_len - 1] == '\n')
|
||||
line_len--;
|
||||
ret = re_search (&p->re_compiled, line->str, line_len,
|
||||
0, line_len, NULL);
|
||||
if (ret == -2)
|
||||
{
|
||||
error (0, 0, _("error in regular expression search"));
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (ret != -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Account for any offset from this regexp. */
|
||||
@@ -868,17 +868,17 @@ split_file (void)
|
||||
{
|
||||
uintmax_t j;
|
||||
if (controls[i].regexpr)
|
||||
{
|
||||
for (j = 0; (controls[i].repeat_forever
|
||||
|| j <= controls[i].repeat); j++)
|
||||
process_regexp (&controls[i], j);
|
||||
}
|
||||
{
|
||||
for (j = 0; (controls[i].repeat_forever
|
||||
|| j <= controls[i].repeat); j++)
|
||||
process_regexp (&controls[i], j);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; (controls[i].repeat_forever
|
||||
|| j <= controls[i].repeat); j++)
|
||||
process_line_count (&controls[i], j);
|
||||
}
|
||||
{
|
||||
for (j = 0; (controls[i].repeat_forever
|
||||
|| j <= controls[i].repeat); j++)
|
||||
process_line_count (&controls[i], j);
|
||||
}
|
||||
}
|
||||
|
||||
create_output_file ();
|
||||
@@ -946,7 +946,7 @@ delete_all_files (bool in_signal_handler)
|
||||
{
|
||||
const char *name = make_filename (i);
|
||||
if (unlink (name) != 0 && !in_signal_handler)
|
||||
error (0, errno, "%s", name);
|
||||
error (0, errno, "%s", name);
|
||||
}
|
||||
|
||||
files_created = 0;
|
||||
@@ -961,41 +961,41 @@ close_output_file (void)
|
||||
if (output_stream)
|
||||
{
|
||||
if (ferror (output_stream))
|
||||
{
|
||||
error (0, 0, _("write error for %s"), quote (output_filename));
|
||||
output_stream = NULL;
|
||||
cleanup_fatal ();
|
||||
}
|
||||
{
|
||||
error (0, 0, _("write error for %s"), quote (output_filename));
|
||||
output_stream = NULL;
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (fclose (output_stream) != 0)
|
||||
{
|
||||
error (0, errno, "%s", output_filename);
|
||||
output_stream = NULL;
|
||||
cleanup_fatal ();
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", output_filename);
|
||||
output_stream = NULL;
|
||||
cleanup_fatal ();
|
||||
}
|
||||
if (bytes_written == 0 && elide_empty_files)
|
||||
{
|
||||
sigset_t oldset;
|
||||
bool unlink_ok;
|
||||
int unlink_errno;
|
||||
{
|
||||
sigset_t oldset;
|
||||
bool unlink_ok;
|
||||
int unlink_errno;
|
||||
|
||||
/* Remove the output file in a critical section, to avoid races. */
|
||||
sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
|
||||
unlink_ok = (unlink (output_filename) == 0);
|
||||
unlink_errno = errno;
|
||||
files_created -= unlink_ok;
|
||||
sigprocmask (SIG_SETMASK, &oldset, NULL);
|
||||
/* Remove the output file in a critical section, to avoid races. */
|
||||
sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
|
||||
unlink_ok = (unlink (output_filename) == 0);
|
||||
unlink_errno = errno;
|
||||
files_created -= unlink_ok;
|
||||
sigprocmask (SIG_SETMASK, &oldset, NULL);
|
||||
|
||||
if (! unlink_ok)
|
||||
error (0, unlink_errno, "%s", output_filename);
|
||||
}
|
||||
if (! unlink_ok)
|
||||
error (0, unlink_errno, "%s", output_filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!suppress_count)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
fprintf (stdout, "%s\n", umaxtostr (bytes_written, buf));
|
||||
}
|
||||
}
|
||||
{
|
||||
if (!suppress_count)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
fprintf (stdout, "%s\n", umaxtostr (bytes_written, buf));
|
||||
}
|
||||
}
|
||||
output_stream = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1062,11 +1062,11 @@ parse_repeat_count (int argnum, struct control *p, char *str)
|
||||
else
|
||||
{
|
||||
if (xstrtoumax (str + 1, NULL, 10, &val, "") != LONGINT_OK)
|
||||
{
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%s}: integer required between `{' and `}'"),
|
||||
global_argv[argnum]);
|
||||
}
|
||||
{
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%s}: integer required between `{' and `}'"),
|
||||
global_argv[argnum]);
|
||||
}
|
||||
p->repeat = val;
|
||||
}
|
||||
|
||||
@@ -1091,7 +1091,7 @@ extract_regexp (int argnum, bool ignore, char const *str)
|
||||
closing_delim = strrchr (str + 1, delim);
|
||||
if (closing_delim == NULL)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%s: closing delimiter `%c' missing"), str, delim);
|
||||
_("%s: closing delimiter `%c' missing"), str, delim);
|
||||
|
||||
len = closing_delim - str - 1;
|
||||
p = new_control_record ();
|
||||
@@ -1132,44 +1132,44 @@ parse_patterns (int argc, int start, char **argv)
|
||||
for (i = start; i < argc; i++)
|
||||
{
|
||||
if (*argv[i] == '/' || *argv[i] == '%')
|
||||
{
|
||||
p = extract_regexp (i, *argv[i] == '%', argv[i]);
|
||||
}
|
||||
{
|
||||
p = extract_regexp (i, *argv[i] == '%', argv[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = new_control_record ();
|
||||
p->argnum = i;
|
||||
{
|
||||
p = new_control_record ();
|
||||
p->argnum = i;
|
||||
|
||||
if (xstrtoumax (argv[i], NULL, 10, &val, "") != LONGINT_OK)
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid pattern"), argv[i]);
|
||||
if (val == 0)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%s: line number must be greater than zero"),
|
||||
argv[i]);
|
||||
if (val < last_val)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("line number %s is smaller than preceding line number, %s"),
|
||||
quote (argv[i]), umaxtostr (last_val, buf));
|
||||
}
|
||||
if (xstrtoumax (argv[i], NULL, 10, &val, "") != LONGINT_OK)
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid pattern"), argv[i]);
|
||||
if (val == 0)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%s: line number must be greater than zero"),
|
||||
argv[i]);
|
||||
if (val < last_val)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("line number %s is smaller than preceding line number, %s"),
|
||||
quote (argv[i]), umaxtostr (last_val, buf));
|
||||
}
|
||||
|
||||
if (val == last_val)
|
||||
error (0, 0,
|
||||
_("warning: line number %s is the same as preceding line number"),
|
||||
quote (argv[i]));
|
||||
if (val == last_val)
|
||||
error (0, 0,
|
||||
_("warning: line number %s is the same as preceding line number"),
|
||||
quote (argv[i]));
|
||||
|
||||
last_val = val;
|
||||
last_val = val;
|
||||
|
||||
p->lines_required = val;
|
||||
}
|
||||
p->lines_required = val;
|
||||
}
|
||||
|
||||
if (i + 1 < argc && *argv[i + 1] == '{')
|
||||
{
|
||||
/* We have a repeat count. */
|
||||
i++;
|
||||
parse_repeat_count (i, p, argv[i]);
|
||||
}
|
||||
{
|
||||
/* We have a repeat count. */
|
||||
i++;
|
||||
parse_repeat_count (i, p, argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1181,22 +1181,22 @@ get_format_flags (char **format_ptr)
|
||||
for (; **format_ptr; (*format_ptr)++)
|
||||
{
|
||||
switch (**format_ptr)
|
||||
{
|
||||
case '-':
|
||||
break;
|
||||
{
|
||||
case '-':
|
||||
break;
|
||||
|
||||
case '+':
|
||||
case ' ':
|
||||
count |= 1;
|
||||
break;
|
||||
case '+':
|
||||
case ' ':
|
||||
count |= 1;
|
||||
break;
|
||||
|
||||
case '#':
|
||||
count |= 2; /* Allow for 0x prefix preceding an `x' conversion. */
|
||||
break;
|
||||
case '#':
|
||||
count |= 2; /* Allow for 0x prefix preceding an `x' conversion. */
|
||||
break;
|
||||
|
||||
default:
|
||||
return count;
|
||||
}
|
||||
default:
|
||||
return count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -1208,7 +1208,7 @@ get_format_width (char **format_ptr)
|
||||
|
||||
if (ISDIGIT (**format_ptr)
|
||||
&& (xstrtoul (*format_ptr, format_ptr, 10, &val, NULL) != LONGINT_OK
|
||||
|| SIZE_MAX < val))
|
||||
|| SIZE_MAX < val))
|
||||
error (EXIT_FAILURE, 0, _("invalid format width"));
|
||||
|
||||
/* Allow for enough octal digits to represent the value of UINT_MAX,
|
||||
@@ -1229,8 +1229,8 @@ get_format_prec (char **format_ptr)
|
||||
{
|
||||
unsigned long int val;
|
||||
if (xstrtoul (*format_ptr, format_ptr, 10, &val, NULL) != LONGINT_OK
|
||||
|| SIZE_MAX < val)
|
||||
error (EXIT_FAILURE, 0, _("invalid format precision"));
|
||||
|| SIZE_MAX < val)
|
||||
error (EXIT_FAILURE, 0, _("invalid format precision"));
|
||||
return val;
|
||||
}
|
||||
}
|
||||
@@ -1257,10 +1257,10 @@ get_format_conv_type (char **format_ptr)
|
||||
default:
|
||||
if (isprint (ch))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid conversion specifier in suffix: %c"), ch);
|
||||
_("invalid conversion specifier in suffix: %c"), ch);
|
||||
else
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid conversion specifier in suffix: \\%.3o"), ch);
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid conversion specifier in suffix: \\%.3o"), ch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1275,30 +1275,30 @@ max_out (char *format)
|
||||
if (*format++ != '%')
|
||||
out_count++;
|
||||
else if (*format == '%')
|
||||
{
|
||||
format++;
|
||||
out_count++;
|
||||
}
|
||||
{
|
||||
format++;
|
||||
out_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (percent)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("too many %% conversion specifications in suffix"));
|
||||
percent = true;
|
||||
out_count += get_format_flags (&format);
|
||||
{
|
||||
size_t width = get_format_width (&format);
|
||||
size_t prec = get_format_prec (&format);
|
||||
{
|
||||
if (percent)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("too many %% conversion specifications in suffix"));
|
||||
percent = true;
|
||||
out_count += get_format_flags (&format);
|
||||
{
|
||||
size_t width = get_format_width (&format);
|
||||
size_t prec = get_format_prec (&format);
|
||||
|
||||
out_count += MAX (width, prec);
|
||||
}
|
||||
get_format_conv_type (&format);
|
||||
}
|
||||
out_count += MAX (width, prec);
|
||||
}
|
||||
get_format_conv_type (&format);
|
||||
}
|
||||
}
|
||||
|
||||
if (! percent)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("missing %% conversion specification in suffix"));
|
||||
_("missing %% conversion specification in suffix"));
|
||||
|
||||
return out_count;
|
||||
}
|
||||
@@ -1328,47 +1328,47 @@ main (int argc, char **argv)
|
||||
switch (optc)
|
||||
{
|
||||
case 'f':
|
||||
prefix = optarg;
|
||||
break;
|
||||
prefix = optarg;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
suffix = optarg;
|
||||
break;
|
||||
suffix = optarg;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
remove_files = false;
|
||||
break;
|
||||
remove_files = false;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
|
||||
|| val > INT_MAX)
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid number"), optarg);
|
||||
digits = val;
|
||||
break;
|
||||
if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
|
||||
|| val > INT_MAX)
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid number"), optarg);
|
||||
digits = val;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
case 'q':
|
||||
suppress_count = true;
|
||||
break;
|
||||
suppress_count = true;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
elide_empty_files = true;
|
||||
break;
|
||||
elide_empty_files = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (argc - optind < 2)
|
||||
{
|
||||
if (argc <= optind)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -1385,22 +1385,22 @@ main (int argc, char **argv)
|
||||
int i;
|
||||
static int const sig[] =
|
||||
{
|
||||
/* The usual suspects. */
|
||||
SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
|
||||
/* The usual suspects. */
|
||||
SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
|
||||
#ifdef SIGPOLL
|
||||
SIGPOLL,
|
||||
SIGPOLL,
|
||||
#endif
|
||||
#ifdef SIGPROF
|
||||
SIGPROF,
|
||||
SIGPROF,
|
||||
#endif
|
||||
#ifdef SIGVTALRM
|
||||
SIGVTALRM,
|
||||
SIGVTALRM,
|
||||
#endif
|
||||
#ifdef SIGXCPU
|
||||
SIGXCPU,
|
||||
SIGXCPU,
|
||||
#endif
|
||||
#ifdef SIGXFSZ
|
||||
SIGXFSZ,
|
||||
SIGXFSZ,
|
||||
#endif
|
||||
};
|
||||
enum { nsigs = ARRAY_CARDINALITY (sig) };
|
||||
@@ -1410,9 +1410,9 @@ main (int argc, char **argv)
|
||||
sigemptyset (&caught_signals);
|
||||
for (i = 0; i < nsigs; i++)
|
||||
{
|
||||
sigaction (sig[i], NULL, &act);
|
||||
if (act.sa_handler != SIG_IGN)
|
||||
sigaddset (&caught_signals, sig[i]);
|
||||
sigaction (sig[i], NULL, &act);
|
||||
if (act.sa_handler != SIG_IGN)
|
||||
sigaddset (&caught_signals, sig[i]);
|
||||
}
|
||||
|
||||
act.sa_handler = interrupt_handler;
|
||||
@@ -1421,7 +1421,7 @@ main (int argc, char **argv)
|
||||
|
||||
for (i = 0; i < nsigs; i++)
|
||||
if (sigismember (&caught_signals, sig[i]))
|
||||
sigaction (sig[i], &act, NULL);
|
||||
sigaction (sig[i], &act, NULL);
|
||||
}
|
||||
|
||||
split_file ();
|
||||
@@ -1440,13 +1440,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... FILE PATTERN...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Output pieces of FILE separated by PATTERN(s) to files `xx00', `xx01', ...,\n\
|
||||
and output byte counts of each piece to standard output.\n\
|
||||
|
||||
@@ -60,11 +60,11 @@
|
||||
do \
|
||||
{ \
|
||||
if (low == 0 || high == 0) \
|
||||
FATAL_ERROR (_("fields and positions are numbered from 1")); \
|
||||
FATAL_ERROR (_("fields and positions are numbered from 1")); \
|
||||
if (n_rp >= n_rp_allocated) \
|
||||
{ \
|
||||
(rp) = X2NREALLOC (rp, &n_rp_allocated); \
|
||||
} \
|
||||
{ \
|
||||
(rp) = X2NREALLOC (rp, &n_rp_allocated); \
|
||||
} \
|
||||
rp[n_rp].lo = (low); \
|
||||
rp[n_rp].hi = (high); \
|
||||
++n_rp; \
|
||||
@@ -183,13 +183,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s OPTION... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Print selected parts of lines from each FILE to standard output.\n\
|
||||
\n\
|
||||
@@ -347,7 +347,7 @@ set_fields (const char *fieldstr)
|
||||
bool rhs_specified = false;
|
||||
bool dash_found = false; /* True if a '-' is found in this field. */
|
||||
bool field_found = false; /* True if at least one field spec
|
||||
has been processed. */
|
||||
has been processed. */
|
||||
|
||||
struct range_pair *rp = NULL;
|
||||
size_t n_rp = 0;
|
||||
@@ -361,139 +361,139 @@ set_fields (const char *fieldstr)
|
||||
for (;;)
|
||||
{
|
||||
if (*fieldstr == '-')
|
||||
{
|
||||
in_digits = false;
|
||||
/* Starting a range. */
|
||||
if (dash_found)
|
||||
FATAL_ERROR (_("invalid byte or field list"));
|
||||
dash_found = true;
|
||||
fieldstr++;
|
||||
{
|
||||
in_digits = false;
|
||||
/* Starting a range. */
|
||||
if (dash_found)
|
||||
FATAL_ERROR (_("invalid byte or field list"));
|
||||
dash_found = true;
|
||||
fieldstr++;
|
||||
|
||||
initial = (lhs_specified ? value : 1);
|
||||
value = 0;
|
||||
}
|
||||
initial = (lhs_specified ? value : 1);
|
||||
value = 0;
|
||||
}
|
||||
else if (*fieldstr == ',' ||
|
||||
isblank (to_uchar (*fieldstr)) || *fieldstr == '\0')
|
||||
{
|
||||
in_digits = false;
|
||||
/* Ending the string, or this field/byte sublist. */
|
||||
if (dash_found)
|
||||
{
|
||||
dash_found = false;
|
||||
isblank (to_uchar (*fieldstr)) || *fieldstr == '\0')
|
||||
{
|
||||
in_digits = false;
|
||||
/* Ending the string, or this field/byte sublist. */
|
||||
if (dash_found)
|
||||
{
|
||||
dash_found = false;
|
||||
|
||||
if (!lhs_specified && !rhs_specified)
|
||||
FATAL_ERROR (_("invalid range with no endpoint: -"));
|
||||
if (!lhs_specified && !rhs_specified)
|
||||
FATAL_ERROR (_("invalid range with no endpoint: -"));
|
||||
|
||||
/* A range. Possibilities: -n, m-n, n-.
|
||||
In any case, `initial' contains the start of the range. */
|
||||
if (!rhs_specified)
|
||||
{
|
||||
/* `n-'. From `initial' to end of line. */
|
||||
eol_range_start = initial;
|
||||
field_found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* `m-n' or `-n' (1-n). */
|
||||
if (value < initial)
|
||||
FATAL_ERROR (_("invalid decreasing range"));
|
||||
/* A range. Possibilities: -n, m-n, n-.
|
||||
In any case, `initial' contains the start of the range. */
|
||||
if (!rhs_specified)
|
||||
{
|
||||
/* `n-'. From `initial' to end of line. */
|
||||
eol_range_start = initial;
|
||||
field_found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* `m-n' or `-n' (1-n). */
|
||||
if (value < initial)
|
||||
FATAL_ERROR (_("invalid decreasing range"));
|
||||
|
||||
/* Is there already a range going to end of line? */
|
||||
if (eol_range_start != 0)
|
||||
{
|
||||
/* Yes. Is the new sequence already contained
|
||||
in the old one? If so, no processing is
|
||||
necessary. */
|
||||
if (initial < eol_range_start)
|
||||
{
|
||||
/* No, the new sequence starts before the
|
||||
old. Does the old range going to end of line
|
||||
extend into the new range? */
|
||||
if (eol_range_start <= value)
|
||||
{
|
||||
/* Yes. Simply move the end of line marker. */
|
||||
eol_range_start = initial;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No. A simple range, before and disjoint from
|
||||
the range going to end of line. Fill it. */
|
||||
ADD_RANGE_PAIR (rp, initial, value);
|
||||
}
|
||||
/* Is there already a range going to end of line? */
|
||||
if (eol_range_start != 0)
|
||||
{
|
||||
/* Yes. Is the new sequence already contained
|
||||
in the old one? If so, no processing is
|
||||
necessary. */
|
||||
if (initial < eol_range_start)
|
||||
{
|
||||
/* No, the new sequence starts before the
|
||||
old. Does the old range going to end of line
|
||||
extend into the new range? */
|
||||
if (eol_range_start <= value)
|
||||
{
|
||||
/* Yes. Simply move the end of line marker. */
|
||||
eol_range_start = initial;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No. A simple range, before and disjoint from
|
||||
the range going to end of line. Fill it. */
|
||||
ADD_RANGE_PAIR (rp, initial, value);
|
||||
}
|
||||
|
||||
/* In any case, some fields were selected. */
|
||||
field_found = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There is no range going to end of line. */
|
||||
ADD_RANGE_PAIR (rp, initial, value);
|
||||
field_found = true;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A simple field number, not a range. */
|
||||
ADD_RANGE_PAIR (rp, value, value);
|
||||
value = 0;
|
||||
field_found = true;
|
||||
}
|
||||
/* In any case, some fields were selected. */
|
||||
field_found = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There is no range going to end of line. */
|
||||
ADD_RANGE_PAIR (rp, initial, value);
|
||||
field_found = true;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A simple field number, not a range. */
|
||||
ADD_RANGE_PAIR (rp, value, value);
|
||||
value = 0;
|
||||
field_found = true;
|
||||
}
|
||||
|
||||
if (*fieldstr == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (*fieldstr == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
fieldstr++;
|
||||
lhs_specified = false;
|
||||
rhs_specified = false;
|
||||
}
|
||||
fieldstr++;
|
||||
lhs_specified = false;
|
||||
rhs_specified = false;
|
||||
}
|
||||
else if (ISDIGIT (*fieldstr))
|
||||
{
|
||||
/* Record beginning of digit string, in case we have to
|
||||
complain about it. */
|
||||
static char const *num_start;
|
||||
if (!in_digits || !num_start)
|
||||
num_start = fieldstr;
|
||||
in_digits = true;
|
||||
{
|
||||
/* Record beginning of digit string, in case we have to
|
||||
complain about it. */
|
||||
static char const *num_start;
|
||||
if (!in_digits || !num_start)
|
||||
num_start = fieldstr;
|
||||
in_digits = true;
|
||||
|
||||
if (dash_found)
|
||||
rhs_specified = 1;
|
||||
else
|
||||
lhs_specified = 1;
|
||||
if (dash_found)
|
||||
rhs_specified = 1;
|
||||
else
|
||||
lhs_specified = 1;
|
||||
|
||||
/* Detect overflow. */
|
||||
if (!DECIMAL_DIGIT_ACCUMULATE (value, *fieldstr - '0', size_t))
|
||||
{
|
||||
/* In case the user specified -c$(echo 2^64|bc),22,
|
||||
complain only about the first number. */
|
||||
/* Determine the length of the offending number. */
|
||||
size_t len = strspn (num_start, "0123456789");
|
||||
char *bad_num = xstrndup (num_start, len);
|
||||
if (operating_mode == byte_mode)
|
||||
error (0, 0,
|
||||
_("byte offset %s is too large"), quote (bad_num));
|
||||
else
|
||||
error (0, 0,
|
||||
_("field number %s is too large"), quote (bad_num));
|
||||
free (bad_num);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
/* Detect overflow. */
|
||||
if (!DECIMAL_DIGIT_ACCUMULATE (value, *fieldstr - '0', size_t))
|
||||
{
|
||||
/* In case the user specified -c$(echo 2^64|bc),22,
|
||||
complain only about the first number. */
|
||||
/* Determine the length of the offending number. */
|
||||
size_t len = strspn (num_start, "0123456789");
|
||||
char *bad_num = xstrndup (num_start, len);
|
||||
if (operating_mode == byte_mode)
|
||||
error (0, 0,
|
||||
_("byte offset %s is too large"), quote (bad_num));
|
||||
else
|
||||
error (0, 0,
|
||||
_("field number %s is too large"), quote (bad_num));
|
||||
free (bad_num);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fieldstr++;
|
||||
}
|
||||
fieldstr++;
|
||||
}
|
||||
else
|
||||
FATAL_ERROR (_("invalid byte or field list"));
|
||||
FATAL_ERROR (_("invalid byte or field list"));
|
||||
}
|
||||
|
||||
max_range_endpoint = 0;
|
||||
for (i = 0; i < n_rp; i++)
|
||||
{
|
||||
if (rp[i].hi > max_range_endpoint)
|
||||
max_range_endpoint = rp[i].hi;
|
||||
max_range_endpoint = rp[i].hi;
|
||||
}
|
||||
|
||||
/* Allocate an array large enough so that it may be indexed by
|
||||
@@ -511,14 +511,14 @@ set_fields (const char *fieldstr)
|
||||
size_t rsi_candidate;
|
||||
|
||||
/* Record the range-start indices, i.e., record each start
|
||||
index that is not part of any other (lo..hi] range. */
|
||||
index that is not part of any other (lo..hi] range. */
|
||||
rsi_candidate = complement ? rp[i].hi + 1 : rp[i].lo;
|
||||
if (output_delimiter_specified
|
||||
&& !is_printable_field (rsi_candidate))
|
||||
mark_range_start (rsi_candidate);
|
||||
&& !is_printable_field (rsi_candidate))
|
||||
mark_range_start (rsi_candidate);
|
||||
|
||||
for (j = rp[i].lo; j <= rp[i].hi; j++)
|
||||
mark_printable_field (j);
|
||||
mark_printable_field (j);
|
||||
}
|
||||
|
||||
if (output_delimiter_specified
|
||||
@@ -550,32 +550,32 @@ cut_bytes (FILE *stream)
|
||||
c = getc (stream);
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
putchar ('\n');
|
||||
byte_idx = 0;
|
||||
print_delimiter = false;
|
||||
}
|
||||
{
|
||||
putchar ('\n');
|
||||
byte_idx = 0;
|
||||
print_delimiter = false;
|
||||
}
|
||||
else if (c == EOF)
|
||||
{
|
||||
if (byte_idx > 0)
|
||||
putchar ('\n');
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (byte_idx > 0)
|
||||
putchar ('\n');
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool range_start;
|
||||
bool *rs = output_delimiter_specified ? &range_start : NULL;
|
||||
if (print_kth (++byte_idx, rs))
|
||||
{
|
||||
if (rs && *rs && print_delimiter)
|
||||
{
|
||||
fwrite (output_delimiter_string, sizeof (char),
|
||||
output_delimiter_length, stdout);
|
||||
}
|
||||
print_delimiter = true;
|
||||
putchar (c);
|
||||
}
|
||||
}
|
||||
{
|
||||
bool range_start;
|
||||
bool *rs = output_delimiter_specified ? &range_start : NULL;
|
||||
if (print_kth (++byte_idx, rs))
|
||||
{
|
||||
if (rs && *rs && print_delimiter)
|
||||
{
|
||||
fwrite (output_delimiter_string, sizeof (char),
|
||||
output_delimiter_length, stdout);
|
||||
}
|
||||
print_delimiter = true;
|
||||
putchar (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,98 +606,98 @@ cut_fields (FILE *stream)
|
||||
while (1)
|
||||
{
|
||||
if (field_idx == 1 && buffer_first_field)
|
||||
{
|
||||
ssize_t len;
|
||||
size_t n_bytes;
|
||||
{
|
||||
ssize_t len;
|
||||
size_t n_bytes;
|
||||
|
||||
len = getndelim2 (&field_1_buffer, &field_1_bufsize, 0,
|
||||
GETNLINE_NO_LIMIT, delim, '\n', stream);
|
||||
if (len < 0)
|
||||
{
|
||||
free (field_1_buffer);
|
||||
field_1_buffer = NULL;
|
||||
if (ferror (stream) || feof (stream))
|
||||
break;
|
||||
xalloc_die ();
|
||||
}
|
||||
len = getndelim2 (&field_1_buffer, &field_1_bufsize, 0,
|
||||
GETNLINE_NO_LIMIT, delim, '\n', stream);
|
||||
if (len < 0)
|
||||
{
|
||||
free (field_1_buffer);
|
||||
field_1_buffer = NULL;
|
||||
if (ferror (stream) || feof (stream))
|
||||
break;
|
||||
xalloc_die ();
|
||||
}
|
||||
|
||||
n_bytes = len;
|
||||
assert (n_bytes != 0);
|
||||
n_bytes = len;
|
||||
assert (n_bytes != 0);
|
||||
|
||||
/* If the first field extends to the end of line (it is not
|
||||
delimited) and we are printing all non-delimited lines,
|
||||
print this one. */
|
||||
if (to_uchar (field_1_buffer[n_bytes - 1]) != delim)
|
||||
{
|
||||
if (suppress_non_delimited)
|
||||
{
|
||||
/* Empty. */
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite (field_1_buffer, sizeof (char), n_bytes, stdout);
|
||||
/* Make sure the output line is newline terminated. */
|
||||
if (field_1_buffer[n_bytes - 1] != '\n')
|
||||
putchar ('\n');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (print_kth (1, NULL))
|
||||
{
|
||||
/* Print the field, but not the trailing delimiter. */
|
||||
fwrite (field_1_buffer, sizeof (char), n_bytes - 1, stdout);
|
||||
found_any_selected_field = true;
|
||||
}
|
||||
++field_idx;
|
||||
}
|
||||
/* If the first field extends to the end of line (it is not
|
||||
delimited) and we are printing all non-delimited lines,
|
||||
print this one. */
|
||||
if (to_uchar (field_1_buffer[n_bytes - 1]) != delim)
|
||||
{
|
||||
if (suppress_non_delimited)
|
||||
{
|
||||
/* Empty. */
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite (field_1_buffer, sizeof (char), n_bytes, stdout);
|
||||
/* Make sure the output line is newline terminated. */
|
||||
if (field_1_buffer[n_bytes - 1] != '\n')
|
||||
putchar ('\n');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (print_kth (1, NULL))
|
||||
{
|
||||
/* Print the field, but not the trailing delimiter. */
|
||||
fwrite (field_1_buffer, sizeof (char), n_bytes - 1, stdout);
|
||||
found_any_selected_field = true;
|
||||
}
|
||||
++field_idx;
|
||||
}
|
||||
|
||||
if (c != EOF)
|
||||
{
|
||||
if (print_kth (field_idx, NULL))
|
||||
{
|
||||
if (found_any_selected_field)
|
||||
{
|
||||
fwrite (output_delimiter_string, sizeof (char),
|
||||
output_delimiter_length, stdout);
|
||||
}
|
||||
found_any_selected_field = true;
|
||||
{
|
||||
if (print_kth (field_idx, NULL))
|
||||
{
|
||||
if (found_any_selected_field)
|
||||
{
|
||||
fwrite (output_delimiter_string, sizeof (char),
|
||||
output_delimiter_length, stdout);
|
||||
}
|
||||
found_any_selected_field = true;
|
||||
|
||||
while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
|
||||
{
|
||||
putchar (c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
|
||||
{
|
||||
/* Empty. */
|
||||
}
|
||||
}
|
||||
}
|
||||
while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
|
||||
{
|
||||
putchar (c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
|
||||
{
|
||||
/* Empty. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
c = getc (stream);
|
||||
if (c != EOF)
|
||||
{
|
||||
ungetc (c, stream);
|
||||
c = '\n';
|
||||
}
|
||||
}
|
||||
{
|
||||
c = getc (stream);
|
||||
if (c != EOF)
|
||||
{
|
||||
ungetc (c, stream);
|
||||
c = '\n';
|
||||
}
|
||||
}
|
||||
|
||||
if (c == delim)
|
||||
++field_idx;
|
||||
++field_idx;
|
||||
else if (c == '\n' || c == EOF)
|
||||
{
|
||||
if (found_any_selected_field
|
||||
|| !(suppress_non_delimited && field_idx == 1))
|
||||
putchar ('\n');
|
||||
if (c == EOF)
|
||||
break;
|
||||
field_idx = 1;
|
||||
found_any_selected_field = false;
|
||||
}
|
||||
{
|
||||
if (found_any_selected_field
|
||||
|| !(suppress_non_delimited && field_idx == 1))
|
||||
putchar ('\n');
|
||||
if (c == EOF)
|
||||
break;
|
||||
field_idx = 1;
|
||||
found_any_selected_field = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,10 +727,10 @@ cut_file (char const *file)
|
||||
{
|
||||
stream = fopen (file, "r");
|
||||
if (stream == NULL)
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cut_stream (stream);
|
||||
@@ -777,60 +777,60 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "b:c:d:f:ns", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'b':
|
||||
case 'c':
|
||||
/* Build the byte list. */
|
||||
if (operating_mode != undefined_mode)
|
||||
FATAL_ERROR (_("only one type of list may be specified"));
|
||||
operating_mode = byte_mode;
|
||||
spec_list_string = optarg;
|
||||
break;
|
||||
{
|
||||
case 'b':
|
||||
case 'c':
|
||||
/* Build the byte list. */
|
||||
if (operating_mode != undefined_mode)
|
||||
FATAL_ERROR (_("only one type of list may be specified"));
|
||||
operating_mode = byte_mode;
|
||||
spec_list_string = optarg;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
/* Build the field list. */
|
||||
if (operating_mode != undefined_mode)
|
||||
FATAL_ERROR (_("only one type of list may be specified"));
|
||||
operating_mode = field_mode;
|
||||
spec_list_string = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
/* Build the field list. */
|
||||
if (operating_mode != undefined_mode)
|
||||
FATAL_ERROR (_("only one type of list may be specified"));
|
||||
operating_mode = field_mode;
|
||||
spec_list_string = optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
/* New delimiter. */
|
||||
/* Interpret -d '' to mean `use the NUL byte as the delimiter.' */
|
||||
if (optarg[0] != '\0' && optarg[1] != '\0')
|
||||
FATAL_ERROR (_("the delimiter must be a single character"));
|
||||
delim = optarg[0];
|
||||
delim_specified = true;
|
||||
break;
|
||||
case 'd':
|
||||
/* New delimiter. */
|
||||
/* Interpret -d '' to mean `use the NUL byte as the delimiter.' */
|
||||
if (optarg[0] != '\0' && optarg[1] != '\0')
|
||||
FATAL_ERROR (_("the delimiter must be a single character"));
|
||||
delim = optarg[0];
|
||||
delim_specified = true;
|
||||
break;
|
||||
|
||||
case OUTPUT_DELIMITER_OPTION:
|
||||
output_delimiter_specified = true;
|
||||
/* Interpret --output-delimiter='' to mean
|
||||
`use the NUL byte as the delimiter.' */
|
||||
output_delimiter_length = (optarg[0] == '\0'
|
||||
? 1 : strlen (optarg));
|
||||
output_delimiter_string = xstrdup (optarg);
|
||||
break;
|
||||
case OUTPUT_DELIMITER_OPTION:
|
||||
output_delimiter_specified = true;
|
||||
/* Interpret --output-delimiter='' to mean
|
||||
`use the NUL byte as the delimiter.' */
|
||||
output_delimiter_length = (optarg[0] == '\0'
|
||||
? 1 : strlen (optarg));
|
||||
output_delimiter_string = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
break;
|
||||
case 'n':
|
||||
break;
|
||||
|
||||
case 's':
|
||||
suppress_non_delimited = true;
|
||||
break;
|
||||
case 's':
|
||||
suppress_non_delimited = true;
|
||||
break;
|
||||
|
||||
case COMPLEMENT_OPTION:
|
||||
complement = true;
|
||||
break;
|
||||
case COMPLEMENT_OPTION:
|
||||
complement = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (operating_mode == undefined_mode)
|
||||
@@ -847,19 +847,19 @@ main (int argc, char **argv)
|
||||
if (output_delimiter_specified)
|
||||
{
|
||||
range_start_ht = hash_initialize (HT_RANGE_START_INDEX_INITIAL_CAPACITY,
|
||||
NULL, hash_int,
|
||||
hash_compare_ints, NULL);
|
||||
NULL, hash_int,
|
||||
hash_compare_ints, NULL);
|
||||
if (range_start_ht == NULL)
|
||||
xalloc_die ();
|
||||
xalloc_die ();
|
||||
|
||||
}
|
||||
|
||||
if (! set_fields (spec_list_string))
|
||||
{
|
||||
if (operating_mode == field_mode)
|
||||
FATAL_ERROR (_("missing list of fields"));
|
||||
FATAL_ERROR (_("missing list of fields"));
|
||||
else
|
||||
FATAL_ERROR (_("missing list of positions"));
|
||||
FATAL_ERROR (_("missing list of positions"));
|
||||
}
|
||||
|
||||
if (!delim_specified)
|
||||
|
||||
+160
-160
@@ -118,14 +118,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [+FORMAT]\n\
|
||||
or: %s [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Display the current time in the given FORMAT, or set the system date.\n\
|
||||
\n\
|
||||
@@ -264,9 +264,9 @@ batch_convert (const char *input_filename, const char *format)
|
||||
{
|
||||
in_stream = fopen (input_filename, "r");
|
||||
if (in_stream == NULL)
|
||||
{
|
||||
error (EXIT_FAILURE, errno, "%s", quote (input_filename));
|
||||
}
|
||||
{
|
||||
error (EXIT_FAILURE, errno, "%s", quote (input_filename));
|
||||
}
|
||||
}
|
||||
|
||||
line = NULL;
|
||||
@@ -276,22 +276,22 @@ batch_convert (const char *input_filename, const char *format)
|
||||
{
|
||||
ssize_t line_length = getline (&line, &buflen, in_stream);
|
||||
if (line_length < 0)
|
||||
{
|
||||
/* FIXME: detect/handle error here. */
|
||||
break;
|
||||
}
|
||||
{
|
||||
/* FIXME: detect/handle error here. */
|
||||
break;
|
||||
}
|
||||
|
||||
if (! get_date (&when, line, NULL))
|
||||
{
|
||||
if (line[line_length - 1] == '\n')
|
||||
line[line_length - 1] = '\0';
|
||||
error (0, 0, _("invalid date %s"), quote (line));
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
if (line[line_length - 1] == '\n')
|
||||
line[line_length - 1] = '\0';
|
||||
error (0, 0, _("invalid date %s"), quote (line));
|
||||
ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok &= show_date (format, when);
|
||||
}
|
||||
{
|
||||
ok &= show_date (format, when);
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose (in_stream) == EOF)
|
||||
@@ -326,138 +326,138 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, short_options, long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
char const *new_format = NULL;
|
||||
|
||||
switch (optc)
|
||||
{
|
||||
case 'd':
|
||||
datestr = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
batch_file = optarg;
|
||||
break;
|
||||
case RFC_3339_OPTION:
|
||||
{
|
||||
static char const rfc_3339_format[][32] =
|
||||
{
|
||||
"%Y-%m-%d",
|
||||
"%Y-%m-%d %H:%M:%S%:z",
|
||||
"%Y-%m-%d %H:%M:%S.%N%:z"
|
||||
};
|
||||
enum Time_spec i =
|
||||
XARGMATCH ("--rfc-3339", optarg,
|
||||
time_spec_string + 2, time_spec + 2);
|
||||
new_format = rfc_3339_format[i];
|
||||
break;
|
||||
}
|
||||
case 'I':
|
||||
{
|
||||
static char const iso_8601_format[][32] =
|
||||
{
|
||||
"%Y-%m-%d",
|
||||
"%Y-%m-%dT%H:%M:%S%z",
|
||||
"%Y-%m-%dT%H:%M:%S,%N%z",
|
||||
"%Y-%m-%dT%H%z",
|
||||
"%Y-%m-%dT%H:%M%z"
|
||||
};
|
||||
enum Time_spec i =
|
||||
(optarg
|
||||
? XARGMATCH ("--iso-8601", optarg, time_spec_string, time_spec)
|
||||
: TIME_SPEC_DATE);
|
||||
new_format = iso_8601_format[i];
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
reference = optarg;
|
||||
break;
|
||||
case 'R':
|
||||
new_format = rfc_2822_format;
|
||||
break;
|
||||
case 's':
|
||||
set_datestr = optarg;
|
||||
set_date = true;
|
||||
break;
|
||||
case 'u':
|
||||
/* POSIX says that `date -u' is equivalent to setting the TZ
|
||||
environment variable, so this option should do nothing other
|
||||
than setting TZ. */
|
||||
if (putenv (bad_cast ("TZ=UTC0")) != 0)
|
||||
xalloc_die ();
|
||||
TZSET;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'd':
|
||||
datestr = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
batch_file = optarg;
|
||||
break;
|
||||
case RFC_3339_OPTION:
|
||||
{
|
||||
static char const rfc_3339_format[][32] =
|
||||
{
|
||||
"%Y-%m-%d",
|
||||
"%Y-%m-%d %H:%M:%S%:z",
|
||||
"%Y-%m-%d %H:%M:%S.%N%:z"
|
||||
};
|
||||
enum Time_spec i =
|
||||
XARGMATCH ("--rfc-3339", optarg,
|
||||
time_spec_string + 2, time_spec + 2);
|
||||
new_format = rfc_3339_format[i];
|
||||
break;
|
||||
}
|
||||
case 'I':
|
||||
{
|
||||
static char const iso_8601_format[][32] =
|
||||
{
|
||||
"%Y-%m-%d",
|
||||
"%Y-%m-%dT%H:%M:%S%z",
|
||||
"%Y-%m-%dT%H:%M:%S,%N%z",
|
||||
"%Y-%m-%dT%H%z",
|
||||
"%Y-%m-%dT%H:%M%z"
|
||||
};
|
||||
enum Time_spec i =
|
||||
(optarg
|
||||
? XARGMATCH ("--iso-8601", optarg, time_spec_string, time_spec)
|
||||
: TIME_SPEC_DATE);
|
||||
new_format = iso_8601_format[i];
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
reference = optarg;
|
||||
break;
|
||||
case 'R':
|
||||
new_format = rfc_2822_format;
|
||||
break;
|
||||
case 's':
|
||||
set_datestr = optarg;
|
||||
set_date = true;
|
||||
break;
|
||||
case 'u':
|
||||
/* POSIX says that `date -u' is equivalent to setting the TZ
|
||||
environment variable, so this option should do nothing other
|
||||
than setting TZ. */
|
||||
if (putenv (bad_cast ("TZ=UTC0")) != 0)
|
||||
xalloc_die ();
|
||||
TZSET;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (new_format)
|
||||
{
|
||||
if (format)
|
||||
error (EXIT_FAILURE, 0, _("multiple output formats specified"));
|
||||
format = new_format;
|
||||
}
|
||||
{
|
||||
if (format)
|
||||
error (EXIT_FAILURE, 0, _("multiple output formats specified"));
|
||||
format = new_format;
|
||||
}
|
||||
}
|
||||
|
||||
option_specified_date = ((datestr ? 1 : 0)
|
||||
+ (batch_file ? 1 : 0)
|
||||
+ (reference ? 1 : 0));
|
||||
+ (batch_file ? 1 : 0)
|
||||
+ (reference ? 1 : 0));
|
||||
|
||||
if (option_specified_date > 1)
|
||||
{
|
||||
error (0, 0,
|
||||
_("the options to specify dates for printing are mutually exclusive"));
|
||||
_("the options to specify dates for printing are mutually exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (set_date && option_specified_date)
|
||||
{
|
||||
error (0, 0,
|
||||
_("the options to print and set the time may not be used together"));
|
||||
_("the options to print and set the time may not be used together"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
if (optind + 1 < argc)
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (argv[optind][0] == '+')
|
||||
{
|
||||
if (format)
|
||||
error (EXIT_FAILURE, 0, _("multiple output formats specified"));
|
||||
format = argv[optind++] + 1;
|
||||
}
|
||||
{
|
||||
if (format)
|
||||
error (EXIT_FAILURE, 0, _("multiple output formats specified"));
|
||||
format = argv[optind++] + 1;
|
||||
}
|
||||
else if (set_date || option_specified_date)
|
||||
{
|
||||
error (0, 0,
|
||||
_("the argument %s lacks a leading `+';\n"
|
||||
"when using an option to specify date(s), any non-option\n"
|
||||
"argument must be a format string beginning with `+'"),
|
||||
quote (argv[optind]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0,
|
||||
_("the argument %s lacks a leading `+';\n"
|
||||
"when using an option to specify date(s), any non-option\n"
|
||||
"argument must be a format string beginning with `+'"),
|
||||
quote (argv[optind]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (!format)
|
||||
{
|
||||
format = DATE_FMT_LANGINFO ();
|
||||
if (! *format)
|
||||
{
|
||||
/* Do not wrap the following literal format string with _(...).
|
||||
For example, suppose LC_ALL is unset, LC_TIME="POSIX",
|
||||
and LANG="ko_KR". In that case, POSIX says that LC_TIME
|
||||
determines the format and contents of date and time strings
|
||||
written by date, which means "date" must generate output
|
||||
using the POSIX locale; but adding _() would cause "date"
|
||||
to use a Korean translation of the format. */
|
||||
format = "%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
{
|
||||
/* Do not wrap the following literal format string with _(...).
|
||||
For example, suppose LC_ALL is unset, LC_TIME="POSIX",
|
||||
and LANG="ko_KR". In that case, POSIX says that LC_TIME
|
||||
determines the format and contents of date and time strings
|
||||
written by date, which means "date" must generate output
|
||||
using the POSIX locale; but adding _() would cause "date"
|
||||
to use a Korean translation of the format. */
|
||||
format = "%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
}
|
||||
|
||||
if (batch_file != NULL)
|
||||
@@ -468,55 +468,55 @@ main (int argc, char **argv)
|
||||
ok = true;
|
||||
|
||||
if (!option_specified_date && !set_date)
|
||||
{
|
||||
if (optind < argc)
|
||||
{
|
||||
/* Prepare to set system clock to the specified date/time
|
||||
given in the POSIX-format. */
|
||||
set_date = true;
|
||||
datestr = argv[optind];
|
||||
valid_date = posixtime (&when.tv_sec,
|
||||
datestr,
|
||||
(PDS_TRAILING_YEAR
|
||||
| PDS_CENTURY | PDS_SECONDS));
|
||||
when.tv_nsec = 0; /* FIXME: posixtime should set this. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare to print the current date/time. */
|
||||
gettime (&when);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (optind < argc)
|
||||
{
|
||||
/* Prepare to set system clock to the specified date/time
|
||||
given in the POSIX-format. */
|
||||
set_date = true;
|
||||
datestr = argv[optind];
|
||||
valid_date = posixtime (&when.tv_sec,
|
||||
datestr,
|
||||
(PDS_TRAILING_YEAR
|
||||
| PDS_CENTURY | PDS_SECONDS));
|
||||
when.tv_nsec = 0; /* FIXME: posixtime should set this. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare to print the current date/time. */
|
||||
gettime (&when);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* (option_specified_date || set_date) */
|
||||
if (reference != NULL)
|
||||
{
|
||||
if (stat (reference, &refstats) != 0)
|
||||
error (EXIT_FAILURE, errno, "%s", reference);
|
||||
when = get_stat_mtime (&refstats);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (set_datestr)
|
||||
datestr = set_datestr;
|
||||
valid_date = get_date (&when, datestr, NULL);
|
||||
}
|
||||
}
|
||||
{
|
||||
/* (option_specified_date || set_date) */
|
||||
if (reference != NULL)
|
||||
{
|
||||
if (stat (reference, &refstats) != 0)
|
||||
error (EXIT_FAILURE, errno, "%s", reference);
|
||||
when = get_stat_mtime (&refstats);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (set_datestr)
|
||||
datestr = set_datestr;
|
||||
valid_date = get_date (&when, datestr, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (! valid_date)
|
||||
error (EXIT_FAILURE, 0, _("invalid date %s"), quote (datestr));
|
||||
error (EXIT_FAILURE, 0, _("invalid date %s"), quote (datestr));
|
||||
|
||||
if (set_date)
|
||||
{
|
||||
/* Set the system clock to the specified date, then regardless of
|
||||
the success of that operation, format and print that date. */
|
||||
if (settime (&when) != 0)
|
||||
{
|
||||
error (0, errno, _("cannot set date"));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
{
|
||||
/* Set the system clock to the specified date, then regardless of
|
||||
the success of that operation, format and print that date. */
|
||||
if (settime (&when) != 0)
|
||||
{
|
||||
error (0, errno, _("cannot set date"));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
ok &= show_date (format, when);
|
||||
}
|
||||
|
||||
@@ -158,22 +158,22 @@ print_header (void)
|
||||
else if (human_output_opts & human_autoscale)
|
||||
{
|
||||
if (human_output_opts & human_base_1024)
|
||||
printf (_(" Size Used Avail Use%%"));
|
||||
printf (_(" Size Used Avail Use%%"));
|
||||
else
|
||||
printf (_(" Size Used Avail Use%%"));
|
||||
printf (_(" Size Used Avail Use%%"));
|
||||
}
|
||||
else if (posix_format)
|
||||
printf (_(" %s-blocks Used Available Capacity"),
|
||||
umaxtostr (output_block_size, buf));
|
||||
umaxtostr (output_block_size, buf));
|
||||
else
|
||||
{
|
||||
int opts = (human_suppress_point_zero
|
||||
| human_autoscale | human_SI
|
||||
| (human_output_opts
|
||||
& (human_group_digits | human_base_1024 | human_B)));
|
||||
| human_autoscale | human_SI
|
||||
| (human_output_opts
|
||||
& (human_group_digits | human_base_1024 | human_B)));
|
||||
|
||||
/* Prefer the base that makes the human-readable value more exact,
|
||||
if there is a difference. */
|
||||
if there is a difference. */
|
||||
|
||||
uintmax_t q1000 = output_block_size;
|
||||
uintmax_t q1024 = output_block_size;
|
||||
@@ -181,21 +181,21 @@ print_header (void)
|
||||
bool divisible_by_1024;
|
||||
|
||||
do
|
||||
{
|
||||
divisible_by_1000 = q1000 % 1000 == 0; q1000 /= 1000;
|
||||
divisible_by_1024 = q1024 % 1024 == 0; q1024 /= 1024;
|
||||
}
|
||||
{
|
||||
divisible_by_1000 = q1000 % 1000 == 0; q1000 /= 1000;
|
||||
divisible_by_1024 = q1024 % 1024 == 0; q1024 /= 1024;
|
||||
}
|
||||
while (divisible_by_1000 & divisible_by_1024);
|
||||
|
||||
if (divisible_by_1000 < divisible_by_1024)
|
||||
opts |= human_base_1024;
|
||||
opts |= human_base_1024;
|
||||
if (divisible_by_1024 < divisible_by_1000)
|
||||
opts &= ~human_base_1024;
|
||||
opts &= ~human_base_1024;
|
||||
if (! (opts & human_base_1024))
|
||||
opts |= human_B;
|
||||
opts |= human_B;
|
||||
|
||||
printf (_(" %4s-blocks Used Available Use%%"),
|
||||
human_readable (output_block_size, buf, opts, 1, 1));
|
||||
human_readable (output_block_size, buf, opts, 1, 1));
|
||||
}
|
||||
|
||||
printf (_(" Mounted on\n"));
|
||||
@@ -250,16 +250,16 @@ known_value (uintmax_t n)
|
||||
|
||||
static char const *
|
||||
df_readable (bool negative, uintmax_t n, char *buf,
|
||||
uintmax_t input_units, uintmax_t output_units)
|
||||
uintmax_t input_units, uintmax_t output_units)
|
||||
{
|
||||
if (! known_value (n) && !negative)
|
||||
return "-";
|
||||
else
|
||||
{
|
||||
char *p = human_readable (negative ? -n : n, buf + negative,
|
||||
human_output_opts, input_units, output_units);
|
||||
human_output_opts, input_units, output_units);
|
||||
if (negative)
|
||||
*--p = '-';
|
||||
*--p = '-';
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ df_readable (bool negative, uintmax_t n, char *buf,
|
||||
how the negation flag is used. */
|
||||
static void
|
||||
add_uint_with_neg_flag (uintmax_t *dest, bool *dest_neg,
|
||||
uintmax_t src, bool src_neg)
|
||||
uintmax_t src, bool src_neg)
|
||||
{
|
||||
if (LOG_EQ (*dest_neg, src_neg))
|
||||
{
|
||||
@@ -314,9 +314,9 @@ add_uint_with_neg_flag (uintmax_t *dest, bool *dest_neg,
|
||||
|
||||
static void
|
||||
show_dev (char const *disk, char const *mount_point,
|
||||
char const *stat_file, char const *fstype,
|
||||
bool me_dummy, bool me_remote,
|
||||
const struct fs_usage *force_fsu)
|
||||
char const *stat_file, char const *fstype,
|
||||
bool me_dummy, bool me_remote,
|
||||
const struct fs_usage *force_fsu)
|
||||
{
|
||||
struct fs_usage fsu;
|
||||
char buf[3][LONGEST_HUMAN_READABLE + 2];
|
||||
@@ -379,18 +379,18 @@ show_dev (char const *disk, char const *mount_point,
|
||||
size_t disk_name_len = strlen (disk);
|
||||
size_t fstype_len = strlen (fstype);
|
||||
if (disk_name_len + fstype_len < 18)
|
||||
printf ("%s%*s ", disk, 18 - (int) disk_name_len, fstype);
|
||||
printf ("%s%*s ", disk, 18 - (int) disk_name_len, fstype);
|
||||
else if (!posix_format)
|
||||
printf ("%s\n%18s ", disk, fstype);
|
||||
printf ("%s\n%18s ", disk, fstype);
|
||||
else
|
||||
printf ("%s %s", disk, fstype);
|
||||
printf ("%s %s", disk, fstype);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen (disk) > 20 && !posix_format)
|
||||
printf ("%s\n%20s", disk, "");
|
||||
printf ("%s\n%20s", disk, "");
|
||||
else
|
||||
printf ("%-20s", disk);
|
||||
printf ("%-20s", disk);
|
||||
}
|
||||
|
||||
if (inode_format)
|
||||
@@ -404,44 +404,44 @@ show_dev (char const *disk, char const *mount_point,
|
||||
available_to_root = available;
|
||||
|
||||
if (known_value (total))
|
||||
grand_fsu.fsu_files += total;
|
||||
grand_fsu.fsu_files += total;
|
||||
if (known_value (available))
|
||||
grand_fsu.fsu_ffree += available;
|
||||
grand_fsu.fsu_ffree += available;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (human_output_opts & human_autoscale)
|
||||
width = 5 + ! (human_output_opts & human_base_1024);
|
||||
width = 5 + ! (human_output_opts & human_base_1024);
|
||||
else
|
||||
{
|
||||
width = 9;
|
||||
if (posix_format)
|
||||
{
|
||||
uintmax_t b;
|
||||
col1_adjustment = -3;
|
||||
for (b = output_block_size; 9 < b; b /= 10)
|
||||
col1_adjustment++;
|
||||
}
|
||||
}
|
||||
{
|
||||
width = 9;
|
||||
if (posix_format)
|
||||
{
|
||||
uintmax_t b;
|
||||
col1_adjustment = -3;
|
||||
for (b = output_block_size; 9 < b; b /= 10)
|
||||
col1_adjustment++;
|
||||
}
|
||||
}
|
||||
use_width = ((posix_format
|
||||
&& ! (human_output_opts & human_autoscale))
|
||||
? 8 : 4);
|
||||
&& ! (human_output_opts & human_autoscale))
|
||||
? 8 : 4);
|
||||
input_units = fsu.fsu_blocksize;
|
||||
output_units = output_block_size;
|
||||
total = fsu.fsu_blocks;
|
||||
available = fsu.fsu_bavail;
|
||||
negate_available = (fsu.fsu_bavail_top_bit_set
|
||||
& known_value (available));
|
||||
& known_value (available));
|
||||
available_to_root = fsu.fsu_bfree;
|
||||
|
||||
if (known_value (total))
|
||||
grand_fsu.fsu_blocks += input_units * total;
|
||||
grand_fsu.fsu_blocks += input_units * total;
|
||||
if (known_value (available_to_root))
|
||||
grand_fsu.fsu_bfree += input_units * available_to_root;
|
||||
grand_fsu.fsu_bfree += input_units * available_to_root;
|
||||
if (known_value (available))
|
||||
add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
|
||||
&grand_fsu.fsu_bavail_top_bit_set,
|
||||
input_units * available, negate_available);
|
||||
add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
|
||||
&grand_fsu.fsu_bavail_top_bit_set,
|
||||
input_units * available, negate_available);
|
||||
}
|
||||
|
||||
used = UINTMAX_MAX;
|
||||
@@ -453,20 +453,20 @@ show_dev (char const *disk, char const *mount_point,
|
||||
}
|
||||
|
||||
printf (" %*s %*s %*s ",
|
||||
width + col1_adjustment,
|
||||
df_readable (false, total,
|
||||
buf[0], input_units, output_units),
|
||||
width, df_readable (negate_used, used,
|
||||
buf[1], input_units, output_units),
|
||||
width, df_readable (negate_available, available,
|
||||
buf[2], input_units, output_units));
|
||||
width + col1_adjustment,
|
||||
df_readable (false, total,
|
||||
buf[0], input_units, output_units),
|
||||
width, df_readable (negate_used, used,
|
||||
buf[1], input_units, output_units),
|
||||
width, df_readable (negate_available, available,
|
||||
buf[2], input_units, output_units));
|
||||
|
||||
if (! known_value (used) || ! known_value (available))
|
||||
;
|
||||
else if (!negate_used
|
||||
&& used <= TYPE_MAXIMUM (uintmax_t) / 100
|
||||
&& used + available != 0
|
||||
&& (used + available < used) == negate_available)
|
||||
&& used <= TYPE_MAXIMUM (uintmax_t) / 100
|
||||
&& used + available != 0
|
||||
&& (used + available < used) == negate_available)
|
||||
{
|
||||
uintmax_t u100 = used * 100;
|
||||
uintmax_t nonroot_total = used + available;
|
||||
@@ -475,23 +475,23 @@ show_dev (char const *disk, char const *mount_point,
|
||||
else
|
||||
{
|
||||
/* The calculation cannot be done easily with integer
|
||||
arithmetic. Fall back on floating point. This can suffer
|
||||
from minor rounding errors, but doing it exactly requires
|
||||
multiple precision arithmetic, and it's not worth the
|
||||
aggravation. */
|
||||
arithmetic. Fall back on floating point. This can suffer
|
||||
from minor rounding errors, but doing it exactly requires
|
||||
multiple precision arithmetic, and it's not worth the
|
||||
aggravation. */
|
||||
double u = negate_used ? - (double) - used : used;
|
||||
double a = negate_available ? - (double) - available : available;
|
||||
double nonroot_total = u + a;
|
||||
if (nonroot_total)
|
||||
{
|
||||
long int lipct = pct = u * 100 / nonroot_total;
|
||||
double ipct = lipct;
|
||||
{
|
||||
long int lipct = pct = u * 100 / nonroot_total;
|
||||
double ipct = lipct;
|
||||
|
||||
/* Like `pct = ceil (dpct);', but avoid ceil so that
|
||||
the math library needn't be linked. */
|
||||
if (ipct - 1 < pct && pct <= ipct + 1)
|
||||
pct = ipct + (ipct < pct);
|
||||
}
|
||||
/* Like `pct = ceil (dpct);', but avoid ceil so that
|
||||
the math library needn't be linked. */
|
||||
if (ipct - 1 < pct && pct <= ipct + 1)
|
||||
pct = ipct + (ipct < pct);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 <= pct)
|
||||
@@ -503,12 +503,12 @@ show_dev (char const *disk, char const *mount_point,
|
||||
{
|
||||
#ifdef HIDE_AUTOMOUNT_PREFIX
|
||||
/* Don't print the first directory name in MOUNT_POINT if it's an
|
||||
artifact of an automounter. This is a bit too aggressive to be
|
||||
the default. */
|
||||
artifact of an automounter. This is a bit too aggressive to be
|
||||
the default. */
|
||||
if (strncmp ("/auto/", mount_point, 6) == 0)
|
||||
mount_point += 5;
|
||||
mount_point += 5;
|
||||
else if (strncmp ("/tmp_mnt/", mount_point, 9) == 0)
|
||||
mount_point += 8;
|
||||
mount_point += 8;
|
||||
#endif
|
||||
printf (" %s", mount_point);
|
||||
}
|
||||
@@ -537,10 +537,10 @@ find_mount_point (const char *file, const struct stat *file_stat)
|
||||
{
|
||||
last_stat = *file_stat;
|
||||
if (chdir (file) < 0)
|
||||
{
|
||||
error (0, errno, _("cannot change to directory %s"), quote (file));
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot change to directory %s"), quote (file));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* FILE is some other kind of file; use its directory. */
|
||||
@@ -551,17 +551,17 @@ find_mount_point (const char *file, const struct stat *file_stat)
|
||||
free (xdir);
|
||||
|
||||
if (chdir (dir) < 0)
|
||||
{
|
||||
error (0, errno, _("cannot change to directory %s"), quote (dir));
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot change to directory %s"), quote (dir));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (stat (".", &last_stat) < 0)
|
||||
{
|
||||
error (0, errno, _("cannot stat current directory (now %s)"),
|
||||
quote (dir));
|
||||
goto done;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot stat current directory (now %s)"),
|
||||
quote (dir));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now walk up FILE's parents until we find another file system or /,
|
||||
@@ -571,18 +571,18 @@ find_mount_point (const char *file, const struct stat *file_stat)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat ("..", &st) < 0)
|
||||
{
|
||||
error (0, errno, _("cannot stat %s"), quote (".."));
|
||||
goto done;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot stat %s"), quote (".."));
|
||||
goto done;
|
||||
}
|
||||
if (st.st_dev != last_stat.st_dev || st.st_ino == last_stat.st_ino)
|
||||
/* cwd is the mount point. */
|
||||
break;
|
||||
/* cwd is the mount point. */
|
||||
break;
|
||||
if (chdir ("..") < 0)
|
||||
{
|
||||
error (0, errno, _("cannot change to directory %s"), quote (".."));
|
||||
goto done;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot change to directory %s"), quote (".."));
|
||||
goto done;
|
||||
}
|
||||
last_stat = st;
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ done:
|
||||
int save_errno = errno;
|
||||
if (restore_cwd (&cwd) != 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to return to initial working directory"));
|
||||
_("failed to return to initial working directory"));
|
||||
free_cwd (&cwd);
|
||||
errno = save_errno;
|
||||
}
|
||||
@@ -618,8 +618,8 @@ show_disk (char const *disk)
|
||||
if (best_match)
|
||||
{
|
||||
show_dev (best_match->me_devname, best_match->me_mountdir, NULL,
|
||||
best_match->me_type, best_match->me_dummy,
|
||||
best_match->me_remote, NULL);
|
||||
best_match->me_type, best_match->me_dummy,
|
||||
best_match->me_remote, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -641,12 +641,12 @@ show_point (const char *point, const struct stat *statp)
|
||||
if (*point == '/')
|
||||
{
|
||||
/* Find the best match: prefer non-dummies, and then prefer the
|
||||
last match if there are ties. */
|
||||
last match if there are ties. */
|
||||
|
||||
for (me = mount_list; me; me = me->me_next)
|
||||
if (STREQ (me->me_mountdir, point) && !STREQ (me->me_type, "lofs")
|
||||
&& (!best_match || best_match->me_dummy || !me->me_dummy))
|
||||
best_match = me;
|
||||
if (STREQ (me->me_mountdir, point) && !STREQ (me->me_type, "lofs")
|
||||
&& (!best_match || best_match->me_dummy || !me->me_dummy))
|
||||
best_match = me;
|
||||
}
|
||||
|
||||
/* Calculate the real absolute file name for POINT, and use that to find
|
||||
@@ -657,87 +657,87 @@ show_point (const char *point, const struct stat *statp)
|
||||
char *resolved = canonicalize_file_name (point);
|
||||
|
||||
if (resolved && resolved[0] == '/')
|
||||
{
|
||||
size_t resolved_len = strlen (resolved);
|
||||
size_t best_match_len = 0;
|
||||
{
|
||||
size_t resolved_len = strlen (resolved);
|
||||
size_t best_match_len = 0;
|
||||
|
||||
for (me = mount_list; me; me = me->me_next)
|
||||
if (!STREQ (me->me_type, "lofs")
|
||||
&& (!best_match || best_match->me_dummy || !me->me_dummy))
|
||||
{
|
||||
size_t len = strlen (me->me_mountdir);
|
||||
if (best_match_len <= len && len <= resolved_len
|
||||
&& (len == 1 /* root file system */
|
||||
|| ((len == resolved_len || resolved[len] == '/')
|
||||
&& strncmp (me->me_mountdir, resolved, len) == 0)))
|
||||
{
|
||||
best_match = me;
|
||||
best_match_len = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (me = mount_list; me; me = me->me_next)
|
||||
if (!STREQ (me->me_type, "lofs")
|
||||
&& (!best_match || best_match->me_dummy || !me->me_dummy))
|
||||
{
|
||||
size_t len = strlen (me->me_mountdir);
|
||||
if (best_match_len <= len && len <= resolved_len
|
||||
&& (len == 1 /* root file system */
|
||||
|| ((len == resolved_len || resolved[len] == '/')
|
||||
&& strncmp (me->me_mountdir, resolved, len) == 0)))
|
||||
{
|
||||
best_match = me;
|
||||
best_match_len = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free (resolved);
|
||||
|
||||
if (best_match
|
||||
&& (stat (best_match->me_mountdir, &disk_stats) != 0
|
||||
|| disk_stats.st_dev != statp->st_dev))
|
||||
best_match = NULL;
|
||||
&& (stat (best_match->me_mountdir, &disk_stats) != 0
|
||||
|| disk_stats.st_dev != statp->st_dev))
|
||||
best_match = NULL;
|
||||
}
|
||||
|
||||
if (! best_match)
|
||||
for (me = mount_list; me; me = me->me_next)
|
||||
{
|
||||
if (me->me_dev == (dev_t) -1)
|
||||
{
|
||||
if (stat (me->me_mountdir, &disk_stats) == 0)
|
||||
me->me_dev = disk_stats.st_dev;
|
||||
else
|
||||
{
|
||||
/* Report only I/O errors. Other errors might be
|
||||
caused by shadowed mount points, which means POINT
|
||||
can't possibly be on this file system. */
|
||||
if (errno == EIO)
|
||||
{
|
||||
error (0, errno, "%s", quote (me->me_mountdir));
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
if (me->me_dev == (dev_t) -1)
|
||||
{
|
||||
if (stat (me->me_mountdir, &disk_stats) == 0)
|
||||
me->me_dev = disk_stats.st_dev;
|
||||
else
|
||||
{
|
||||
/* Report only I/O errors. Other errors might be
|
||||
caused by shadowed mount points, which means POINT
|
||||
can't possibly be on this file system. */
|
||||
if (errno == EIO)
|
||||
{
|
||||
error (0, errno, "%s", quote (me->me_mountdir));
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* So we won't try and fail repeatedly. */
|
||||
me->me_dev = (dev_t) -2;
|
||||
}
|
||||
}
|
||||
/* So we won't try and fail repeatedly. */
|
||||
me->me_dev = (dev_t) -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (statp->st_dev == me->me_dev
|
||||
&& !STREQ (me->me_type, "lofs")
|
||||
&& (!best_match || best_match->me_dummy || !me->me_dummy))
|
||||
{
|
||||
/* Skip bogus mtab entries. */
|
||||
if (stat (me->me_mountdir, &disk_stats) != 0
|
||||
|| disk_stats.st_dev != me->me_dev)
|
||||
me->me_dev = (dev_t) -2;
|
||||
else
|
||||
best_match = me;
|
||||
}
|
||||
if (statp->st_dev == me->me_dev
|
||||
&& !STREQ (me->me_type, "lofs")
|
||||
&& (!best_match || best_match->me_dummy || !me->me_dummy))
|
||||
{
|
||||
/* Skip bogus mtab entries. */
|
||||
if (stat (me->me_mountdir, &disk_stats) != 0
|
||||
|| disk_stats.st_dev != me->me_dev)
|
||||
me->me_dev = (dev_t) -2;
|
||||
else
|
||||
best_match = me;
|
||||
}
|
||||
}
|
||||
|
||||
if (best_match)
|
||||
show_dev (best_match->me_devname, best_match->me_mountdir, point,
|
||||
best_match->me_type, best_match->me_dummy, best_match->me_remote,
|
||||
NULL);
|
||||
best_match->me_type, best_match->me_dummy, best_match->me_remote,
|
||||
NULL);
|
||||
else
|
||||
{
|
||||
/* We couldn't find the mount entry corresponding to POINT. Go ahead and
|
||||
print as much info as we can; methods that require the device to be
|
||||
present will fail at a later point. */
|
||||
print as much info as we can; methods that require the device to be
|
||||
present will fail at a later point. */
|
||||
|
||||
/* Find the actual mount point. */
|
||||
char *mp = find_mount_point (point, statp);
|
||||
if (mp)
|
||||
{
|
||||
show_dev (NULL, mp, NULL, NULL, false, false, NULL);
|
||||
free (mp);
|
||||
}
|
||||
{
|
||||
show_dev (NULL, mp, NULL, NULL, false, false, NULL);
|
||||
free (mp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,7 +764,7 @@ show_all_entries (void)
|
||||
|
||||
for (me = mount_list; me; me = me->me_next)
|
||||
show_dev (me->me_devname, me->me_mountdir, NULL, me->me_type,
|
||||
me->me_dummy, me->me_remote, NULL);
|
||||
me->me_dummy, me->me_remote, NULL);
|
||||
}
|
||||
|
||||
/* Add FSTYPE to the list of file system types to display. */
|
||||
@@ -798,7 +798,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... [FILE]...\n"), program_name);
|
||||
@@ -872,93 +872,93 @@ main (int argc, char **argv)
|
||||
{
|
||||
int oi = -1;
|
||||
int c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options,
|
||||
&oi);
|
||||
&oi);
|
||||
if (c == -1)
|
||||
break;
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'a':
|
||||
show_all_fs = true;
|
||||
break;
|
||||
case 'B':
|
||||
{
|
||||
enum strtol_error e = human_options (optarg, &human_output_opts,
|
||||
&output_block_size);
|
||||
if (e != LONGINT_OK)
|
||||
xstrtol_fatal (e, oi, c, long_options, optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
inode_format = true;
|
||||
break;
|
||||
case 'h':
|
||||
human_output_opts = human_autoscale | human_SI | human_base_1024;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case 'H':
|
||||
human_output_opts = human_autoscale | human_SI;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case 'k':
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024;
|
||||
break;
|
||||
case 'l':
|
||||
show_local_fs = true;
|
||||
break;
|
||||
case 'm': /* obsolescent */
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024 * 1024;
|
||||
break;
|
||||
case 'T':
|
||||
print_type = true;
|
||||
break;
|
||||
case 'P':
|
||||
posix_format = true;
|
||||
break;
|
||||
case SYNC_OPTION:
|
||||
require_sync = true;
|
||||
break;
|
||||
case NO_SYNC_OPTION:
|
||||
require_sync = false;
|
||||
break;
|
||||
{
|
||||
case 'a':
|
||||
show_all_fs = true;
|
||||
break;
|
||||
case 'B':
|
||||
{
|
||||
enum strtol_error e = human_options (optarg, &human_output_opts,
|
||||
&output_block_size);
|
||||
if (e != LONGINT_OK)
|
||||
xstrtol_fatal (e, oi, c, long_options, optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
inode_format = true;
|
||||
break;
|
||||
case 'h':
|
||||
human_output_opts = human_autoscale | human_SI | human_base_1024;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case 'H':
|
||||
human_output_opts = human_autoscale | human_SI;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case 'k':
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024;
|
||||
break;
|
||||
case 'l':
|
||||
show_local_fs = true;
|
||||
break;
|
||||
case 'm': /* obsolescent */
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024 * 1024;
|
||||
break;
|
||||
case 'T':
|
||||
print_type = true;
|
||||
break;
|
||||
case 'P':
|
||||
posix_format = true;
|
||||
break;
|
||||
case SYNC_OPTION:
|
||||
require_sync = true;
|
||||
break;
|
||||
case NO_SYNC_OPTION:
|
||||
require_sync = false;
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
/* Accept -F as a synonym for -t for compatibility with Solaris. */
|
||||
case 't':
|
||||
add_fs_type (optarg);
|
||||
break;
|
||||
case 'F':
|
||||
/* Accept -F as a synonym for -t for compatibility with Solaris. */
|
||||
case 't':
|
||||
add_fs_type (optarg);
|
||||
break;
|
||||
|
||||
case 'v': /* For SysV compatibility. */
|
||||
/* ignore */
|
||||
break;
|
||||
case 'x':
|
||||
add_excluded_fs_type (optarg);
|
||||
break;
|
||||
case 'v': /* For SysV compatibility. */
|
||||
/* ignore */
|
||||
break;
|
||||
case 'x':
|
||||
add_excluded_fs_type (optarg);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
print_grand_total = true;
|
||||
break;
|
||||
case 'c':
|
||||
print_grand_total = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (human_output_opts == -1)
|
||||
{
|
||||
if (posix_format)
|
||||
{
|
||||
human_output_opts = 0;
|
||||
output_block_size = (getenv ("POSIXLY_CORRECT") ? 512 : 1024);
|
||||
}
|
||||
{
|
||||
human_output_opts = 0;
|
||||
output_block_size = (getenv ("POSIXLY_CORRECT") ? 512 : 1024);
|
||||
}
|
||||
else
|
||||
human_options (getenv ("DF_BLOCK_SIZE"),
|
||||
&human_output_opts, &output_block_size);
|
||||
human_options (getenv ("DF_BLOCK_SIZE"),
|
||||
&human_output_opts, &output_block_size);
|
||||
}
|
||||
|
||||
/* Fail if the same file system type was both selected and excluded. */
|
||||
@@ -967,18 +967,18 @@ main (int argc, char **argv)
|
||||
struct fs_type_list *fs_incl;
|
||||
for (fs_incl = fs_select_list; fs_incl; fs_incl = fs_incl->fs_next)
|
||||
{
|
||||
struct fs_type_list *fs_excl;
|
||||
for (fs_excl = fs_exclude_list; fs_excl; fs_excl = fs_excl->fs_next)
|
||||
{
|
||||
if (STREQ (fs_incl->fs_name, fs_excl->fs_name))
|
||||
{
|
||||
error (0, 0,
|
||||
_("file system type %s both selected and excluded"),
|
||||
quote (fs_incl->fs_name));
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
struct fs_type_list *fs_excl;
|
||||
for (fs_excl = fs_exclude_list; fs_excl; fs_excl = fs_excl->fs_next)
|
||||
{
|
||||
if (STREQ (fs_incl->fs_name, fs_excl->fs_name))
|
||||
{
|
||||
error (0, 0,
|
||||
_("file system type %s both selected and excluded"),
|
||||
quote (fs_incl->fs_name));
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match)
|
||||
exit (EXIT_FAILURE);
|
||||
@@ -989,38 +989,38 @@ main (int argc, char **argv)
|
||||
int i;
|
||||
|
||||
/* Open each of the given entries to make sure any corresponding
|
||||
partition is automounted. This must be done before reading the
|
||||
file system table. */
|
||||
partition is automounted. This must be done before reading the
|
||||
file system table. */
|
||||
stats = xnmalloc (argc - optind, sizeof *stats);
|
||||
for (i = optind; i < argc; ++i)
|
||||
{
|
||||
int fd = open (argv[i], O_RDONLY | O_NOCTTY);
|
||||
if (fd < 0 || fstat (fd, &stats[i - optind]))
|
||||
{
|
||||
error (0, errno, "%s", quote (argv[i]));
|
||||
exit_status = EXIT_FAILURE;
|
||||
argv[i] = NULL;
|
||||
}
|
||||
if (0 <= fd)
|
||||
close (fd);
|
||||
}
|
||||
{
|
||||
int fd = open (argv[i], O_RDONLY | O_NOCTTY);
|
||||
if (fd < 0 || fstat (fd, &stats[i - optind]))
|
||||
{
|
||||
error (0, errno, "%s", quote (argv[i]));
|
||||
exit_status = EXIT_FAILURE;
|
||||
argv[i] = NULL;
|
||||
}
|
||||
if (0 <= fd)
|
||||
close (fd);
|
||||
}
|
||||
}
|
||||
|
||||
mount_list =
|
||||
read_file_system_list ((fs_select_list != NULL
|
||||
|| fs_exclude_list != NULL
|
||||
|| print_type
|
||||
|| show_local_fs));
|
||||
|| fs_exclude_list != NULL
|
||||
|| print_type
|
||||
|| show_local_fs));
|
||||
|
||||
if (mount_list == NULL)
|
||||
{
|
||||
/* Couldn't read the table of mounted file systems.
|
||||
Fail if df was invoked with no file name arguments;
|
||||
Otherwise, merely give a warning and proceed. */
|
||||
Fail if df was invoked with no file name arguments;
|
||||
Otherwise, merely give a warning and proceed. */
|
||||
int status = (optind < argc ? 0 : EXIT_FAILURE);
|
||||
const char *warning = (optind < argc ? _("Warning: ") : "");
|
||||
error (status, errno, "%s%s", warning,
|
||||
_("cannot read table of mounted file systems"));
|
||||
_("cannot read table of mounted file systems"));
|
||||
}
|
||||
|
||||
if (require_sync)
|
||||
@@ -1034,8 +1034,8 @@ main (int argc, char **argv)
|
||||
show_listed_fs = true;
|
||||
|
||||
for (i = optind; i < argc; ++i)
|
||||
if (argv[i])
|
||||
show_entry (argv[i], &stats[i - optind]);
|
||||
if (argv[i])
|
||||
show_entry (argv[i], &stats[i - optind]);
|
||||
}
|
||||
else
|
||||
show_all_entries ();
|
||||
@@ -1043,7 +1043,7 @@ main (int argc, char **argv)
|
||||
if (print_grand_total)
|
||||
{
|
||||
if (inode_format)
|
||||
grand_fsu.fsu_blocks = 1;
|
||||
grand_fsu.fsu_blocks = 1;
|
||||
show_dev ("total", NULL, NULL, NULL, false, false, &grand_fsu);
|
||||
}
|
||||
|
||||
|
||||
+148
-148
@@ -198,29 +198,29 @@ append_quoted (const char *str)
|
||||
while (*str != '\0')
|
||||
{
|
||||
switch (*str)
|
||||
{
|
||||
case '\'':
|
||||
APPEND_CHAR ('\'');
|
||||
APPEND_CHAR ('\\');
|
||||
APPEND_CHAR ('\'');
|
||||
need_backslash = true;
|
||||
break;
|
||||
{
|
||||
case '\'':
|
||||
APPEND_CHAR ('\'');
|
||||
APPEND_CHAR ('\\');
|
||||
APPEND_CHAR ('\'');
|
||||
need_backslash = true;
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
case '^':
|
||||
need_backslash = !need_backslash;
|
||||
break;
|
||||
case '\\':
|
||||
case '^':
|
||||
need_backslash = !need_backslash;
|
||||
break;
|
||||
|
||||
case ':':
|
||||
case '=':
|
||||
if (need_backslash)
|
||||
APPEND_CHAR ('\\');
|
||||
/* Fall through */
|
||||
case ':':
|
||||
case '=':
|
||||
if (need_backslash)
|
||||
APPEND_CHAR ('\\');
|
||||
/* Fall through */
|
||||
|
||||
default:
|
||||
need_backslash = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
need_backslash = true;
|
||||
break;
|
||||
}
|
||||
|
||||
APPEND_CHAR (*str);
|
||||
++str;
|
||||
@@ -261,106 +261,106 @@ dc_parse_stream (FILE *fp, const char *filename)
|
||||
++line_number;
|
||||
|
||||
if (fp)
|
||||
{
|
||||
if (getline (&input_line, &input_line_size, fp) <= 0)
|
||||
{
|
||||
free (input_line);
|
||||
break;
|
||||
}
|
||||
line = input_line;
|
||||
}
|
||||
{
|
||||
if (getline (&input_line, &input_line_size, fp) <= 0)
|
||||
{
|
||||
free (input_line);
|
||||
break;
|
||||
}
|
||||
line = input_line;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (next_G_line == G_line + sizeof G_line)
|
||||
break;
|
||||
line = next_G_line;
|
||||
next_G_line += strlen (next_G_line) + 1;
|
||||
}
|
||||
{
|
||||
if (next_G_line == G_line + sizeof G_line)
|
||||
break;
|
||||
line = next_G_line;
|
||||
next_G_line += strlen (next_G_line) + 1;
|
||||
}
|
||||
|
||||
parse_line (line, &keywd, &arg);
|
||||
|
||||
if (keywd == NULL)
|
||||
continue;
|
||||
continue;
|
||||
|
||||
if (arg == NULL)
|
||||
{
|
||||
error (0, 0, _("%s:%lu: invalid line; missing second token"),
|
||||
filename, (unsigned long int) line_number);
|
||||
ok = false;
|
||||
free (keywd);
|
||||
continue;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("%s:%lu: invalid line; missing second token"),
|
||||
filename, (unsigned long int) line_number);
|
||||
ok = false;
|
||||
free (keywd);
|
||||
continue;
|
||||
}
|
||||
|
||||
unrecognized = false;
|
||||
if (c_strcasecmp (keywd, "TERM") == 0)
|
||||
{
|
||||
if (STREQ (arg, term))
|
||||
state = ST_TERMSURE;
|
||||
else if (state != ST_TERMSURE)
|
||||
state = ST_TERMNO;
|
||||
}
|
||||
{
|
||||
if (STREQ (arg, term))
|
||||
state = ST_TERMSURE;
|
||||
else if (state != ST_TERMSURE)
|
||||
state = ST_TERMNO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state == ST_TERMSURE)
|
||||
state = ST_TERMYES; /* Another TERM can cancel */
|
||||
{
|
||||
if (state == ST_TERMSURE)
|
||||
state = ST_TERMYES; /* Another TERM can cancel */
|
||||
|
||||
if (state != ST_TERMNO)
|
||||
{
|
||||
if (keywd[0] == '.')
|
||||
{
|
||||
APPEND_CHAR ('*');
|
||||
append_quoted (keywd);
|
||||
APPEND_CHAR ('=');
|
||||
append_quoted (arg);
|
||||
APPEND_CHAR (':');
|
||||
}
|
||||
else if (keywd[0] == '*')
|
||||
{
|
||||
append_quoted (keywd);
|
||||
APPEND_CHAR ('=');
|
||||
append_quoted (arg);
|
||||
APPEND_CHAR (':');
|
||||
}
|
||||
else if (c_strcasecmp (keywd, "OPTIONS") == 0
|
||||
|| c_strcasecmp (keywd, "COLOR") == 0
|
||||
|| c_strcasecmp (keywd, "EIGHTBIT") == 0)
|
||||
{
|
||||
/* Ignore. */
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
if (state != ST_TERMNO)
|
||||
{
|
||||
if (keywd[0] == '.')
|
||||
{
|
||||
APPEND_CHAR ('*');
|
||||
append_quoted (keywd);
|
||||
APPEND_CHAR ('=');
|
||||
append_quoted (arg);
|
||||
APPEND_CHAR (':');
|
||||
}
|
||||
else if (keywd[0] == '*')
|
||||
{
|
||||
append_quoted (keywd);
|
||||
APPEND_CHAR ('=');
|
||||
append_quoted (arg);
|
||||
APPEND_CHAR (':');
|
||||
}
|
||||
else if (c_strcasecmp (keywd, "OPTIONS") == 0
|
||||
|| c_strcasecmp (keywd, "COLOR") == 0
|
||||
|| c_strcasecmp (keywd, "EIGHTBIT") == 0)
|
||||
{
|
||||
/* Ignore. */
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; slack_codes[i] != NULL; ++i)
|
||||
if (c_strcasecmp (keywd, slack_codes[i]) == 0)
|
||||
break;
|
||||
for (i = 0; slack_codes[i] != NULL; ++i)
|
||||
if (c_strcasecmp (keywd, slack_codes[i]) == 0)
|
||||
break;
|
||||
|
||||
if (slack_codes[i] != NULL)
|
||||
{
|
||||
APPEND_TWO_CHAR_STRING (ls_codes[i]);
|
||||
APPEND_CHAR ('=');
|
||||
append_quoted (arg);
|
||||
APPEND_CHAR (':');
|
||||
}
|
||||
else
|
||||
{
|
||||
unrecognized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unrecognized = true;
|
||||
}
|
||||
}
|
||||
if (slack_codes[i] != NULL)
|
||||
{
|
||||
APPEND_TWO_CHAR_STRING (ls_codes[i]);
|
||||
APPEND_CHAR ('=');
|
||||
append_quoted (arg);
|
||||
APPEND_CHAR (':');
|
||||
}
|
||||
else
|
||||
{
|
||||
unrecognized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unrecognized = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (unrecognized && (state == ST_TERMSURE || state == ST_TERMYES))
|
||||
{
|
||||
error (0, 0, _("%s:%lu: unrecognized keyword %s"),
|
||||
(filename ? quote (filename) : _("<internal>")),
|
||||
(unsigned long int) line_number, keywd);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("%s:%lu: unrecognized keyword %s"),
|
||||
(filename ? quote (filename) : _("<internal>")),
|
||||
(unsigned long int) line_number, keywd);
|
||||
ok = false;
|
||||
}
|
||||
|
||||
free (keywd);
|
||||
free (arg);
|
||||
@@ -411,23 +411,23 @@ main (int argc, char **argv)
|
||||
switch (optc)
|
||||
{
|
||||
case 'b': /* Bourne shell syntax. */
|
||||
syntax = SHELL_SYNTAX_BOURNE;
|
||||
break;
|
||||
syntax = SHELL_SYNTAX_BOURNE;
|
||||
break;
|
||||
|
||||
case 'c': /* C shell syntax. */
|
||||
syntax = SHELL_SYNTAX_C;
|
||||
break;
|
||||
syntax = SHELL_SYNTAX_C;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
print_database = true;
|
||||
break;
|
||||
print_database = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
@@ -438,7 +438,7 @@ main (int argc, char **argv)
|
||||
if (print_database && syntax != SHELL_SYNTAX_UNKNOWN)
|
||||
{
|
||||
error (0, 0,
|
||||
_("the options to output dircolors' internal database and\n\
|
||||
_("the options to output dircolors' internal database and\n\
|
||||
to select a shell syntax are mutually exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
@@ -447,9 +447,9 @@ to select a shell syntax are mutually exclusive"));
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (argv[!print_database]));
|
||||
if (print_database)
|
||||
fprintf (stderr, "%s\n",
|
||||
_("file operands cannot be combined with "
|
||||
"--print-database (-p)"));
|
||||
fprintf (stderr, "%s\n",
|
||||
_("file operands cannot be combined with "
|
||||
"--print-database (-p)"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -457,51 +457,51 @@ to select a shell syntax are mutually exclusive"));
|
||||
{
|
||||
char const *p = G_line;
|
||||
while (p < G_line + sizeof G_line)
|
||||
{
|
||||
puts (p);
|
||||
p += strlen (p) + 1;
|
||||
}
|
||||
{
|
||||
puts (p);
|
||||
p += strlen (p) + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If shell syntax was not explicitly specified, try to guess it. */
|
||||
if (syntax == SHELL_SYNTAX_UNKNOWN)
|
||||
{
|
||||
syntax = guess_shell_syntax ();
|
||||
if (syntax == SHELL_SYNTAX_UNKNOWN)
|
||||
{
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("no SHELL environment variable, and no shell type option given"));
|
||||
}
|
||||
}
|
||||
{
|
||||
syntax = guess_shell_syntax ();
|
||||
if (syntax == SHELL_SYNTAX_UNKNOWN)
|
||||
{
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("no SHELL environment variable, and no shell type option given"));
|
||||
}
|
||||
}
|
||||
|
||||
obstack_init (&lsc_obstack);
|
||||
if (argc == 0)
|
||||
ok = dc_parse_stream (NULL, NULL);
|
||||
ok = dc_parse_stream (NULL, NULL);
|
||||
else
|
||||
ok = dc_parse_file (argv[0]);
|
||||
ok = dc_parse_file (argv[0]);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
size_t len = obstack_object_size (&lsc_obstack);
|
||||
char *s = obstack_finish (&lsc_obstack);
|
||||
const char *prefix;
|
||||
const char *suffix;
|
||||
{
|
||||
size_t len = obstack_object_size (&lsc_obstack);
|
||||
char *s = obstack_finish (&lsc_obstack);
|
||||
const char *prefix;
|
||||
const char *suffix;
|
||||
|
||||
if (syntax == SHELL_SYNTAX_BOURNE)
|
||||
{
|
||||
prefix = "LS_COLORS='";
|
||||
suffix = "';\nexport LS_COLORS\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix = "setenv LS_COLORS '";
|
||||
suffix = "'\n";
|
||||
}
|
||||
fputs (prefix, stdout);
|
||||
fwrite (s, 1, len, stdout);
|
||||
fputs (suffix, stdout);
|
||||
}
|
||||
if (syntax == SHELL_SYNTAX_BOURNE)
|
||||
{
|
||||
prefix = "LS_COLORS='";
|
||||
suffix = "';\nexport LS_COLORS\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix = "setenv LS_COLORS '";
|
||||
suffix = "'\n";
|
||||
}
|
||||
fputs (prefix, stdout);
|
||||
fwrite (s, 1, len, stdout);
|
||||
fputs (suffix, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ TERM xterm-debian
|
||||
RESET 0 # reset to "normal" color
|
||||
DIR 01;34 # directory
|
||||
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
|
||||
# numerical value, the color is as for the file pointed to.)
|
||||
# numerical value, the color is as for the file pointed to.)
|
||||
MULTIHARDLINK 00 # regular file with more than one link
|
||||
FIFO 40;33 # pipe
|
||||
SOCK 01;35 # socket
|
||||
|
||||
+4
-4
@@ -39,14 +39,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s NAME\n\
|
||||
or: %s OPTION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Print NAME with its trailing /component removed; if NAME contains no /'s,\n\
|
||||
output `.' (meaning the current directory).\n\
|
||||
@@ -60,7 +60,7 @@ Examples:\n\
|
||||
%s /usr/bin/sort Output \"/usr/bin\".\n\
|
||||
%s stdio.h Output \".\".\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -82,7 +82,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -396,7 +396,7 @@ static void
|
||||
hash_init (void)
|
||||
{
|
||||
htab = hash_initialize (INITIAL_TABLE_SIZE, NULL,
|
||||
entry_hash, entry_compare, free);
|
||||
entry_hash, entry_compare, free);
|
||||
if (htab == NULL)
|
||||
xalloc_die ();
|
||||
}
|
||||
@@ -427,7 +427,7 @@ print_only_size (uintmax_t n_bytes)
|
||||
{
|
||||
char buf[LONGEST_HUMAN_READABLE + 1];
|
||||
fputs (human_readable (n_bytes, buf, human_output_opts,
|
||||
1, output_block_size), stdout);
|
||||
1, output_block_size), stdout);
|
||||
}
|
||||
|
||||
/* Print size (and optionally time) indicated by *PDUI, followed by STRING. */
|
||||
@@ -492,7 +492,7 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
|
||||
case FTS_DNR:
|
||||
/* Don't return just yet, since although the directory is not readable,
|
||||
we were able to stat it, so we do have a size. */
|
||||
we were able to stat it, so we do have a size. */
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"), quote (file));
|
||||
ok = false;
|
||||
break;
|
||||
@@ -512,25 +512,25 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
via a hard link, then don't let it contribute to the sums. */
|
||||
if (skip
|
||||
|| (!opt_count_all
|
||||
&& ! S_ISDIR (sb->st_mode)
|
||||
&& 1 < sb->st_nlink
|
||||
&& ! hash_ins (sb->st_ino, sb->st_dev)))
|
||||
&& ! S_ISDIR (sb->st_mode)
|
||||
&& 1 < sb->st_nlink
|
||||
&& ! hash_ins (sb->st_ino, sb->st_dev)))
|
||||
{
|
||||
/* Note that we must not simply return here.
|
||||
We still have to update prev_level and maybe propagate
|
||||
some sums up the hierarchy. */
|
||||
We still have to update prev_level and maybe propagate
|
||||
some sums up the hierarchy. */
|
||||
duinfo_init (&dui);
|
||||
print = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
duinfo_set (&dui,
|
||||
(apparent_size
|
||||
? sb->st_size
|
||||
: (uintmax_t) ST_NBLOCKS (*sb) * ST_NBLOCKSIZE),
|
||||
(time_type == time_mtime ? get_stat_mtime (sb)
|
||||
: time_type == time_atime ? get_stat_atime (sb)
|
||||
: get_stat_ctime (sb)));
|
||||
(apparent_size
|
||||
? sb->st_size
|
||||
: (uintmax_t) ST_NBLOCKS (*sb) * ST_NBLOCKSIZE),
|
||||
(time_type == time_mtime ? get_stat_mtime (sb)
|
||||
: time_type == time_atime ? get_stat_atime (sb)
|
||||
: get_stat_ctime (sb)));
|
||||
}
|
||||
|
||||
level = ent->fts_level;
|
||||
@@ -544,44 +544,44 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
else
|
||||
{
|
||||
if (level == prev_level)
|
||||
{
|
||||
/* This is usually the most common case. Do nothing. */
|
||||
}
|
||||
{
|
||||
/* This is usually the most common case. Do nothing. */
|
||||
}
|
||||
else if (level > prev_level)
|
||||
{
|
||||
/* Descending the hierarchy.
|
||||
Clear the accumulators for *all* levels between prev_level
|
||||
and the current one. The depth may change dramatically,
|
||||
e.g., from 1 to 10. */
|
||||
size_t i;
|
||||
{
|
||||
/* Descending the hierarchy.
|
||||
Clear the accumulators for *all* levels between prev_level
|
||||
and the current one. The depth may change dramatically,
|
||||
e.g., from 1 to 10. */
|
||||
size_t i;
|
||||
|
||||
if (n_alloc <= level)
|
||||
{
|
||||
dulvl = xnrealloc (dulvl, level, 2 * sizeof *dulvl);
|
||||
n_alloc = level * 2;
|
||||
}
|
||||
if (n_alloc <= level)
|
||||
{
|
||||
dulvl = xnrealloc (dulvl, level, 2 * sizeof *dulvl);
|
||||
n_alloc = level * 2;
|
||||
}
|
||||
|
||||
for (i = prev_level + 1; i <= level; i++)
|
||||
{
|
||||
duinfo_init (&dulvl[i].ent);
|
||||
duinfo_init (&dulvl[i].subdir);
|
||||
}
|
||||
}
|
||||
for (i = prev_level + 1; i <= level; i++)
|
||||
{
|
||||
duinfo_init (&dulvl[i].ent);
|
||||
duinfo_init (&dulvl[i].subdir);
|
||||
}
|
||||
}
|
||||
else /* level < prev_level */
|
||||
{
|
||||
/* Ascending the hierarchy.
|
||||
Process a directory only after all entries in that
|
||||
directory have been processed. When the depth decreases,
|
||||
propagate sums from the children (prev_level) to the parent.
|
||||
Here, the current level is always one smaller than the
|
||||
previous one. */
|
||||
assert (level == prev_level - 1);
|
||||
duinfo_add (&dui_to_print, &dulvl[prev_level].ent);
|
||||
if (!opt_separate_dirs)
|
||||
duinfo_add (&dui_to_print, &dulvl[prev_level].subdir);
|
||||
duinfo_add (&dulvl[level].subdir, &dulvl[prev_level].ent);
|
||||
duinfo_add (&dulvl[level].subdir, &dulvl[prev_level].subdir);
|
||||
}
|
||||
{
|
||||
/* Ascending the hierarchy.
|
||||
Process a directory only after all entries in that
|
||||
directory have been processed. When the depth decreases,
|
||||
propagate sums from the children (prev_level) to the parent.
|
||||
Here, the current level is always one smaller than the
|
||||
previous one. */
|
||||
assert (level == prev_level - 1);
|
||||
duinfo_add (&dui_to_print, &dulvl[prev_level].ent);
|
||||
if (!opt_separate_dirs)
|
||||
duinfo_add (&dui_to_print, &dulvl[prev_level].subdir);
|
||||
duinfo_add (&dulvl[level].subdir, &dulvl[prev_level].ent);
|
||||
duinfo_add (&dulvl[level].subdir, &dulvl[prev_level].subdir);
|
||||
}
|
||||
}
|
||||
|
||||
prev_level = level;
|
||||
@@ -623,28 +623,28 @@ du_files (char **files, int bit_flags)
|
||||
FTS *fts = xfts_open (files, bit_flags, NULL);
|
||||
|
||||
while (1)
|
||||
{
|
||||
FTSENT *ent;
|
||||
{
|
||||
FTSENT *ent;
|
||||
|
||||
ent = fts_read (fts);
|
||||
if (ent == NULL)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
FTS_CROSS_CHECK (fts);
|
||||
ent = fts_read (fts);
|
||||
if (ent == NULL)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
FTS_CROSS_CHECK (fts);
|
||||
|
||||
ok &= process_file (fts, ent);
|
||||
}
|
||||
ok &= process_file (fts, ent);
|
||||
}
|
||||
|
||||
/* Ignore failure, since the only way it can do so is in failing to
|
||||
return to the original directory, and since we're about to exit,
|
||||
that doesn't matter. */
|
||||
return to the original directory, and since we're about to exit,
|
||||
that doesn't matter. */
|
||||
fts_close (fts);
|
||||
}
|
||||
|
||||
@@ -683,162 +683,162 @@ main (int argc, char **argv)
|
||||
exclude = new_exclude ();
|
||||
|
||||
human_options (getenv ("DU_BLOCK_SIZE"),
|
||||
&human_output_opts, &output_block_size);
|
||||
&human_output_opts, &output_block_size);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int oi = -1;
|
||||
int c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
|
||||
long_options, &oi);
|
||||
long_options, &oi);
|
||||
if (c == -1)
|
||||
break;
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
{
|
||||
#if DU_DEBUG
|
||||
case 'd':
|
||||
fts_debug = true;
|
||||
break;
|
||||
case 'd':
|
||||
fts_debug = true;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case '0':
|
||||
opt_nul_terminate_output = true;
|
||||
break;
|
||||
case '0':
|
||||
opt_nul_terminate_output = true;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
opt_all = true;
|
||||
break;
|
||||
case 'a':
|
||||
opt_all = true;
|
||||
break;
|
||||
|
||||
case APPARENT_SIZE_OPTION:
|
||||
apparent_size = true;
|
||||
break;
|
||||
case APPARENT_SIZE_OPTION:
|
||||
apparent_size = true;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
apparent_size = true;
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case 'b':
|
||||
apparent_size = true;
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
print_grand_total = true;
|
||||
break;
|
||||
case 'c':
|
||||
print_grand_total = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
human_output_opts = human_autoscale | human_SI | human_base_1024;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case 'h':
|
||||
human_output_opts = human_autoscale | human_SI | human_base_1024;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
|
||||
case HUMAN_SI_OPTION:
|
||||
human_output_opts = human_autoscale | human_SI;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
case HUMAN_SI_OPTION:
|
||||
human_output_opts = human_autoscale | human_SI;
|
||||
output_block_size = 1;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024;
|
||||
break;
|
||||
case 'k':
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024;
|
||||
break;
|
||||
|
||||
case MAX_DEPTH_OPTION: /* --max-depth=N */
|
||||
{
|
||||
unsigned long int tmp_ulong;
|
||||
if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
|
||||
&& tmp_ulong <= SIZE_MAX)
|
||||
{
|
||||
max_depth_specified = true;
|
||||
max_depth = tmp_ulong;
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, 0, _("invalid maximum depth %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MAX_DEPTH_OPTION: /* --max-depth=N */
|
||||
{
|
||||
unsigned long int tmp_ulong;
|
||||
if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
|
||||
&& tmp_ulong <= SIZE_MAX)
|
||||
{
|
||||
max_depth_specified = true;
|
||||
max_depth = tmp_ulong;
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, 0, _("invalid maximum depth %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MEGABYTES_LONG_OPTION: /* FIXME: remove in 2009 */
|
||||
error (0, 0,
|
||||
_("the --megabytes option is deprecated; use -m instead"));
|
||||
/* fall through */
|
||||
case 'm':
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024 * 1024;
|
||||
break;
|
||||
case MEGABYTES_LONG_OPTION: /* FIXME: remove in 2009 */
|
||||
error (0, 0,
|
||||
_("the --megabytes option is deprecated; use -m instead"));
|
||||
/* fall through */
|
||||
case 'm':
|
||||
human_output_opts = 0;
|
||||
output_block_size = 1024 * 1024;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
opt_count_all = true;
|
||||
break;
|
||||
case 'l':
|
||||
opt_count_all = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
opt_summarize_only = true;
|
||||
break;
|
||||
case 's':
|
||||
opt_summarize_only = true;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
bit_flags |= FTS_XDEV;
|
||||
break;
|
||||
case 'x':
|
||||
bit_flags |= FTS_XDEV;
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
{
|
||||
enum strtol_error e = human_options (optarg, &human_output_opts,
|
||||
&output_block_size);
|
||||
if (e != LONGINT_OK)
|
||||
xstrtol_fatal (e, oi, c, long_options, optarg);
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
{
|
||||
enum strtol_error e = human_options (optarg, &human_output_opts,
|
||||
&output_block_size);
|
||||
if (e != LONGINT_OK)
|
||||
xstrtol_fatal (e, oi, c, long_options, optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'H': /* NOTE: before 2008-12, -H was equivalent to --si. */
|
||||
case 'D':
|
||||
symlink_deref_bits = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
case 'H': /* NOTE: before 2008-12, -H was equivalent to --si. */
|
||||
case 'D':
|
||||
symlink_deref_bits = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'L': /* --dereference */
|
||||
symlink_deref_bits = FTS_LOGICAL;
|
||||
break;
|
||||
case 'L': /* --dereference */
|
||||
symlink_deref_bits = FTS_LOGICAL;
|
||||
break;
|
||||
|
||||
case 'P': /* --no-dereference */
|
||||
symlink_deref_bits = FTS_PHYSICAL;
|
||||
break;
|
||||
case 'P': /* --no-dereference */
|
||||
symlink_deref_bits = FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
opt_separate_dirs = true;
|
||||
break;
|
||||
case 'S':
|
||||
opt_separate_dirs = true;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
if (add_exclude_file (add_exclude, exclude, optarg,
|
||||
EXCLUDE_WILDCARDS, '\n'))
|
||||
{
|
||||
error (0, errno, "%s", quotearg_colon (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
if (add_exclude_file (add_exclude, exclude, optarg,
|
||||
EXCLUDE_WILDCARDS, '\n'))
|
||||
{
|
||||
error (0, errno, "%s", quotearg_colon (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case FILES0_FROM_OPTION:
|
||||
files_from = optarg;
|
||||
break;
|
||||
case FILES0_FROM_OPTION:
|
||||
files_from = optarg;
|
||||
break;
|
||||
|
||||
case EXCLUDE_OPTION:
|
||||
add_exclude (exclude, optarg, EXCLUDE_WILDCARDS);
|
||||
break;
|
||||
case EXCLUDE_OPTION:
|
||||
add_exclude (exclude, optarg, EXCLUDE_WILDCARDS);
|
||||
break;
|
||||
|
||||
case TIME_OPTION:
|
||||
opt_time = true;
|
||||
time_type =
|
||||
(optarg
|
||||
? XARGMATCH ("--time", optarg, time_args, time_types)
|
||||
: time_mtime);
|
||||
break;
|
||||
case TIME_OPTION:
|
||||
opt_time = true;
|
||||
time_type =
|
||||
(optarg
|
||||
? XARGMATCH ("--time", optarg, time_args, time_types)
|
||||
: time_mtime);
|
||||
break;
|
||||
|
||||
case TIME_STYLE_OPTION:
|
||||
time_style = optarg;
|
||||
break;
|
||||
case TIME_STYLE_OPTION:
|
||||
time_style = optarg;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
ok = false;
|
||||
}
|
||||
default:
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
@@ -853,7 +853,7 @@ main (int argc, char **argv)
|
||||
if (opt_summarize_only && max_depth_specified && max_depth == 0)
|
||||
{
|
||||
error (0, 0,
|
||||
_("warning: summarizing is the same as using --max-depth=0"));
|
||||
_("warning: summarizing is the same as using --max-depth=0"));
|
||||
}
|
||||
|
||||
if (opt_summarize_only && max_depth_specified && max_depth != 0)
|
||||
@@ -870,48 +870,48 @@ main (int argc, char **argv)
|
||||
if (opt_time)
|
||||
{
|
||||
if (! time_style)
|
||||
{
|
||||
time_style = getenv ("TIME_STYLE");
|
||||
{
|
||||
time_style = getenv ("TIME_STYLE");
|
||||
|
||||
/* Ignore TIMESTYLE="locale", for compatibility with ls. */
|
||||
if (! time_style || STREQ (time_style, "locale"))
|
||||
time_style = "long-iso";
|
||||
else if (*time_style == '+')
|
||||
{
|
||||
/* Ignore anything after a newline, for compatibility
|
||||
with ls. */
|
||||
char *p = strchr (time_style, '\n');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Ignore "posix-" prefix, for compatibility with ls. */
|
||||
static char const posix_prefix[] = "posix-";
|
||||
while (strncmp (time_style, posix_prefix, sizeof posix_prefix - 1)
|
||||
== 0)
|
||||
time_style += sizeof posix_prefix - 1;
|
||||
}
|
||||
}
|
||||
/* Ignore TIMESTYLE="locale", for compatibility with ls. */
|
||||
if (! time_style || STREQ (time_style, "locale"))
|
||||
time_style = "long-iso";
|
||||
else if (*time_style == '+')
|
||||
{
|
||||
/* Ignore anything after a newline, for compatibility
|
||||
with ls. */
|
||||
char *p = strchr (time_style, '\n');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Ignore "posix-" prefix, for compatibility with ls. */
|
||||
static char const posix_prefix[] = "posix-";
|
||||
while (strncmp (time_style, posix_prefix, sizeof posix_prefix - 1)
|
||||
== 0)
|
||||
time_style += sizeof posix_prefix - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (*time_style == '+')
|
||||
time_format = time_style + 1;
|
||||
time_format = time_style + 1;
|
||||
else
|
||||
{
|
||||
switch (XARGMATCH ("time style", time_style,
|
||||
time_style_args, time_style_types))
|
||||
{
|
||||
case full_iso_time_style:
|
||||
time_format = "%Y-%m-%d %H:%M:%S.%N %z";
|
||||
break;
|
||||
case full_iso_time_style:
|
||||
time_format = "%Y-%m-%d %H:%M:%S.%N %z";
|
||||
break;
|
||||
|
||||
case long_iso_time_style:
|
||||
time_format = "%Y-%m-%d %H:%M";
|
||||
break;
|
||||
case long_iso_time_style:
|
||||
time_format = "%Y-%m-%d %H:%M";
|
||||
break;
|
||||
|
||||
case iso_time_style:
|
||||
time_format = "%Y-%m-%d";
|
||||
break;
|
||||
case iso_time_style:
|
||||
time_format = "%Y-%m-%d";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -920,18 +920,18 @@ main (int argc, char **argv)
|
||||
if (files_from)
|
||||
{
|
||||
/* When using --files0-from=F, you may not specify any files
|
||||
on the command-line. */
|
||||
on the command-line. */
|
||||
if (optind < argc)
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (argv[optind]));
|
||||
fprintf (stderr, "%s\n",
|
||||
_("file operands cannot be combined with --files0-from"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (argv[optind]));
|
||||
fprintf (stderr, "%s\n",
|
||||
_("file operands cannot be combined with --files0-from"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (! (STREQ (files_from, "-") || freopen (files_from, "r", stdin)))
|
||||
error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
|
||||
quote (files_from));
|
||||
error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
|
||||
quote (files_from));
|
||||
|
||||
ai = argv_iter_init_stream (stdin);
|
||||
}
|
||||
@@ -956,64 +956,64 @@ main (int argc, char **argv)
|
||||
enum argv_iter_err ai_err;
|
||||
char *file_name = argv_iter (ai, &ai_err);
|
||||
if (ai_err == AI_ERR_EOF)
|
||||
break;
|
||||
break;
|
||||
if (!file_name)
|
||||
{
|
||||
switch (ai_err)
|
||||
{
|
||||
case AI_ERR_READ:
|
||||
error (0, errno, _("%s: read error"), quote (files_from));
|
||||
skip_file = true;
|
||||
continue;
|
||||
{
|
||||
switch (ai_err)
|
||||
{
|
||||
case AI_ERR_READ:
|
||||
error (0, errno, _("%s: read error"), quote (files_from));
|
||||
skip_file = true;
|
||||
continue;
|
||||
|
||||
case AI_ERR_MEM:
|
||||
xalloc_die ();
|
||||
case AI_ERR_MEM:
|
||||
xalloc_die ();
|
||||
|
||||
default:
|
||||
assert (!"unexpected error code from argv_iter");
|
||||
}
|
||||
}
|
||||
default:
|
||||
assert (!"unexpected error code from argv_iter");
|
||||
}
|
||||
}
|
||||
if (files_from && STREQ (files_from, "-") && STREQ (file_name, "-"))
|
||||
{
|
||||
/* Give a better diagnostic in an unusual case:
|
||||
printf - | du --files0-from=- */
|
||||
error (0, 0, _("when reading file names from stdin, "
|
||||
"no file name of %s allowed"),
|
||||
quote (file_name));
|
||||
skip_file = true;
|
||||
}
|
||||
{
|
||||
/* Give a better diagnostic in an unusual case:
|
||||
printf - | du --files0-from=- */
|
||||
error (0, 0, _("when reading file names from stdin, "
|
||||
"no file name of %s allowed"),
|
||||
quote (file_name));
|
||||
skip_file = true;
|
||||
}
|
||||
|
||||
/* Report and skip any empty file names before invoking fts.
|
||||
This works around a glitch in fts, which fails immediately
|
||||
(without looking at the other file names) when given an empty
|
||||
file name. */
|
||||
This works around a glitch in fts, which fails immediately
|
||||
(without looking at the other file names) when given an empty
|
||||
file name. */
|
||||
if (!file_name[0])
|
||||
{
|
||||
/* Diagnose a zero-length file name. When it's one
|
||||
among many, knowing the record number may help.
|
||||
FIXME: currently print the record number only with
|
||||
--files0-from=FILE. Maybe do it for argv, too? */
|
||||
if (files_from == NULL)
|
||||
error (0, 0, "%s", _("invalid zero-length file name"));
|
||||
else
|
||||
{
|
||||
/* Using the standard `filename:line-number:' prefix here is
|
||||
not totally appropriate, since NUL is the separator, not NL,
|
||||
but it might be better than nothing. */
|
||||
unsigned long int file_number = argv_iter_n_args (ai);
|
||||
error (0, 0, "%s:%lu: %s", quotearg_colon (files_from),
|
||||
file_number, _("invalid zero-length file name"));
|
||||
}
|
||||
skip_file = true;
|
||||
}
|
||||
{
|
||||
/* Diagnose a zero-length file name. When it's one
|
||||
among many, knowing the record number may help.
|
||||
FIXME: currently print the record number only with
|
||||
--files0-from=FILE. Maybe do it for argv, too? */
|
||||
if (files_from == NULL)
|
||||
error (0, 0, "%s", _("invalid zero-length file name"));
|
||||
else
|
||||
{
|
||||
/* Using the standard `filename:line-number:' prefix here is
|
||||
not totally appropriate, since NUL is the separator, not NL,
|
||||
but it might be better than nothing. */
|
||||
unsigned long int file_number = argv_iter_n_args (ai);
|
||||
error (0, 0, "%s:%lu: %s", quotearg_colon (files_from),
|
||||
file_number, _("invalid zero-length file name"));
|
||||
}
|
||||
skip_file = true;
|
||||
}
|
||||
|
||||
if (skip_file)
|
||||
ok = false;
|
||||
ok = false;
|
||||
else
|
||||
{
|
||||
temp_argv[0] = file_name;
|
||||
ok &= du_files (temp_argv, bit_flags);
|
||||
}
|
||||
{
|
||||
temp_argv[0] = file_name;
|
||||
ok &= du_files (temp_argv, bit_flags);
|
||||
}
|
||||
}
|
||||
|
||||
argv_iter_free (ai);
|
||||
|
||||
+107
-107
@@ -37,7 +37,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -50,13 +50,13 @@ Echo the STRING(s) to standard output.\n\
|
||||
-n do not output the trailing newline\n\
|
||||
"), stdout);
|
||||
fputs (_(DEFAULT_ECHO_TO_XPG
|
||||
? N_("\
|
||||
? N_("\
|
||||
-e enable interpretation of backslash escapes (default)\n\
|
||||
-E disable interpretation of backslash escapes\n")
|
||||
: N_("\
|
||||
: N_("\
|
||||
-e enable interpretation of backslash escapes\n\
|
||||
-E disable interpretation of backslash escapes (default)\n")),
|
||||
stdout);
|
||||
stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
fputs (_("\
|
||||
@@ -128,14 +128,14 @@ main (int argc, char **argv)
|
||||
if (allow_options && argc == 2)
|
||||
{
|
||||
if (STREQ (argv[1], "--help"))
|
||||
usage (EXIT_SUCCESS);
|
||||
usage (EXIT_SUCCESS);
|
||||
|
||||
if (STREQ (argv[1], "--version"))
|
||||
{
|
||||
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
|
||||
(char *) NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
{
|
||||
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
|
||||
(char *) NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
--argc;
|
||||
@@ -144,45 +144,45 @@ main (int argc, char **argv)
|
||||
if (allow_options)
|
||||
while (argc > 0 && *argv[0] == '-')
|
||||
{
|
||||
char const *temp = argv[0] + 1;
|
||||
size_t i;
|
||||
char const *temp = argv[0] + 1;
|
||||
size_t i;
|
||||
|
||||
/* If it appears that we are handling options, then make sure that
|
||||
all of the options specified are actually valid. Otherwise, the
|
||||
string should just be echoed. */
|
||||
/* If it appears that we are handling options, then make sure that
|
||||
all of the options specified are actually valid. Otherwise, the
|
||||
string should just be echoed. */
|
||||
|
||||
for (i = 0; temp[i]; i++)
|
||||
switch (temp[i])
|
||||
{
|
||||
case 'e': case 'E': case 'n':
|
||||
break;
|
||||
default:
|
||||
goto just_echo;
|
||||
}
|
||||
for (i = 0; temp[i]; i++)
|
||||
switch (temp[i])
|
||||
{
|
||||
case 'e': case 'E': case 'n':
|
||||
break;
|
||||
default:
|
||||
goto just_echo;
|
||||
}
|
||||
|
||||
if (i == 0)
|
||||
goto just_echo;
|
||||
if (i == 0)
|
||||
goto just_echo;
|
||||
|
||||
/* All of the options in TEMP are valid options to ECHO.
|
||||
Handle them. */
|
||||
while (*temp)
|
||||
switch (*temp++)
|
||||
{
|
||||
case 'e':
|
||||
do_v9 = true;
|
||||
break;
|
||||
/* All of the options in TEMP are valid options to ECHO.
|
||||
Handle them. */
|
||||
while (*temp)
|
||||
switch (*temp++)
|
||||
{
|
||||
case 'e':
|
||||
do_v9 = true;
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
do_v9 = false;
|
||||
break;
|
||||
case 'E':
|
||||
do_v9 = false;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
display_return = false;
|
||||
break;
|
||||
}
|
||||
case 'n':
|
||||
display_return = false;
|
||||
break;
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
just_echo:
|
||||
@@ -190,77 +190,77 @@ just_echo:
|
||||
if (do_v9)
|
||||
{
|
||||
while (argc > 0)
|
||||
{
|
||||
char const *s = argv[0];
|
||||
unsigned char c;
|
||||
{
|
||||
char const *s = argv[0];
|
||||
unsigned char c;
|
||||
|
||||
while ((c = *s++))
|
||||
{
|
||||
if (c == '\\' && *s)
|
||||
{
|
||||
switch (c = *s++)
|
||||
{
|
||||
case 'a': c = '\a'; break;
|
||||
case 'b': c = '\b'; break;
|
||||
case 'c': exit (EXIT_SUCCESS);
|
||||
case 'f': c = '\f'; break;
|
||||
case 'n': c = '\n'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'v': c = '\v'; break;
|
||||
case 'x':
|
||||
{
|
||||
unsigned char ch = *s;
|
||||
if (! isxdigit (ch))
|
||||
goto not_an_escape;
|
||||
s++;
|
||||
c = hextobin (ch);
|
||||
ch = *s;
|
||||
if (isxdigit (ch))
|
||||
{
|
||||
s++;
|
||||
c = c * 16 + hextobin (ch);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
c = 0;
|
||||
if (! ('0' <= *s && *s <= '7'))
|
||||
break;
|
||||
c = *s++;
|
||||
/* Fall through. */
|
||||
case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
c -= '0';
|
||||
if ('0' <= *s && *s <= '7')
|
||||
c = c * 8 + (*s++ - '0');
|
||||
if ('0' <= *s && *s <= '7')
|
||||
c = c * 8 + (*s++ - '0');
|
||||
break;
|
||||
case '\\': break;
|
||||
while ((c = *s++))
|
||||
{
|
||||
if (c == '\\' && *s)
|
||||
{
|
||||
switch (c = *s++)
|
||||
{
|
||||
case 'a': c = '\a'; break;
|
||||
case 'b': c = '\b'; break;
|
||||
case 'c': exit (EXIT_SUCCESS);
|
||||
case 'f': c = '\f'; break;
|
||||
case 'n': c = '\n'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'v': c = '\v'; break;
|
||||
case 'x':
|
||||
{
|
||||
unsigned char ch = *s;
|
||||
if (! isxdigit (ch))
|
||||
goto not_an_escape;
|
||||
s++;
|
||||
c = hextobin (ch);
|
||||
ch = *s;
|
||||
if (isxdigit (ch))
|
||||
{
|
||||
s++;
|
||||
c = c * 16 + hextobin (ch);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
c = 0;
|
||||
if (! ('0' <= *s && *s <= '7'))
|
||||
break;
|
||||
c = *s++;
|
||||
/* Fall through. */
|
||||
case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
c -= '0';
|
||||
if ('0' <= *s && *s <= '7')
|
||||
c = c * 8 + (*s++ - '0');
|
||||
if ('0' <= *s && *s <= '7')
|
||||
c = c * 8 + (*s++ - '0');
|
||||
break;
|
||||
case '\\': break;
|
||||
|
||||
not_an_escape:
|
||||
default: putchar ('\\'); break;
|
||||
}
|
||||
}
|
||||
putchar (c);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc > 0)
|
||||
putchar (' ');
|
||||
}
|
||||
not_an_escape:
|
||||
default: putchar ('\\'); break;
|
||||
}
|
||||
}
|
||||
putchar (c);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc > 0)
|
||||
putchar (' ');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (argc > 0)
|
||||
{
|
||||
fputs (argv[0], stdout);
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc > 0)
|
||||
putchar (' ');
|
||||
}
|
||||
{
|
||||
fputs (argv[0], stdout);
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc > 0)
|
||||
putchar (' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (display_return)
|
||||
|
||||
@@ -20,24 +20,24 @@
|
||||
-
|
||||
-i
|
||||
--ignore-environment
|
||||
Construct a new environment from scratch; normally the
|
||||
environment is inherited from the parent process, except as
|
||||
modified by other options.
|
||||
Construct a new environment from scratch; normally the
|
||||
environment is inherited from the parent process, except as
|
||||
modified by other options.
|
||||
|
||||
-u variable
|
||||
--unset=variable
|
||||
Unset variable VARIABLE (remove it from the environment).
|
||||
If VARIABLE was not set, does nothing.
|
||||
Unset variable VARIABLE (remove it from the environment).
|
||||
If VARIABLE was not set, does nothing.
|
||||
|
||||
variable=value (an arg containing a "=" character)
|
||||
Set the environment variable VARIABLE to value VALUE. VALUE
|
||||
may be of zero length ("variable="). Setting a variable to a
|
||||
zero-length value is different from unsetting it.
|
||||
Set the environment variable VARIABLE to value VALUE. VALUE
|
||||
may be of zero length ("variable="). Setting a variable to a
|
||||
zero-length value is different from unsetting it.
|
||||
|
||||
--
|
||||
Indicate that the following argument is the program
|
||||
to invoke. This is necessary when the program's name
|
||||
begins with "-" or contains a "=".
|
||||
Indicate that the following argument is the program
|
||||
to invoke. This is necessary when the program's name
|
||||
begins with "-" or contains a "=".
|
||||
|
||||
The first remaining argument specifies a program to invoke;
|
||||
it is searched for according to the specification of the PATH
|
||||
@@ -51,29 +51,29 @@
|
||||
Examples:
|
||||
|
||||
If the environment passed to "env" is
|
||||
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
|
||||
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
|
||||
|
||||
env - foo
|
||||
runs "foo" in a null environment.
|
||||
runs "foo" in a null environment.
|
||||
|
||||
env foo
|
||||
runs "foo" in the environment
|
||||
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
|
||||
runs "foo" in the environment
|
||||
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
|
||||
|
||||
env DISPLAY=gnu:0 nemacs
|
||||
runs "nemacs" in the environment
|
||||
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks DISPLAY=gnu:0 }
|
||||
runs "nemacs" in the environment
|
||||
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks DISPLAY=gnu:0 }
|
||||
|
||||
env - LOGNAME=foo /hacks/hack bar baz
|
||||
runs the "hack" program on arguments "bar" and "baz" in an
|
||||
environment in which the only variable is "LOGNAME". Note that
|
||||
the "-" option clears out the PATH variable, so one should be
|
||||
careful to specify in which directory to find the program to
|
||||
call.
|
||||
runs the "hack" program on arguments "bar" and "baz" in an
|
||||
environment in which the only variable is "LOGNAME". Note that
|
||||
the "-" option clears out the PATH variable, so one should be
|
||||
careful to specify in which directory to find the program to
|
||||
call.
|
||||
|
||||
env -u EDITOR LOGNAME=foo PATH=/energy -- e=mc2 bar baz
|
||||
runs the program "/energy/e=mc2" with environment
|
||||
{ LOGNAME=foo PATH=/energy }
|
||||
runs the program "/energy/e=mc2" with environment
|
||||
{ LOGNAME=foo PATH=/energy }
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
@@ -107,12 +107,12 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Set each NAME to VALUE in the environment and run COMMAND.\n\
|
||||
\n\
|
||||
@@ -148,17 +148,17 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'i':
|
||||
ignore_environment = true;
|
||||
break;
|
||||
case 'u':
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'i':
|
||||
ignore_environment = true;
|
||||
break;
|
||||
case 'u':
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc && STREQ (argv[optind], "-"))
|
||||
@@ -186,7 +186,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
char *const *e = environ;
|
||||
while (*e)
|
||||
puts (*e++);
|
||||
puts (*e++);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
+134
-134
@@ -23,10 +23,10 @@
|
||||
--tabs=tab1[,tab2[,...]]
|
||||
-t tab1[,tab2[,...]]
|
||||
-tab1[,tab2[,...]] If only one tab stop is given, set the tabs tab1
|
||||
columns apart instead of the default 8. Otherwise,
|
||||
set the tabs at columns tab1, tab2, etc. (numbered from
|
||||
0); replace any tabs beyond the tab stops given with
|
||||
single spaces.
|
||||
columns apart instead of the default 8. Otherwise,
|
||||
set the tabs at columns tab1, tab2, etc. (numbered from
|
||||
0); replace any tabs beyond the tab stops given with
|
||||
single spaces.
|
||||
--initial
|
||||
-i Only convert initial tabs on each line to spaces.
|
||||
|
||||
@@ -97,13 +97,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Convert tabs in each FILE to spaces, writing to standard output.\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n\
|
||||
@@ -150,38 +150,38 @@ parse_tab_stops (char const *stops)
|
||||
for (; *stops; stops++)
|
||||
{
|
||||
if (*stops == ',' || isblank (to_uchar (*stops)))
|
||||
{
|
||||
if (have_tabval)
|
||||
add_tab_stop (tabval);
|
||||
have_tabval = false;
|
||||
}
|
||||
{
|
||||
if (have_tabval)
|
||||
add_tab_stop (tabval);
|
||||
have_tabval = false;
|
||||
}
|
||||
else if (ISDIGIT (*stops))
|
||||
{
|
||||
if (!have_tabval)
|
||||
{
|
||||
tabval = 0;
|
||||
have_tabval = true;
|
||||
num_start = stops;
|
||||
}
|
||||
{
|
||||
if (!have_tabval)
|
||||
{
|
||||
tabval = 0;
|
||||
have_tabval = true;
|
||||
num_start = stops;
|
||||
}
|
||||
|
||||
/* Detect overflow. */
|
||||
if (!DECIMAL_DIGIT_ACCUMULATE (tabval, *stops - '0', uintmax_t))
|
||||
{
|
||||
size_t len = strspn (num_start, "0123456789");
|
||||
char *bad_num = xstrndup (num_start, len);
|
||||
error (0, 0, _("tab stop is too large %s"), quote (bad_num));
|
||||
free (bad_num);
|
||||
ok = false;
|
||||
stops = num_start + len - 1;
|
||||
}
|
||||
}
|
||||
/* Detect overflow. */
|
||||
if (!DECIMAL_DIGIT_ACCUMULATE (tabval, *stops - '0', uintmax_t))
|
||||
{
|
||||
size_t len = strspn (num_start, "0123456789");
|
||||
char *bad_num = xstrndup (num_start, len);
|
||||
error (0, 0, _("tab stop is too large %s"), quote (bad_num));
|
||||
free (bad_num);
|
||||
ok = false;
|
||||
stops = num_start + len - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, 0, _("tab size contains invalid character(s): %s"),
|
||||
quote (stops));
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("tab size contains invalid character(s): %s"),
|
||||
quote (stops));
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
@@ -203,9 +203,9 @@ validate_tab_stops (uintmax_t const *tabs, size_t entries)
|
||||
for (i = 0; i < entries; i++)
|
||||
{
|
||||
if (tabs[i] == 0)
|
||||
error (EXIT_FAILURE, 0, _("tab size cannot be 0"));
|
||||
error (EXIT_FAILURE, 0, _("tab size cannot be 0"));
|
||||
if (tabs[i] <= prev_tab)
|
||||
error (EXIT_FAILURE, 0, _("tab sizes must be ascending"));
|
||||
error (EXIT_FAILURE, 0, _("tab sizes must be ascending"));
|
||||
prev_tab = tabs[i];
|
||||
}
|
||||
}
|
||||
@@ -224,33 +224,33 @@ next_file (FILE *fp)
|
||||
if (fp)
|
||||
{
|
||||
if (ferror (fp))
|
||||
{
|
||||
error (0, errno, "%s", prev_file);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", prev_file);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
if (STREQ (prev_file, "-"))
|
||||
clearerr (fp); /* Also clear EOF. */
|
||||
clearerr (fp); /* Also clear EOF. */
|
||||
else if (fclose (fp) != 0)
|
||||
{
|
||||
error (0, errno, "%s", prev_file);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", prev_file);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
while ((file = *file_list++) != NULL)
|
||||
{
|
||||
if (STREQ (file, "-"))
|
||||
{
|
||||
have_read_stdin = true;
|
||||
prev_file = file;
|
||||
return stdin;
|
||||
}
|
||||
{
|
||||
have_read_stdin = true;
|
||||
prev_file = file;
|
||||
return stdin;
|
||||
}
|
||||
fp = fopen (file, "r");
|
||||
if (fp)
|
||||
{
|
||||
prev_file = file;
|
||||
return fp;
|
||||
}
|
||||
{
|
||||
prev_file = file;
|
||||
return fp;
|
||||
}
|
||||
error (0, errno, "%s", file);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
@@ -279,7 +279,7 @@ expand (void)
|
||||
|
||||
|
||||
/* The following variables have valid values only when CONVERT
|
||||
is true: */
|
||||
is true: */
|
||||
|
||||
/* Column of next input character. */
|
||||
uintmax_t column = 0;
|
||||
@@ -291,68 +291,68 @@ expand (void)
|
||||
/* Convert a line of text. */
|
||||
|
||||
do
|
||||
{
|
||||
while ((c = getc (fp)) < 0 && (fp = next_file (fp)))
|
||||
continue;
|
||||
{
|
||||
while ((c = getc (fp)) < 0 && (fp = next_file (fp)))
|
||||
continue;
|
||||
|
||||
if (convert)
|
||||
{
|
||||
if (c == '\t')
|
||||
{
|
||||
/* Column the next input tab stop is on. */
|
||||
uintmax_t next_tab_column;
|
||||
if (convert)
|
||||
{
|
||||
if (c == '\t')
|
||||
{
|
||||
/* Column the next input tab stop is on. */
|
||||
uintmax_t next_tab_column;
|
||||
|
||||
if (tab_size)
|
||||
next_tab_column = column + (tab_size - column % tab_size);
|
||||
else
|
||||
for (;;)
|
||||
if (tab_index == first_free_tab)
|
||||
{
|
||||
next_tab_column = column + 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
uintmax_t tab = tab_list[tab_index++];
|
||||
if (column < tab)
|
||||
{
|
||||
next_tab_column = tab;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tab_size)
|
||||
next_tab_column = column + (tab_size - column % tab_size);
|
||||
else
|
||||
for (;;)
|
||||
if (tab_index == first_free_tab)
|
||||
{
|
||||
next_tab_column = column + 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
uintmax_t tab = tab_list[tab_index++];
|
||||
if (column < tab)
|
||||
{
|
||||
next_tab_column = tab;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (next_tab_column < column)
|
||||
error (EXIT_FAILURE, 0, _("input line is too long"));
|
||||
if (next_tab_column < column)
|
||||
error (EXIT_FAILURE, 0, _("input line is too long"));
|
||||
|
||||
while (++column < next_tab_column)
|
||||
if (putchar (' ') < 0)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
while (++column < next_tab_column)
|
||||
if (putchar (' ') < 0)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
|
||||
c = ' ';
|
||||
}
|
||||
else if (c == '\b')
|
||||
{
|
||||
/* Go back one column, and force recalculation of the
|
||||
next tab stop. */
|
||||
column -= !!column;
|
||||
tab_index -= !!tab_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
column++;
|
||||
if (!column)
|
||||
error (EXIT_FAILURE, 0, _("input line is too long"));
|
||||
}
|
||||
c = ' ';
|
||||
}
|
||||
else if (c == '\b')
|
||||
{
|
||||
/* Go back one column, and force recalculation of the
|
||||
next tab stop. */
|
||||
column -= !!column;
|
||||
tab_index -= !!tab_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
column++;
|
||||
if (!column)
|
||||
error (EXIT_FAILURE, 0, _("input line is too long"));
|
||||
}
|
||||
|
||||
convert &= convert_entire_line | !! isblank (c);
|
||||
}
|
||||
convert &= convert_entire_line | !! isblank (c);
|
||||
}
|
||||
|
||||
if (c < 0)
|
||||
return;
|
||||
if (c < 0)
|
||||
return;
|
||||
|
||||
if (putchar (c) < 0)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
}
|
||||
if (putchar (c) < 0)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
}
|
||||
while (c != '\n');
|
||||
}
|
||||
}
|
||||
@@ -379,35 +379,35 @@ main (int argc, char **argv)
|
||||
while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'i':
|
||||
convert_entire_line = false;
|
||||
break;
|
||||
{
|
||||
case 'i':
|
||||
convert_entire_line = false;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
parse_tab_stops (optarg);
|
||||
break;
|
||||
case 't':
|
||||
parse_tab_stops (optarg);
|
||||
break;
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
if (optarg)
|
||||
parse_tab_stops (optarg - 1);
|
||||
else
|
||||
{
|
||||
char tab_stop[2];
|
||||
tab_stop[0] = c;
|
||||
tab_stop[1] = '\0';
|
||||
parse_tab_stops (tab_stop);
|
||||
}
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
if (optarg)
|
||||
parse_tab_stops (optarg - 1);
|
||||
else
|
||||
{
|
||||
char tab_stop[2];
|
||||
tab_stop[0] = c;
|
||||
tab_stop[1] = '\0';
|
||||
parse_tab_stops (tab_stop);
|
||||
}
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
validate_tab_stops (tab_list, first_free_tab);
|
||||
|
||||
+164
-164
@@ -89,7 +89,7 @@ mpz_mul (mpz_t r, mpz_t a0, mpz_t b0)
|
||||
intmax_t b = b0[0];
|
||||
intmax_t val = a * b;
|
||||
if (! (a == 0 || b == 0
|
||||
|| ((val < 0) == ((a < 0) ^ (b < 0)) && val / a == b)))
|
||||
|| ((val < 0) == ((a < 0) ^ (b < 0)) && val / a == b)))
|
||||
integer_overflow ('*');
|
||||
r[0] = val;
|
||||
}
|
||||
@@ -196,14 +196,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s EXPRESSION\n\
|
||||
or: %s OPTION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
putchar ('\n');
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
@@ -231,7 +231,7 @@ separates increasing precedence groups. EXPRESSION may be:\n\
|
||||
ARG1 - ARG2 arithmetic difference of ARG1 and ARG2\n\
|
||||
"), stdout);
|
||||
/* Tell xgettext that the "% A" below is not a printf-style
|
||||
format string: xgettext:no-c-format */
|
||||
format string: xgettext:no-c-format */
|
||||
fputs (_("\
|
||||
\n\
|
||||
ARG1 * ARG2 arithmetic product of ARG1 and ARG2\n\
|
||||
@@ -309,7 +309,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
/* The above handles --help and --version.
|
||||
Since there is no other invocation of getopt, handle `--' here. */
|
||||
if (argc > 1 && STREQ (argv[1], "--"))
|
||||
@@ -398,20 +398,20 @@ null (VALUE *v)
|
||||
return mpz_sgn (v->u.i) == 0;
|
||||
case string:
|
||||
{
|
||||
char const *cp = v->u.s;
|
||||
if (*cp == '\0')
|
||||
return true;
|
||||
char const *cp = v->u.s;
|
||||
if (*cp == '\0')
|
||||
return true;
|
||||
|
||||
cp += (*cp == '-');
|
||||
cp += (*cp == '-');
|
||||
|
||||
do
|
||||
{
|
||||
if (*cp != '0')
|
||||
return false;
|
||||
}
|
||||
while (*++cp);
|
||||
do
|
||||
{
|
||||
if (*cp != '0')
|
||||
return false;
|
||||
}
|
||||
while (*++cp);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
abort ();
|
||||
@@ -442,10 +442,10 @@ tostring (VALUE *v)
|
||||
{
|
||||
case integer:
|
||||
{
|
||||
char *s = mpz_get_str (NULL, 10, v->u.i);
|
||||
mpz_clear (v->u.i);
|
||||
v->u.s = s;
|
||||
v->type = string;
|
||||
char *s = mpz_get_str (NULL, 10, v->u.i);
|
||||
mpz_clear (v->u.i);
|
||||
v->u.s = s;
|
||||
v->type = string;
|
||||
}
|
||||
break;
|
||||
case string:
|
||||
@@ -466,15 +466,15 @@ toarith (VALUE *v)
|
||||
return true;
|
||||
case string:
|
||||
{
|
||||
char *s = v->u.s;
|
||||
char *s = v->u.s;
|
||||
|
||||
if (! looks_like_integer (s))
|
||||
return false;
|
||||
if (mpz_init_set_str (v->u.i, s, 10) != 0 && !HAVE_GMP)
|
||||
error (EXPR_FAILURE, ERANGE, "%s", s);
|
||||
free (s);
|
||||
v->type = integer;
|
||||
return true;
|
||||
if (! looks_like_integer (s))
|
||||
return false;
|
||||
if (mpz_init_set_str (v->u.i, s, 10) != 0 && !HAVE_GMP)
|
||||
error (EXPR_FAILURE, ERANGE, "%s", s);
|
||||
free (s);
|
||||
v->type = integer;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
abort ();
|
||||
@@ -493,7 +493,7 @@ getsize (mpz_t i)
|
||||
{
|
||||
unsigned long int ul = mpz_get_ui (i);
|
||||
if (ul < SIZE_MAX)
|
||||
return ul;
|
||||
return ul;
|
||||
}
|
||||
return SIZE_MAX - 1;
|
||||
}
|
||||
@@ -575,25 +575,25 @@ docolon (VALUE *sv, VALUE *pv)
|
||||
{
|
||||
/* Were \(...\) used? */
|
||||
if (re_buffer.re_nsub > 0)
|
||||
{
|
||||
sv->u.s[re_regs.end[1]] = '\0';
|
||||
v = str_value (sv->u.s + re_regs.start[1]);
|
||||
}
|
||||
{
|
||||
sv->u.s[re_regs.end[1]] = '\0';
|
||||
v = str_value (sv->u.s + re_regs.start[1]);
|
||||
}
|
||||
else
|
||||
v = int_value (matchlen);
|
||||
v = int_value (matchlen);
|
||||
}
|
||||
else if (matchlen == -1)
|
||||
{
|
||||
/* Match failed -- return the right kind of null. */
|
||||
if (re_buffer.re_nsub > 0)
|
||||
v = str_value ("");
|
||||
v = str_value ("");
|
||||
else
|
||||
v = int_value (0);
|
||||
v = int_value (0);
|
||||
}
|
||||
else
|
||||
error (EXPR_FAILURE,
|
||||
(matchlen == -2 ? errno : EOVERFLOW),
|
||||
_("error in regular expression matcher"));
|
||||
(matchlen == -2 ? errno : EOVERFLOW),
|
||||
_("error in regular expression matcher"));
|
||||
|
||||
if (0 < re_regs.num_regs)
|
||||
{
|
||||
@@ -622,7 +622,7 @@ eval7 (bool evaluate)
|
||||
{
|
||||
v = eval (evaluate);
|
||||
if (!nextarg (")"))
|
||||
syntax_error ();
|
||||
syntax_error ();
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -649,7 +649,7 @@ eval6 (bool evaluate)
|
||||
if (nextarg ("+"))
|
||||
{
|
||||
if (nomoreargs ())
|
||||
syntax_error ();
|
||||
syntax_error ();
|
||||
return str_value (*args++);
|
||||
}
|
||||
else if (nextarg ("length"))
|
||||
@@ -665,12 +665,12 @@ eval6 (bool evaluate)
|
||||
l = eval6 (evaluate);
|
||||
r = eval6 (evaluate);
|
||||
if (evaluate)
|
||||
{
|
||||
v = docolon (l, r);
|
||||
freev (l);
|
||||
}
|
||||
{
|
||||
v = docolon (l, r);
|
||||
freev (l);
|
||||
}
|
||||
else
|
||||
v = l;
|
||||
v = l;
|
||||
freev (r);
|
||||
return v;
|
||||
}
|
||||
@@ -698,25 +698,25 @@ eval6 (bool evaluate)
|
||||
llen = strlen (l->u.s);
|
||||
|
||||
if (!toarith (i1) || !toarith (i2))
|
||||
v = str_value ("");
|
||||
v = str_value ("");
|
||||
else
|
||||
{
|
||||
size_t pos = getsize (i1->u.i);
|
||||
size_t len = getsize (i2->u.i);
|
||||
{
|
||||
size_t pos = getsize (i1->u.i);
|
||||
size_t len = getsize (i2->u.i);
|
||||
|
||||
if (llen < pos || pos == 0 || len == 0 || len == SIZE_MAX)
|
||||
v = str_value ("");
|
||||
else
|
||||
{
|
||||
size_t vlen = MIN (len, llen - pos + 1);
|
||||
char *vlim;
|
||||
v = xmalloc (sizeof *v);
|
||||
v->type = string;
|
||||
v->u.s = xmalloc (vlen + 1);
|
||||
vlim = mempcpy (v->u.s, l->u.s + pos - 1, vlen);
|
||||
*vlim = '\0';
|
||||
}
|
||||
}
|
||||
if (llen < pos || pos == 0 || len == 0 || len == SIZE_MAX)
|
||||
v = str_value ("");
|
||||
else
|
||||
{
|
||||
size_t vlen = MIN (len, llen - pos + 1);
|
||||
char *vlim;
|
||||
v = xmalloc (sizeof *v);
|
||||
v->type = string;
|
||||
v->u.s = xmalloc (vlen + 1);
|
||||
vlim = mempcpy (v->u.s, l->u.s + pos - 1, vlen);
|
||||
*vlim = '\0';
|
||||
}
|
||||
}
|
||||
freev (l);
|
||||
freev (i1);
|
||||
freev (i2);
|
||||
@@ -743,18 +743,18 @@ eval5 (bool evaluate)
|
||||
while (1)
|
||||
{
|
||||
if (nextarg (":"))
|
||||
{
|
||||
r = eval6 (evaluate);
|
||||
if (evaluate)
|
||||
{
|
||||
v = docolon (l, r);
|
||||
freev (l);
|
||||
l = v;
|
||||
}
|
||||
freev (r);
|
||||
}
|
||||
{
|
||||
r = eval6 (evaluate);
|
||||
if (evaluate)
|
||||
{
|
||||
v = docolon (l, r);
|
||||
freev (l);
|
||||
l = v;
|
||||
}
|
||||
freev (r);
|
||||
}
|
||||
else
|
||||
return l;
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,25 +774,25 @@ eval4 (bool evaluate)
|
||||
while (1)
|
||||
{
|
||||
if (nextarg ("*"))
|
||||
fxn = multiply;
|
||||
fxn = multiply;
|
||||
else if (nextarg ("/"))
|
||||
fxn = divide;
|
||||
fxn = divide;
|
||||
else if (nextarg ("%"))
|
||||
fxn = mod;
|
||||
fxn = mod;
|
||||
else
|
||||
return l;
|
||||
return l;
|
||||
r = eval5 (evaluate);
|
||||
if (evaluate)
|
||||
{
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
if (fxn != multiply && mpz_sgn (r->u.i) == 0)
|
||||
error (EXPR_INVALID, 0, _("division by zero"));
|
||||
((fxn == multiply ? mpz_mul
|
||||
: fxn == divide ? mpz_tdiv_q
|
||||
: mpz_tdiv_r)
|
||||
(l->u.i, l->u.i, r->u.i));
|
||||
}
|
||||
{
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
if (fxn != multiply && mpz_sgn (r->u.i) == 0)
|
||||
error (EXPR_INVALID, 0, _("division by zero"));
|
||||
((fxn == multiply ? mpz_mul
|
||||
: fxn == divide ? mpz_tdiv_q
|
||||
: mpz_tdiv_r)
|
||||
(l->u.i, l->u.i, r->u.i));
|
||||
}
|
||||
freev (r);
|
||||
}
|
||||
}
|
||||
@@ -813,18 +813,18 @@ eval3 (bool evaluate)
|
||||
while (1)
|
||||
{
|
||||
if (nextarg ("+"))
|
||||
fxn = plus;
|
||||
fxn = plus;
|
||||
else if (nextarg ("-"))
|
||||
fxn = minus;
|
||||
fxn = minus;
|
||||
else
|
||||
return l;
|
||||
return l;
|
||||
r = eval4 (evaluate);
|
||||
if (evaluate)
|
||||
{
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
(fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);
|
||||
}
|
||||
{
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
(fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);
|
||||
}
|
||||
freev (r);
|
||||
}
|
||||
}
|
||||
@@ -844,62 +844,62 @@ eval2 (bool evaluate)
|
||||
{
|
||||
VALUE *r;
|
||||
enum
|
||||
{
|
||||
less_than, less_equal, equal, not_equal, greater_equal, greater_than
|
||||
} fxn;
|
||||
{
|
||||
less_than, less_equal, equal, not_equal, greater_equal, greater_than
|
||||
} fxn;
|
||||
bool val = false;
|
||||
|
||||
if (nextarg ("<"))
|
||||
fxn = less_than;
|
||||
fxn = less_than;
|
||||
else if (nextarg ("<="))
|
||||
fxn = less_equal;
|
||||
fxn = less_equal;
|
||||
else if (nextarg ("=") || nextarg ("=="))
|
||||
fxn = equal;
|
||||
fxn = equal;
|
||||
else if (nextarg ("!="))
|
||||
fxn = not_equal;
|
||||
fxn = not_equal;
|
||||
else if (nextarg (">="))
|
||||
fxn = greater_equal;
|
||||
fxn = greater_equal;
|
||||
else if (nextarg (">"))
|
||||
fxn = greater_than;
|
||||
fxn = greater_than;
|
||||
else
|
||||
return l;
|
||||
return l;
|
||||
r = eval3 (evaluate);
|
||||
|
||||
if (evaluate)
|
||||
{
|
||||
int cmp;
|
||||
tostring (l);
|
||||
tostring (r);
|
||||
{
|
||||
int cmp;
|
||||
tostring (l);
|
||||
tostring (r);
|
||||
|
||||
if (looks_like_integer (l->u.s) && looks_like_integer (r->u.s))
|
||||
cmp = strintcmp (l->u.s, r->u.s);
|
||||
else
|
||||
{
|
||||
errno = 0;
|
||||
cmp = strcoll (l->u.s, r->u.s);
|
||||
if (looks_like_integer (l->u.s) && looks_like_integer (r->u.s))
|
||||
cmp = strintcmp (l->u.s, r->u.s);
|
||||
else
|
||||
{
|
||||
errno = 0;
|
||||
cmp = strcoll (l->u.s, r->u.s);
|
||||
|
||||
if (errno)
|
||||
{
|
||||
error (0, errno, _("string comparison failed"));
|
||||
error (0, 0, _("set LC_ALL='C' to work around the problem"));
|
||||
error (EXPR_INVALID, 0,
|
||||
_("the strings compared were %s and %s"),
|
||||
quotearg_n_style (0, locale_quoting_style, l->u.s),
|
||||
quotearg_n_style (1, locale_quoting_style, r->u.s));
|
||||
}
|
||||
}
|
||||
if (errno)
|
||||
{
|
||||
error (0, errno, _("string comparison failed"));
|
||||
error (0, 0, _("set LC_ALL='C' to work around the problem"));
|
||||
error (EXPR_INVALID, 0,
|
||||
_("the strings compared were %s and %s"),
|
||||
quotearg_n_style (0, locale_quoting_style, l->u.s),
|
||||
quotearg_n_style (1, locale_quoting_style, r->u.s));
|
||||
}
|
||||
}
|
||||
|
||||
switch (fxn)
|
||||
{
|
||||
case less_than: val = (cmp < 0); break;
|
||||
case less_equal: val = (cmp <= 0); break;
|
||||
case equal: val = (cmp == 0); break;
|
||||
case not_equal: val = (cmp != 0); break;
|
||||
case greater_equal: val = (cmp >= 0); break;
|
||||
case greater_than: val = (cmp > 0); break;
|
||||
default: abort ();
|
||||
}
|
||||
}
|
||||
switch (fxn)
|
||||
{
|
||||
case less_than: val = (cmp < 0); break;
|
||||
case less_equal: val = (cmp <= 0); break;
|
||||
case equal: val = (cmp == 0); break;
|
||||
case not_equal: val = (cmp != 0); break;
|
||||
case greater_equal: val = (cmp >= 0); break;
|
||||
case greater_than: val = (cmp > 0); break;
|
||||
default: abort ();
|
||||
}
|
||||
}
|
||||
|
||||
freev (l);
|
||||
freev (r);
|
||||
@@ -922,19 +922,19 @@ eval1 (bool evaluate)
|
||||
while (1)
|
||||
{
|
||||
if (nextarg ("&"))
|
||||
{
|
||||
r = eval2 (evaluate & ~ null (l));
|
||||
if (null (l) || null (r))
|
||||
{
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (0);
|
||||
}
|
||||
else
|
||||
freev (r);
|
||||
}
|
||||
{
|
||||
r = eval2 (evaluate & ~ null (l));
|
||||
if (null (l) || null (r))
|
||||
{
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (0);
|
||||
}
|
||||
else
|
||||
freev (r);
|
||||
}
|
||||
else
|
||||
return l;
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -953,22 +953,22 @@ eval (bool evaluate)
|
||||
while (1)
|
||||
{
|
||||
if (nextarg ("|"))
|
||||
{
|
||||
r = eval1 (evaluate & null (l));
|
||||
if (null (l))
|
||||
{
|
||||
freev (l);
|
||||
l = r;
|
||||
if (null (l))
|
||||
{
|
||||
freev (l);
|
||||
l = int_value (0);
|
||||
}
|
||||
}
|
||||
else
|
||||
freev (r);
|
||||
}
|
||||
{
|
||||
r = eval1 (evaluate & null (l));
|
||||
if (null (l))
|
||||
{
|
||||
freev (l);
|
||||
l = r;
|
||||
if (null (l))
|
||||
{
|
||||
freev (l);
|
||||
l = int_value (0);
|
||||
}
|
||||
}
|
||||
else
|
||||
freev (r);
|
||||
}
|
||||
else
|
||||
return l;
|
||||
return l;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -114,10 +114,10 @@ EOF
|
||||
while (defined (my $line = <FH>))
|
||||
{
|
||||
$line =~ /^[ \t]+case S_MAGIC_/
|
||||
or next;
|
||||
or next;
|
||||
$line =~ m!^[ \t]+case (S_MAGIC_\w+): /\* (0x[0-9A-Fa-f]+) \*/$!
|
||||
or (warn "$ME:$file:$.: malformed case S_MAGIC_... line"),
|
||||
$fail = 1, next;
|
||||
or (warn "$ME:$file:$.: malformed case S_MAGIC_... line"),
|
||||
$fail = 1, next;
|
||||
my $name = $1;
|
||||
my $value = $2;
|
||||
print "# define $name $value\n";
|
||||
|
||||
+84
-84
@@ -110,7 +110,7 @@ factor_using_division (mpz_t t, unsigned int limit)
|
||||
{
|
||||
mpz_tdiv_qr_ui (q, r, t, 3);
|
||||
if (mpz_cmp_ui (r, 0) != 0)
|
||||
break;
|
||||
break;
|
||||
mpz_set (t, q);
|
||||
emit_ul_factor (3);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ factor_using_division (mpz_t t, unsigned int limit)
|
||||
{
|
||||
mpz_tdiv_qr_ui (q, r, t, 5);
|
||||
if (mpz_cmp_ui (r, 0) != 0)
|
||||
break;
|
||||
break;
|
||||
mpz_set (t, q);
|
||||
emit_ul_factor (5);
|
||||
}
|
||||
@@ -131,21 +131,21 @@ factor_using_division (mpz_t t, unsigned int limit)
|
||||
{
|
||||
mpz_tdiv_qr_ui (q, r, t, f);
|
||||
if (mpz_cmp_ui (r, 0) != 0)
|
||||
{
|
||||
f += addv[ai];
|
||||
if (mpz_cmp_ui (q, f) < 0)
|
||||
break;
|
||||
ai = (ai + 1) & 7;
|
||||
failures++;
|
||||
if (failures > limit)
|
||||
break;
|
||||
}
|
||||
{
|
||||
f += addv[ai];
|
||||
if (mpz_cmp_ui (q, f) < 0)
|
||||
break;
|
||||
ai = (ai + 1) & 7;
|
||||
failures++;
|
||||
if (failures > limit)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
mpz_swap (t, q);
|
||||
emit_ul_factor (f);
|
||||
failures = 0;
|
||||
}
|
||||
{
|
||||
mpz_swap (t, q);
|
||||
emit_ul_factor (f);
|
||||
failures = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mpz_clear (q);
|
||||
@@ -184,67 +184,67 @@ S2:
|
||||
mpz_sub (t1, x1, x); mpz_mul (t2, P, t1); mpz_mod (P, t2, n);
|
||||
c++;
|
||||
if (c == 20)
|
||||
{
|
||||
c = 0;
|
||||
mpz_gcd (g, P, n);
|
||||
if (mpz_cmp_ui (g, 1) != 0)
|
||||
goto S4;
|
||||
mpz_set (y, x);
|
||||
}
|
||||
{
|
||||
c = 0;
|
||||
mpz_gcd (g, P, n);
|
||||
if (mpz_cmp_ui (g, 1) != 0)
|
||||
goto S4;
|
||||
mpz_set (y, x);
|
||||
}
|
||||
|
||||
k--;
|
||||
if (k > 0)
|
||||
goto S2;
|
||||
goto S2;
|
||||
|
||||
mpz_gcd (g, P, n);
|
||||
if (mpz_cmp_ui (g, 1) != 0)
|
||||
goto S4;
|
||||
goto S4;
|
||||
|
||||
mpz_set (x1, x);
|
||||
k = l;
|
||||
l = 2 * l;
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
|
||||
}
|
||||
{
|
||||
mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
|
||||
}
|
||||
mpz_set (y, x);
|
||||
c = 0;
|
||||
goto S2;
|
||||
S4:
|
||||
do
|
||||
{
|
||||
mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n);
|
||||
mpz_sub (t1, x1, y); mpz_gcd (g, t1, n);
|
||||
}
|
||||
{
|
||||
mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n);
|
||||
mpz_sub (t1, x1, y); mpz_gcd (g, t1, n);
|
||||
}
|
||||
while (mpz_cmp_ui (g, 1) == 0);
|
||||
|
||||
mpz_div (n, n, g); /* divide by g, before g is overwritten */
|
||||
|
||||
if (!mpz_probab_prime_p (g, 3))
|
||||
{
|
||||
do
|
||||
{
|
||||
mp_limb_t a_limb;
|
||||
mpn_random (&a_limb, (mp_size_t) 1);
|
||||
a_int = (int) a_limb;
|
||||
}
|
||||
while (a_int == -2 || a_int == 0);
|
||||
{
|
||||
do
|
||||
{
|
||||
mp_limb_t a_limb;
|
||||
mpn_random (&a_limb, (mp_size_t) 1);
|
||||
a_int = (int) a_limb;
|
||||
}
|
||||
while (a_int == -2 || a_int == 0);
|
||||
|
||||
debug ("[composite factor--restarting pollard-rho] ");
|
||||
factor_using_pollard_rho (g, a_int);
|
||||
}
|
||||
debug ("[composite factor--restarting pollard-rho] ");
|
||||
factor_using_pollard_rho (g, a_int);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_factor (g);
|
||||
}
|
||||
{
|
||||
emit_factor (g);
|
||||
}
|
||||
mpz_mod (x, x, n);
|
||||
mpz_mod (x1, x1, n);
|
||||
mpz_mod (y, y, n);
|
||||
if (mpz_probab_prime_p (n, 3))
|
||||
{
|
||||
emit_factor (n);
|
||||
break;
|
||||
}
|
||||
{
|
||||
emit_factor (n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mpz_clear (g);
|
||||
@@ -309,15 +309,15 @@ factor_wheel (uintmax_t n0, size_t max_n_factors, uintmax_t *factors)
|
||||
{
|
||||
q = n / d;
|
||||
while (n == q * d)
|
||||
{
|
||||
assert (n_factors < max_n_factors);
|
||||
factors[n_factors++] = d;
|
||||
n = q;
|
||||
q = n / d;
|
||||
}
|
||||
{
|
||||
assert (n_factors < max_n_factors);
|
||||
factors[n_factors++] = d;
|
||||
n = q;
|
||||
q = n / d;
|
||||
}
|
||||
d += *(w++);
|
||||
if (w == WHEEL_END)
|
||||
w = WHEEL_START;
|
||||
w = WHEEL_START;
|
||||
}
|
||||
while (d <= q);
|
||||
|
||||
@@ -407,13 +407,13 @@ print_factors_multi (mpz_t t)
|
||||
factor_using_division (t, division_limit);
|
||||
|
||||
if (mpz_cmp_ui (t, 1) != 0)
|
||||
{
|
||||
debug ("[is number prime?] ");
|
||||
if (mpz_probab_prime_p (t, 3))
|
||||
emit_factor (t);
|
||||
else
|
||||
factor_using_pollard_rho (t, 1);
|
||||
}
|
||||
{
|
||||
debug ("[is number prime?] ");
|
||||
if (mpz_probab_prime_p (t, 3))
|
||||
emit_factor (t);
|
||||
else
|
||||
factor_using_pollard_rho (t, 1);
|
||||
}
|
||||
}
|
||||
|
||||
mpz_clear (t);
|
||||
@@ -443,11 +443,11 @@ print_factors (char const *s)
|
||||
mpz_t t;
|
||||
mpz_init (t);
|
||||
if (gmp_sscanf (s, "%Zd", t) == 1)
|
||||
{
|
||||
debug ("[%s]", _("using arbitrary-precision arithmetic"));
|
||||
print_factors_multi (t);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
debug ("[%s]", _("using arbitrary-precision arithmetic"));
|
||||
print_factors_multi (t);
|
||||
return true;
|
||||
}
|
||||
err = LONGINT_INVALID;
|
||||
}
|
||||
#endif
|
||||
@@ -487,14 +487,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [NUMBER]...\n\
|
||||
or: %s OPTION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Print the prime factors of each specified integer NUMBER. If none\n\
|
||||
are specified on the command line, read them from standard input.\n\
|
||||
@@ -518,9 +518,9 @@ do_stdin (void)
|
||||
for (;;)
|
||||
{
|
||||
size_t token_length = readtoken (stdin, DELIM, sizeof (DELIM) - 1,
|
||||
&tokenbuffer);
|
||||
&tokenbuffer);
|
||||
if (token_length == (size_t) -1)
|
||||
break;
|
||||
break;
|
||||
ok &= print_factors (tokenbuffer.buffer);
|
||||
}
|
||||
free (tokenbuffer.buffer);
|
||||
@@ -545,18 +545,18 @@ main (int argc, char **argv)
|
||||
while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case VERBOSE_OPTION:
|
||||
verbose = true;
|
||||
break;
|
||||
{
|
||||
case VERBOSE_OPTION:
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= optind)
|
||||
@@ -566,8 +566,8 @@ main (int argc, char **argv)
|
||||
int i;
|
||||
ok = true;
|
||||
for (i = optind; i < argc; i++)
|
||||
if (! print_factors (argv[i]))
|
||||
ok = false;
|
||||
if (! print_factors (argv[i]))
|
||||
ok = false;
|
||||
}
|
||||
#if HAVE_GMP
|
||||
free (factor);
|
||||
|
||||
@@ -263,7 +263,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [-WIDTH] [OPTION]... [FILE]...\n"), program_name);
|
||||
@@ -281,7 +281,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
reattaching the prefix to reformatted lines\n\
|
||||
-s, --split-only split long lines, but do not refill\n\
|
||||
"),
|
||||
stdout);
|
||||
stdout);
|
||||
fputs (_("\
|
||||
-t, --tagged-paragraph indentation of first line different from second\n\
|
||||
-u, --uniform-spacing one space between words, two after sentences\n\
|
||||
@@ -292,7 +292,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
fputs (_("\
|
||||
\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n"),
|
||||
stdout);
|
||||
stdout);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
@@ -345,40 +345,40 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
while ((optchar = getopt_long (argc, argv, "0123456789cstuw:p:",
|
||||
long_options, NULL))
|
||||
!= -1)
|
||||
long_options, NULL))
|
||||
!= -1)
|
||||
switch (optchar)
|
||||
{
|
||||
default:
|
||||
if (ISDIGIT (optchar))
|
||||
error (0, 0, _("invalid option -- %c; -WIDTH is recognized\
|
||||
if (ISDIGIT (optchar))
|
||||
error (0, 0, _("invalid option -- %c; -WIDTH is recognized\
|
||||
only when it is the first\noption; use -w N instead"),
|
||||
optchar);
|
||||
usage (EXIT_FAILURE);
|
||||
optchar);
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
case 'c':
|
||||
crown = true;
|
||||
break;
|
||||
crown = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
split = true;
|
||||
break;
|
||||
split = true;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
tagged = true;
|
||||
break;
|
||||
tagged = true;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
uniform = true;
|
||||
break;
|
||||
uniform = true;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
max_width_option = optarg;
|
||||
break;
|
||||
max_width_option = optarg;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
set_prefix (optarg);
|
||||
break;
|
||||
set_prefix (optarg);
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
@@ -389,12 +389,12 @@ main (int argc, char **argv)
|
||||
if (max_width_option)
|
||||
{
|
||||
/* Limit max_width to MAXCHARS / 2; otherwise, the resulting
|
||||
output can be quite ugly. */
|
||||
output can be quite ugly. */
|
||||
unsigned long int tmp;
|
||||
if (! (xstrtoul (max_width_option, NULL, 10, &tmp, "") == LONGINT_OK
|
||||
&& tmp <= MAXCHARS / 2))
|
||||
error (EXIT_FAILURE, 0, _("invalid width: %s"),
|
||||
quote (max_width_option));
|
||||
&& tmp <= MAXCHARS / 2))
|
||||
error (EXIT_FAILURE, 0, _("invalid width: %s"),
|
||||
quote (max_width_option));
|
||||
max_width = tmp;
|
||||
}
|
||||
|
||||
@@ -405,31 +405,31 @@ main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
for (; optind < argc; optind++)
|
||||
{
|
||||
char *file = argv[optind];
|
||||
if (STREQ (file, "-"))
|
||||
fmt (stdin);
|
||||
else
|
||||
{
|
||||
FILE *in_stream;
|
||||
in_stream = fopen (file, "r");
|
||||
if (in_stream != NULL)
|
||||
{
|
||||
fmt (in_stream);
|
||||
if (fclose (in_stream) == EOF)
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno, _("cannot open %s for reading"),
|
||||
quote (file));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
char *file = argv[optind];
|
||||
if (STREQ (file, "-"))
|
||||
fmt (stdin);
|
||||
else
|
||||
{
|
||||
FILE *in_stream;
|
||||
in_stream = fopen (file, "r");
|
||||
if (in_stream != NULL)
|
||||
{
|
||||
fmt (in_stream);
|
||||
if (fclose (in_stream) == EOF)
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno, _("cannot open %s for reading"),
|
||||
quote (file));
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
@@ -488,9 +488,9 @@ set_other_indent (bool same_paragraph)
|
||||
else if (tagged)
|
||||
{
|
||||
if (same_paragraph && in_column != first_indent)
|
||||
{
|
||||
other_indent = in_column;
|
||||
}
|
||||
{
|
||||
other_indent = in_column;
|
||||
}
|
||||
|
||||
/* Only one line: use the secondary indent from last time if it
|
||||
splits, or 0 if there have been no multi-line paragraphs in the
|
||||
@@ -498,7 +498,7 @@ set_other_indent (bool same_paragraph)
|
||||
pick a new secondary indent. */
|
||||
|
||||
else if (other_indent == first_indent)
|
||||
other_indent = first_indent == 0 ? DEF_INDENT : 0;
|
||||
other_indent = first_indent == 0 ? DEF_INDENT : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -532,15 +532,15 @@ get_paragraph (FILE *f)
|
||||
/* Scan (and copy) blank lines, and lines not introduced by the prefix. */
|
||||
|
||||
while (c == '\n' || c == EOF
|
||||
|| next_prefix_indent < prefix_lead_space
|
||||
|| in_column < next_prefix_indent + prefix_full_length)
|
||||
|| next_prefix_indent < prefix_lead_space
|
||||
|| in_column < next_prefix_indent + prefix_full_length)
|
||||
{
|
||||
c = copy_rest (f, c);
|
||||
if (c == EOF)
|
||||
{
|
||||
next_char = EOF;
|
||||
return false;
|
||||
}
|
||||
{
|
||||
next_char = EOF;
|
||||
return false;
|
||||
}
|
||||
putchar ('\n');
|
||||
c = get_prefix (f);
|
||||
}
|
||||
@@ -563,29 +563,29 @@ get_paragraph (FILE *f)
|
||||
else if (crown)
|
||||
{
|
||||
if (same_para (c))
|
||||
{
|
||||
do
|
||||
{ /* for each line till the end of the para */
|
||||
c = get_line (f, c);
|
||||
}
|
||||
while (same_para (c) && in_column == other_indent);
|
||||
}
|
||||
{
|
||||
do
|
||||
{ /* for each line till the end of the para */
|
||||
c = get_line (f, c);
|
||||
}
|
||||
while (same_para (c) && in_column == other_indent);
|
||||
}
|
||||
}
|
||||
else if (tagged)
|
||||
{
|
||||
if (same_para (c) && in_column != first_indent)
|
||||
{
|
||||
do
|
||||
{ /* for each line till the end of the para */
|
||||
c = get_line (f, c);
|
||||
}
|
||||
while (same_para (c) && in_column == other_indent);
|
||||
}
|
||||
{
|
||||
do
|
||||
{ /* for each line till the end of the para */
|
||||
c = get_line (f, c);
|
||||
}
|
||||
while (same_para (c) && in_column == other_indent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (same_para (c) && in_column == other_indent)
|
||||
c = get_line (f, c);
|
||||
c = get_line (f, c);
|
||||
}
|
||||
(word_limit - 1)->period = (word_limit - 1)->final = true;
|
||||
next_char = c;
|
||||
@@ -607,11 +607,11 @@ copy_rest (FILE *f, int c)
|
||||
{
|
||||
put_space (next_prefix_indent);
|
||||
for (s = prefix; out_column != in_column && *s; out_column++)
|
||||
putchar (*s++);
|
||||
putchar (*s++);
|
||||
if (c != EOF && c != '\n')
|
||||
put_space (in_column - out_column);
|
||||
put_space (in_column - out_column);
|
||||
if (c == EOF && in_column >= next_prefix_indent + prefix_length)
|
||||
putchar ('\n');
|
||||
putchar ('\n');
|
||||
}
|
||||
while (c != '\n' && c != EOF)
|
||||
{
|
||||
@@ -629,8 +629,8 @@ static bool
|
||||
same_para (int c)
|
||||
{
|
||||
return (next_prefix_indent == prefix_indent
|
||||
&& in_column >= next_prefix_indent + prefix_full_length
|
||||
&& c != '\n' && c != EOF);
|
||||
&& in_column >= next_prefix_indent + prefix_full_length
|
||||
&& c != '\n' && c != EOF);
|
||||
}
|
||||
|
||||
/* Read a line from input file F, given first non-blank character C
|
||||
@@ -658,15 +658,15 @@ get_line (FILE *f, int c)
|
||||
|
||||
word_limit->text = wptr;
|
||||
do
|
||||
{
|
||||
if (wptr == end_of_parabuf)
|
||||
{
|
||||
set_other_indent (true);
|
||||
flush_paragraph ();
|
||||
}
|
||||
*wptr++ = c;
|
||||
c = getc (f);
|
||||
}
|
||||
{
|
||||
if (wptr == end_of_parabuf)
|
||||
{
|
||||
set_other_indent (true);
|
||||
flush_paragraph ();
|
||||
}
|
||||
*wptr++ = c;
|
||||
c = getc (f);
|
||||
}
|
||||
while (c != EOF && !isspace (c));
|
||||
in_column += word_limit->length = wptr - word_limit->text;
|
||||
check_punctuation (word_limit);
|
||||
@@ -677,15 +677,15 @@ get_line (FILE *f, int c)
|
||||
c = get_space (f, c);
|
||||
word_limit->space = in_column - start;
|
||||
word_limit->final = (c == EOF
|
||||
|| (word_limit->period
|
||||
&& (c == '\n' || word_limit->space > 1)));
|
||||
|| (word_limit->period
|
||||
&& (c == '\n' || word_limit->space > 1)));
|
||||
if (c == '\n' || c == EOF || uniform)
|
||||
word_limit->space = word_limit->final ? 2 : 1;
|
||||
word_limit->space = word_limit->final ? 2 : 1;
|
||||
if (word_limit == end_of_word)
|
||||
{
|
||||
set_other_indent (true);
|
||||
flush_paragraph ();
|
||||
}
|
||||
{
|
||||
set_other_indent (true);
|
||||
flush_paragraph ();
|
||||
}
|
||||
word_limit++;
|
||||
}
|
||||
while (c != '\n' && c != EOF);
|
||||
@@ -710,13 +710,13 @@ get_prefix (FILE *f)
|
||||
const char *p;
|
||||
next_prefix_indent = in_column;
|
||||
for (p = prefix; *p != '\0'; p++)
|
||||
{
|
||||
unsigned char pc = *p;
|
||||
if (c != pc)
|
||||
return c;
|
||||
in_column++;
|
||||
c = getc (f);
|
||||
}
|
||||
{
|
||||
unsigned char pc = *p;
|
||||
if (c != pc)
|
||||
return c;
|
||||
in_column++;
|
||||
c = getc (f);
|
||||
}
|
||||
c = get_space (f, c);
|
||||
}
|
||||
return c;
|
||||
@@ -731,14 +731,14 @@ get_space (FILE *f, int c)
|
||||
for (;;)
|
||||
{
|
||||
if (c == ' ')
|
||||
in_column++;
|
||||
in_column++;
|
||||
else if (c == '\t')
|
||||
{
|
||||
tabs = true;
|
||||
in_column = (in_column / TABWIDTH + 1) * TABWIDTH;
|
||||
}
|
||||
{
|
||||
tabs = true;
|
||||
in_column = (in_column / TABWIDTH + 1) * TABWIDTH;
|
||||
}
|
||||
else
|
||||
return c;
|
||||
return c;
|
||||
c = getc (f);
|
||||
}
|
||||
}
|
||||
@@ -794,12 +794,12 @@ flush_paragraph (void)
|
||||
for (w = word->next_break; w != word_limit; w = w->next_break)
|
||||
{
|
||||
if (w->best_cost - w->next_break->best_cost < best_break)
|
||||
{
|
||||
split_point = w;
|
||||
best_break = w->best_cost - w->next_break->best_cost;
|
||||
}
|
||||
{
|
||||
split_point = w;
|
||||
best_break = w->best_cost - w->next_break->best_cost;
|
||||
}
|
||||
if (best_break <= MAXCOST - LINE_CREDIT)
|
||||
best_break += LINE_CREDIT;
|
||||
best_break += LINE_CREDIT;
|
||||
}
|
||||
put_paragraph (split_point);
|
||||
|
||||
@@ -848,30 +848,30 @@ fmt_paragraph (void)
|
||||
w = start;
|
||||
len += w->length;
|
||||
do
|
||||
{
|
||||
w++;
|
||||
{
|
||||
w++;
|
||||
|
||||
/* Consider breaking before w. */
|
||||
/* Consider breaking before w. */
|
||||
|
||||
wcost = line_cost (w, len) + w->best_cost;
|
||||
if (start == word && last_line_length > 0)
|
||||
wcost += RAGGED_COST (len - last_line_length);
|
||||
if (wcost < best)
|
||||
{
|
||||
best = wcost;
|
||||
start->next_break = w;
|
||||
start->line_length = len;
|
||||
}
|
||||
wcost = line_cost (w, len) + w->best_cost;
|
||||
if (start == word && last_line_length > 0)
|
||||
wcost += RAGGED_COST (len - last_line_length);
|
||||
if (wcost < best)
|
||||
{
|
||||
best = wcost;
|
||||
start->next_break = w;
|
||||
start->line_length = len;
|
||||
}
|
||||
|
||||
/* This is a kludge to keep us from computing `len' as the
|
||||
sum of the sentinel length and some non-zero number.
|
||||
Since the sentinel w->length may be INT_MAX, adding
|
||||
to that would give a negative result. */
|
||||
if (w == word_limit)
|
||||
break;
|
||||
/* This is a kludge to keep us from computing `len' as the
|
||||
sum of the sentinel length and some non-zero number.
|
||||
Since the sentinel w->length may be INT_MAX, adding
|
||||
to that would give a negative result. */
|
||||
if (w == word_limit)
|
||||
break;
|
||||
|
||||
len += (w - 1)->space + w->length; /* w > start >= word */
|
||||
}
|
||||
len += (w - 1)->space + w->length; /* w > start >= word */
|
||||
}
|
||||
while (len < max_width);
|
||||
start->best_cost = best + base_cost (start);
|
||||
}
|
||||
@@ -892,16 +892,16 @@ base_cost (WORD *this)
|
||||
if (this > word)
|
||||
{
|
||||
if ((this - 1)->period)
|
||||
{
|
||||
if ((this - 1)->final)
|
||||
cost -= SENTENCE_BONUS;
|
||||
else
|
||||
cost += NOBREAK_COST;
|
||||
}
|
||||
{
|
||||
if ((this - 1)->final)
|
||||
cost -= SENTENCE_BONUS;
|
||||
else
|
||||
cost += NOBREAK_COST;
|
||||
}
|
||||
else if ((this - 1)->punct)
|
||||
cost -= PUNCT_BONUS;
|
||||
cost -= PUNCT_BONUS;
|
||||
else if (this > word + 1 && (this - 2)->final)
|
||||
cost += WIDOW_COST ((this - 1)->length);
|
||||
cost += WIDOW_COST ((this - 1)->length);
|
||||
}
|
||||
|
||||
if (this->paren)
|
||||
@@ -997,11 +997,11 @@ put_space (int space)
|
||||
{
|
||||
tab_target = space_target / TABWIDTH * TABWIDTH;
|
||||
if (out_column + 1 < tab_target)
|
||||
while (out_column < tab_target)
|
||||
{
|
||||
putchar ('\t');
|
||||
out_column = (out_column / TABWIDTH + 1) * TABWIDTH;
|
||||
}
|
||||
while (out_column < tab_target)
|
||||
{
|
||||
putchar ('\t');
|
||||
out_column = (out_column / TABWIDTH + 1) * TABWIDTH;
|
||||
}
|
||||
}
|
||||
while (out_column < space_target)
|
||||
{
|
||||
|
||||
+97
-97
@@ -60,13 +60,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Wrap input lines in each FILE (standard input by default), writing to\n\
|
||||
standard output.\n\
|
||||
@@ -97,16 +97,16 @@ adjust_column (size_t column, char c)
|
||||
if (!count_bytes)
|
||||
{
|
||||
if (c == '\b')
|
||||
{
|
||||
if (column > 0)
|
||||
column--;
|
||||
}
|
||||
{
|
||||
if (column > 0)
|
||||
column--;
|
||||
}
|
||||
else if (c == '\r')
|
||||
column = 0;
|
||||
column = 0;
|
||||
else if (c == '\t')
|
||||
column += TAB_WIDTH - column % TAB_WIDTH;
|
||||
column += TAB_WIDTH - column % TAB_WIDTH;
|
||||
else /* if (isprint (c)) */
|
||||
column++;
|
||||
column++;
|
||||
}
|
||||
else
|
||||
column++;
|
||||
@@ -145,71 +145,71 @@ fold_file (char const *filename, size_t width)
|
||||
while ((c = getc (istream)) != EOF)
|
||||
{
|
||||
if (offset_out + 1 >= allocated_out)
|
||||
line_out = X2REALLOC (line_out, &allocated_out);
|
||||
line_out = X2REALLOC (line_out, &allocated_out);
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
line_out[offset_out++] = c;
|
||||
fwrite (line_out, sizeof (char), offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
continue;
|
||||
}
|
||||
{
|
||||
line_out[offset_out++] = c;
|
||||
fwrite (line_out, sizeof (char), offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
rescan:
|
||||
column = adjust_column (column, c);
|
||||
|
||||
if (column > width)
|
||||
{
|
||||
/* This character would make the line too long.
|
||||
Print the line plus a newline, and make this character
|
||||
start the next line. */
|
||||
if (break_spaces)
|
||||
{
|
||||
bool found_blank = false;
|
||||
size_t logical_end = offset_out;
|
||||
{
|
||||
/* This character would make the line too long.
|
||||
Print the line plus a newline, and make this character
|
||||
start the next line. */
|
||||
if (break_spaces)
|
||||
{
|
||||
bool found_blank = false;
|
||||
size_t logical_end = offset_out;
|
||||
|
||||
/* Look for the last blank. */
|
||||
while (logical_end)
|
||||
{
|
||||
--logical_end;
|
||||
if (isblank (to_uchar (line_out[logical_end])))
|
||||
{
|
||||
found_blank = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Look for the last blank. */
|
||||
while (logical_end)
|
||||
{
|
||||
--logical_end;
|
||||
if (isblank (to_uchar (line_out[logical_end])))
|
||||
{
|
||||
found_blank = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_blank)
|
||||
{
|
||||
size_t i;
|
||||
if (found_blank)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* Found a blank. Don't output the part after it. */
|
||||
logical_end++;
|
||||
fwrite (line_out, sizeof (char), (size_t) logical_end,
|
||||
stdout);
|
||||
putchar ('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
The areas being copied here might overlap. */
|
||||
memmove (line_out, line_out + logical_end,
|
||||
offset_out - logical_end);
|
||||
offset_out -= logical_end;
|
||||
for (column = i = 0; i < offset_out; i++)
|
||||
column = adjust_column (column, line_out[i]);
|
||||
goto rescan;
|
||||
}
|
||||
}
|
||||
/* Found a blank. Don't output the part after it. */
|
||||
logical_end++;
|
||||
fwrite (line_out, sizeof (char), (size_t) logical_end,
|
||||
stdout);
|
||||
putchar ('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
The areas being copied here might overlap. */
|
||||
memmove (line_out, line_out + logical_end,
|
||||
offset_out - logical_end);
|
||||
offset_out -= logical_end;
|
||||
for (column = i = 0; i < offset_out; i++)
|
||||
column = adjust_column (column, line_out[i]);
|
||||
goto rescan;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset_out == 0)
|
||||
{
|
||||
line_out[offset_out++] = c;
|
||||
continue;
|
||||
}
|
||||
if (offset_out == 0)
|
||||
{
|
||||
line_out[offset_out++] = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
line_out[offset_out++] = '\n';
|
||||
fwrite (line_out, sizeof (char), (size_t) offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
goto rescan;
|
||||
}
|
||||
line_out[offset_out++] = '\n';
|
||||
fwrite (line_out, sizeof (char), (size_t) offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
goto rescan;
|
||||
}
|
||||
|
||||
line_out[offset_out++] = c;
|
||||
}
|
||||
@@ -223,7 +223,7 @@ fold_file (char const *filename, size_t width)
|
||||
{
|
||||
error (0, saved_errno, "%s", filename);
|
||||
if (!STREQ (filename, "-"))
|
||||
fclose (istream);
|
||||
fclose (istream);
|
||||
return false;
|
||||
}
|
||||
if (!STREQ (filename, "-") && fclose (istream) == EOF)
|
||||
@@ -258,44 +258,44 @@ main (int argc, char **argv)
|
||||
char optargbuf[2];
|
||||
|
||||
switch (optc)
|
||||
{
|
||||
case 'b': /* Count bytes rather than columns. */
|
||||
count_bytes = true;
|
||||
break;
|
||||
{
|
||||
case 'b': /* Count bytes rather than columns. */
|
||||
count_bytes = true;
|
||||
break;
|
||||
|
||||
case 's': /* Break at word boundaries. */
|
||||
break_spaces = true;
|
||||
break;
|
||||
case 's': /* Break at word boundaries. */
|
||||
break_spaces = true;
|
||||
break;
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
if (optarg)
|
||||
optarg--;
|
||||
else
|
||||
{
|
||||
optargbuf[0] = optc;
|
||||
optargbuf[1] = '\0';
|
||||
optarg = optargbuf;
|
||||
}
|
||||
/* Fall through. */
|
||||
case 'w': /* Line width. */
|
||||
{
|
||||
unsigned long int tmp_ulong;
|
||||
if (! (xstrtoul (optarg, NULL, 10, &tmp_ulong, "") == LONGINT_OK
|
||||
&& 0 < tmp_ulong && tmp_ulong < SIZE_MAX - TAB_WIDTH))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid number of columns: %s"), quote (optarg));
|
||||
width = tmp_ulong;
|
||||
}
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
if (optarg)
|
||||
optarg--;
|
||||
else
|
||||
{
|
||||
optargbuf[0] = optc;
|
||||
optargbuf[1] = '\0';
|
||||
optarg = optargbuf;
|
||||
}
|
||||
/* Fall through. */
|
||||
case 'w': /* Line width. */
|
||||
{
|
||||
unsigned long int tmp_ulong;
|
||||
if (! (xstrtoul (optarg, NULL, 10, &tmp_ulong, "") == LONGINT_OK
|
||||
&& 0 < tmp_ulong && tmp_ulong < SIZE_MAX - TAB_WIDTH))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid number of columns: %s"), quote (optarg));
|
||||
width = tmp_ulong;
|
||||
}
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == optind)
|
||||
@@ -304,7 +304,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
ok = true;
|
||||
for (i = optind; i < argc; i++)
|
||||
ok &= fold_file (argv[i], width);
|
||||
ok &= fold_file (argv[i], width);
|
||||
}
|
||||
|
||||
if (have_read_stdin && fclose (stdin) == EOF)
|
||||
|
||||
+338
-338
@@ -102,13 +102,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Print the first 10 lines of each FILE to standard output.\n\
|
||||
With more than one FILE, precede each with a header giving the file name.\n\
|
||||
@@ -186,15 +186,15 @@ copy_fd (int src_fd, FILE *o_stream, uintmax_t n_bytes)
|
||||
size_t n_to_read = MIN (buf_size, n_bytes);
|
||||
size_t n_read = safe_read (src_fd, buf, n_to_read);
|
||||
if (n_read == SAFE_READ_ERROR)
|
||||
return COPY_FD_READ_ERROR;
|
||||
return COPY_FD_READ_ERROR;
|
||||
|
||||
n_bytes -= n_read;
|
||||
|
||||
if (n_read == 0 && n_bytes != 0)
|
||||
return COPY_FD_UNEXPECTED_EOF;
|
||||
return COPY_FD_UNEXPECTED_EOF;
|
||||
|
||||
if (fwrite (buf, 1, n_read, o_stream) < n_read)
|
||||
return COPY_FD_WRITE_ERROR;
|
||||
return COPY_FD_WRITE_ERROR;
|
||||
}
|
||||
|
||||
return COPY_FD_OK;
|
||||
@@ -229,7 +229,7 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0)
|
||||
{
|
||||
char umax_buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
error (EXIT_FAILURE, 0, _("%s: number of bytes is too large"),
|
||||
umaxtostr (n_elide_0, umax_buf));
|
||||
umaxtostr (n_elide_0, umax_buf));
|
||||
}
|
||||
|
||||
/* Two cases to consider...
|
||||
@@ -255,54 +255,54 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0)
|
||||
b[1] = b[0] + n_to_read;
|
||||
|
||||
for (i = false; ! eof ; i = !i)
|
||||
{
|
||||
size_t n_read = full_read (fd, b[i], n_to_read);
|
||||
size_t delta = 0;
|
||||
if (n_read < n_to_read)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
{
|
||||
size_t n_read = full_read (fd, b[i], n_to_read);
|
||||
size_t delta = 0;
|
||||
if (n_read < n_to_read)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
/* reached EOF */
|
||||
if (n_read <= n_elide)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
/* The input is no larger than the number of bytes
|
||||
to elide. So there's nothing to output, and
|
||||
we're done. */
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = n_elide - n_read;
|
||||
}
|
||||
}
|
||||
eof = true;
|
||||
}
|
||||
/* reached EOF */
|
||||
if (n_read <= n_elide)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
/* The input is no larger than the number of bytes
|
||||
to elide. So there's nothing to output, and
|
||||
we're done. */
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = n_elide - n_read;
|
||||
}
|
||||
}
|
||||
eof = true;
|
||||
}
|
||||
|
||||
/* Output any (but maybe just part of the) elided data from
|
||||
the previous round. */
|
||||
if ( ! first)
|
||||
{
|
||||
/* Don't bother checking for errors here.
|
||||
If there's a failure, the test of the following
|
||||
fwrite or in close_stdout will catch it. */
|
||||
fwrite (b[!i] + READ_BUFSIZE, 1, n_elide - delta, stdout);
|
||||
}
|
||||
first = false;
|
||||
/* Output any (but maybe just part of the) elided data from
|
||||
the previous round. */
|
||||
if ( ! first)
|
||||
{
|
||||
/* Don't bother checking for errors here.
|
||||
If there's a failure, the test of the following
|
||||
fwrite or in close_stdout will catch it. */
|
||||
fwrite (b[!i] + READ_BUFSIZE, 1, n_elide - delta, stdout);
|
||||
}
|
||||
first = false;
|
||||
|
||||
if (n_elide < n_read
|
||||
&& fwrite (b[i], 1, n_read - n_elide, stdout) < n_read - n_elide)
|
||||
{
|
||||
error (0, errno, _("write error"));
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n_elide < n_read
|
||||
&& fwrite (b[i], 1, n_read - n_elide, stdout) < n_read - n_elide)
|
||||
{
|
||||
error (0, errno, _("write error"));
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free (b[0]);
|
||||
return ok;
|
||||
@@ -310,7 +310,7 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0)
|
||||
else
|
||||
{
|
||||
/* Read blocks of size READ_BUFSIZE, until we've read at least n_elide
|
||||
bytes. Then, for each new buffer we read, also write an old one. */
|
||||
bytes. Then, for each new buffer we read, also write an old one. */
|
||||
|
||||
bool ok = true;
|
||||
bool eof = false;
|
||||
@@ -326,74 +326,74 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0)
|
||||
|
||||
buffered_enough = false;
|
||||
for (i = 0, i_next = 1; !eof; i = i_next, i_next = (i_next + 1) % n_bufs)
|
||||
{
|
||||
if (b[i] == NULL)
|
||||
b[i] = xmalloc (READ_BUFSIZE);
|
||||
n_read = full_read (fd, b[i], READ_BUFSIZE);
|
||||
if (n_read < READ_BUFSIZE)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
ok = false;
|
||||
goto free_mem;
|
||||
}
|
||||
eof = true;
|
||||
}
|
||||
{
|
||||
if (b[i] == NULL)
|
||||
b[i] = xmalloc (READ_BUFSIZE);
|
||||
n_read = full_read (fd, b[i], READ_BUFSIZE);
|
||||
if (n_read < READ_BUFSIZE)
|
||||
{
|
||||
if (errno != 0)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
ok = false;
|
||||
goto free_mem;
|
||||
}
|
||||
eof = true;
|
||||
}
|
||||
|
||||
if (i + 1 == n_bufs)
|
||||
buffered_enough = true;
|
||||
if (i + 1 == n_bufs)
|
||||
buffered_enough = true;
|
||||
|
||||
if (buffered_enough)
|
||||
{
|
||||
if (fwrite (b[i_next], 1, n_read, stdout) < n_read)
|
||||
{
|
||||
error (0, errno, _("write error"));
|
||||
ok = false;
|
||||
goto free_mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buffered_enough)
|
||||
{
|
||||
if (fwrite (b[i_next], 1, n_read, stdout) < n_read)
|
||||
{
|
||||
error (0, errno, _("write error"));
|
||||
ok = false;
|
||||
goto free_mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Output any remainder: rem bytes from b[i] + n_read. */
|
||||
if (rem)
|
||||
{
|
||||
if (buffered_enough)
|
||||
{
|
||||
size_t n_bytes_left_in_b_i = READ_BUFSIZE - n_read;
|
||||
if (rem < n_bytes_left_in_b_i)
|
||||
{
|
||||
fwrite (b[i] + n_read, 1, rem, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite (b[i] + n_read, 1, n_bytes_left_in_b_i, stdout);
|
||||
fwrite (b[i_next], 1, rem - n_bytes_left_in_b_i, stdout);
|
||||
}
|
||||
}
|
||||
else if (i + 1 == n_bufs)
|
||||
{
|
||||
/* This happens when n_elide < file_size < n_elide_round.
|
||||
{
|
||||
if (buffered_enough)
|
||||
{
|
||||
size_t n_bytes_left_in_b_i = READ_BUFSIZE - n_read;
|
||||
if (rem < n_bytes_left_in_b_i)
|
||||
{
|
||||
fwrite (b[i] + n_read, 1, rem, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite (b[i] + n_read, 1, n_bytes_left_in_b_i, stdout);
|
||||
fwrite (b[i_next], 1, rem - n_bytes_left_in_b_i, stdout);
|
||||
}
|
||||
}
|
||||
else if (i + 1 == n_bufs)
|
||||
{
|
||||
/* This happens when n_elide < file_size < n_elide_round.
|
||||
|
||||
|READ_BUF.|
|
||||
| | rem |
|
||||
|---------!---------!---------!---------|
|
||||
|---- n_elide ---------|
|
||||
| | x |
|
||||
| |y |
|
||||
|---- file size -----------|
|
||||
| |n_read|
|
||||
|---- n_elide_round ----------|
|
||||
*/
|
||||
size_t y = READ_BUFSIZE - rem;
|
||||
size_t x = n_read - y;
|
||||
fwrite (b[i_next], 1, x, stdout);
|
||||
}
|
||||
}
|
||||
|READ_BUF.|
|
||||
| | rem |
|
||||
|---------!---------!---------!---------|
|
||||
|---- n_elide ---------|
|
||||
| | x |
|
||||
| |y |
|
||||
|---- file size -----------|
|
||||
| |n_read|
|
||||
|---- n_elide_round ----------|
|
||||
*/
|
||||
size_t y = READ_BUFSIZE - rem;
|
||||
size_t x = n_read - y;
|
||||
fwrite (b[i_next], 1, x, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
free_mem:;
|
||||
for (i = 0; i < n_bufs; i++)
|
||||
free (b[i]);
|
||||
free (b[i]);
|
||||
free (b);
|
||||
|
||||
return ok;
|
||||
@@ -424,31 +424,31 @@ elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide)
|
||||
enum Copy_fd_status err;
|
||||
|
||||
if ((current_pos = lseek (fd, (off_t) 0, SEEK_CUR)) == -1
|
||||
|| (end_pos = lseek (fd, (off_t) 0, SEEK_END)) == -1)
|
||||
{
|
||||
error (0, errno, _("cannot lseek %s"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
|| (end_pos = lseek (fd, (off_t) 0, SEEK_END)) == -1)
|
||||
{
|
||||
error (0, errno, _("cannot lseek %s"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Be careful here. The current position may actually be
|
||||
beyond the end of the file. */
|
||||
beyond the end of the file. */
|
||||
bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 : diff;
|
||||
|
||||
if (bytes_remaining <= n_elide)
|
||||
return true;
|
||||
return true;
|
||||
|
||||
/* Seek back to `current' position, then copy the required
|
||||
number of bytes from fd. */
|
||||
number of bytes from fd. */
|
||||
if (lseek (fd, (off_t) 0, current_pos) == -1)
|
||||
{
|
||||
error (0, errno, _("%s: cannot lseek back to original position"),
|
||||
quote (filename));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("%s: cannot lseek back to original position"),
|
||||
quote (filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
err = copy_fd (fd, stdout, bytes_remaining - n_elide);
|
||||
if (err == COPY_FD_OK)
|
||||
return true;
|
||||
return true;
|
||||
|
||||
diagnose_copy_fd_failure (err, filename);
|
||||
return false;
|
||||
@@ -488,20 +488,20 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide)
|
||||
{
|
||||
n_read = safe_read (fd, tmp->buffer, BUFSIZ);
|
||||
if (n_read == 0 || n_read == SAFE_READ_ERROR)
|
||||
break;
|
||||
break;
|
||||
tmp->nbytes = n_read;
|
||||
tmp->nlines = 0;
|
||||
tmp->next = NULL;
|
||||
|
||||
/* Count the number of newlines just read. */
|
||||
{
|
||||
char const *buffer_end = tmp->buffer + n_read;
|
||||
char const *p = tmp->buffer;
|
||||
while ((p = memchr (p, '\n', buffer_end - p)))
|
||||
{
|
||||
++p;
|
||||
++tmp->nlines;
|
||||
}
|
||||
char const *buffer_end = tmp->buffer + n_read;
|
||||
char const *p = tmp->buffer;
|
||||
while ((p = memchr (p, '\n', buffer_end - p)))
|
||||
{
|
||||
++p;
|
||||
++tmp->nlines;
|
||||
}
|
||||
}
|
||||
total_lines += tmp->nlines;
|
||||
|
||||
@@ -509,29 +509,29 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide)
|
||||
one to it. This is because when reading from a pipe, `n_read' can
|
||||
often be very small. */
|
||||
if (tmp->nbytes + last->nbytes < BUFSIZ)
|
||||
{
|
||||
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
|
||||
last->nbytes += tmp->nbytes;
|
||||
last->nlines += tmp->nlines;
|
||||
}
|
||||
{
|
||||
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
|
||||
last->nbytes += tmp->nbytes;
|
||||
last->nlines += tmp->nlines;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there's not enough room, link the new buffer onto the end of
|
||||
the list, then either free up the oldest buffer for the next
|
||||
read if that would leave enough lines, or else malloc a new one.
|
||||
Some compaction mechanism is possible but probably not
|
||||
worthwhile. */
|
||||
last = last->next = tmp;
|
||||
if (n_elide < total_lines - first->nlines)
|
||||
{
|
||||
fwrite (first->buffer, 1, first->nbytes, stdout);
|
||||
tmp = first;
|
||||
total_lines -= first->nlines;
|
||||
first = first->next;
|
||||
}
|
||||
else
|
||||
tmp = xmalloc (sizeof (LBUFFER));
|
||||
}
|
||||
{
|
||||
/* If there's not enough room, link the new buffer onto the end of
|
||||
the list, then either free up the oldest buffer for the next
|
||||
read if that would leave enough lines, or else malloc a new one.
|
||||
Some compaction mechanism is possible but probably not
|
||||
worthwhile. */
|
||||
last = last->next = tmp;
|
||||
if (n_elide < total_lines - first->nlines)
|
||||
{
|
||||
fwrite (first->buffer, 1, first->nbytes, stdout);
|
||||
tmp = first;
|
||||
total_lines -= first->nlines;
|
||||
first = first->next;
|
||||
}
|
||||
else
|
||||
tmp = xmalloc (sizeof (LBUFFER));
|
||||
}
|
||||
}
|
||||
|
||||
free (tmp);
|
||||
@@ -564,11 +564,11 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide)
|
||||
char const *buffer_end = tmp->buffer + tmp->nbytes;
|
||||
char const *p = tmp->buffer;
|
||||
while (n && (p = memchr (p, '\n', buffer_end - p)))
|
||||
{
|
||||
++p;
|
||||
++tmp->nlines;
|
||||
--n;
|
||||
}
|
||||
{
|
||||
++p;
|
||||
++tmp->nlines;
|
||||
--n;
|
||||
}
|
||||
fwrite (tmp->buffer, 1, p - tmp->buffer, stdout);
|
||||
}
|
||||
|
||||
@@ -595,8 +595,8 @@ free_lbuffers:
|
||||
in a less efficient implementation or a messy interface. */
|
||||
static bool
|
||||
elide_tail_lines_seekable (const char *pretty_filename, int fd,
|
||||
uintmax_t n_lines,
|
||||
off_t start_pos, off_t end_pos)
|
||||
uintmax_t n_lines,
|
||||
off_t start_pos, off_t end_pos)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
size_t bytes_read;
|
||||
@@ -614,7 +614,7 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd,
|
||||
{
|
||||
char offset_buf[INT_BUFSIZE_BOUND (off_t)];
|
||||
error (0, errno, _("%s: cannot seek to offset %s"),
|
||||
pretty_filename, offtostr (pos, offset_buf));
|
||||
pretty_filename, offtostr (pos, offset_buf));
|
||||
return false;
|
||||
}
|
||||
bytes_read = safe_read (fd, buffer, bytes_read);
|
||||
@@ -634,72 +634,72 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd,
|
||||
|
||||
size_t n = bytes_read;
|
||||
while (n)
|
||||
{
|
||||
char const *nl;
|
||||
nl = memrchr (buffer, '\n', n);
|
||||
if (nl == NULL)
|
||||
break;
|
||||
n = nl - buffer;
|
||||
if (n_lines-- == 0)
|
||||
{
|
||||
/* Found it. */
|
||||
/* If necessary, restore the file pointer and copy
|
||||
input to output up to position, POS. */
|
||||
if (start_pos < pos)
|
||||
{
|
||||
enum Copy_fd_status err;
|
||||
if (lseek (fd, start_pos, SEEK_SET) < 0)
|
||||
{
|
||||
/* Failed to reposition file pointer. */
|
||||
error (0, errno,
|
||||
"%s: unable to restore file pointer to initial offset",
|
||||
quote (pretty_filename));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
char const *nl;
|
||||
nl = memrchr (buffer, '\n', n);
|
||||
if (nl == NULL)
|
||||
break;
|
||||
n = nl - buffer;
|
||||
if (n_lines-- == 0)
|
||||
{
|
||||
/* Found it. */
|
||||
/* If necessary, restore the file pointer and copy
|
||||
input to output up to position, POS. */
|
||||
if (start_pos < pos)
|
||||
{
|
||||
enum Copy_fd_status err;
|
||||
if (lseek (fd, start_pos, SEEK_SET) < 0)
|
||||
{
|
||||
/* Failed to reposition file pointer. */
|
||||
error (0, errno,
|
||||
"%s: unable to restore file pointer to initial offset",
|
||||
quote (pretty_filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
err = copy_fd (fd, stdout, pos - start_pos);
|
||||
if (err != COPY_FD_OK)
|
||||
{
|
||||
diagnose_copy_fd_failure (err, pretty_filename);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
err = copy_fd (fd, stdout, pos - start_pos);
|
||||
if (err != COPY_FD_OK)
|
||||
{
|
||||
diagnose_copy_fd_failure (err, pretty_filename);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the initial portion of the buffer
|
||||
in which we found the desired newline byte.
|
||||
Don't bother testing for failure for such a small amount.
|
||||
Any failure will be detected upon close. */
|
||||
fwrite (buffer, 1, n + 1, stdout);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/* Output the initial portion of the buffer
|
||||
in which we found the desired newline byte.
|
||||
Don't bother testing for failure for such a small amount.
|
||||
Any failure will be detected upon close. */
|
||||
fwrite (buffer, 1, n + 1, stdout);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough newlines in that bufferfull. */
|
||||
if (pos == start_pos)
|
||||
{
|
||||
/* Not enough lines in the file. */
|
||||
return true;
|
||||
}
|
||||
{
|
||||
/* Not enough lines in the file. */
|
||||
return true;
|
||||
}
|
||||
pos -= BUFSIZ;
|
||||
if (lseek (fd, pos, SEEK_SET) < 0)
|
||||
{
|
||||
char offset_buf[INT_BUFSIZE_BOUND (off_t)];
|
||||
error (0, errno, _("%s: cannot seek to offset %s"),
|
||||
pretty_filename, offtostr (pos, offset_buf));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
char offset_buf[INT_BUFSIZE_BOUND (off_t)];
|
||||
error (0, errno, _("%s: cannot seek to offset %s"),
|
||||
pretty_filename, offtostr (pos, offset_buf));
|
||||
return false;
|
||||
}
|
||||
|
||||
bytes_read = safe_read (fd, buffer, BUFSIZ);
|
||||
if (bytes_read == SAFE_READ_ERROR)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (pretty_filename));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (pretty_filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* FIXME: is this dead code?
|
||||
Consider the test, pos == start_pos, above. */
|
||||
Consider the test, pos == start_pos, above. */
|
||||
if (bytes_read == 0)
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,24 +713,24 @@ elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide)
|
||||
if (!presume_input_pipe)
|
||||
{
|
||||
/* Find the offset, OFF, of the Nth newline from the end,
|
||||
but not counting the last byte of the file.
|
||||
If found, write from current position to OFF, inclusive.
|
||||
Otherwise, just return true. */
|
||||
but not counting the last byte of the file.
|
||||
If found, write from current position to OFF, inclusive.
|
||||
Otherwise, just return true. */
|
||||
|
||||
off_t start_pos = lseek (fd, (off_t) 0, SEEK_CUR);
|
||||
off_t end_pos = lseek (fd, (off_t) 0, SEEK_END);
|
||||
if (0 <= start_pos && start_pos < end_pos)
|
||||
{
|
||||
/* If the file is empty, we're done. */
|
||||
if (end_pos == 0)
|
||||
return true;
|
||||
{
|
||||
/* If the file is empty, we're done. */
|
||||
if (end_pos == 0)
|
||||
return true;
|
||||
|
||||
return elide_tail_lines_seekable (filename, fd, n_elide,
|
||||
start_pos, end_pos);
|
||||
}
|
||||
return elide_tail_lines_seekable (filename, fd, n_elide,
|
||||
start_pos, end_pos);
|
||||
}
|
||||
|
||||
/* lseek failed or the end offset precedes start.
|
||||
Fall through. */
|
||||
Fall through. */
|
||||
}
|
||||
|
||||
return elide_tail_lines_pipe (filename, fd, n_elide);
|
||||
@@ -746,17 +746,17 @@ head_bytes (const char *filename, int fd, uintmax_t bytes_to_write)
|
||||
{
|
||||
size_t bytes_read;
|
||||
if (bytes_to_write < bytes_to_read)
|
||||
bytes_to_read = bytes_to_write;
|
||||
bytes_to_read = bytes_to_write;
|
||||
bytes_read = safe_read (fd, buffer, bytes_to_read);
|
||||
if (bytes_read == SAFE_READ_ERROR)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
if (bytes_read == 0)
|
||||
break;
|
||||
break;
|
||||
if (fwrite (buffer, 1, bytes_read, stdout) < bytes_read)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
bytes_to_write -= bytes_read;
|
||||
}
|
||||
return true;
|
||||
@@ -773,31 +773,31 @@ head_lines (const char *filename, int fd, uintmax_t lines_to_write)
|
||||
size_t bytes_to_write = 0;
|
||||
|
||||
if (bytes_read == SAFE_READ_ERROR)
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("error reading %s"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
if (bytes_read == 0)
|
||||
break;
|
||||
break;
|
||||
while (bytes_to_write < bytes_read)
|
||||
if (buffer[bytes_to_write++] == '\n' && --lines_to_write == 0)
|
||||
{
|
||||
off_t n_bytes_past_EOL = bytes_read - bytes_to_write;
|
||||
/* If we have read more data than that on the specified number
|
||||
of lines, try to seek back to the position we would have
|
||||
gotten to had we been reading one byte at a time. */
|
||||
if (lseek (fd, -n_bytes_past_EOL, SEEK_CUR) < 0)
|
||||
{
|
||||
int e = errno;
|
||||
struct stat st;
|
||||
if (fstat (fd, &st) != 0 || S_ISREG (st.st_mode))
|
||||
error (0, e, _("cannot reposition file pointer for %s"),
|
||||
quote (filename));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (buffer[bytes_to_write++] == '\n' && --lines_to_write == 0)
|
||||
{
|
||||
off_t n_bytes_past_EOL = bytes_read - bytes_to_write;
|
||||
/* If we have read more data than that on the specified number
|
||||
of lines, try to seek back to the position we would have
|
||||
gotten to had we been reading one byte at a time. */
|
||||
if (lseek (fd, -n_bytes_past_EOL, SEEK_CUR) < 0)
|
||||
{
|
||||
int e = errno;
|
||||
struct stat st;
|
||||
if (fstat (fd, &st) != 0 || S_ISREG (st.st_mode))
|
||||
error (0, e, _("cannot reposition file pointer for %s"),
|
||||
quote (filename));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (fwrite (buffer, 1, bytes_to_write, stdout) < bytes_to_write)
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
error (EXIT_FAILURE, errno, _("write error"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -812,13 +812,13 @@ head (const char *filename, int fd, uintmax_t n_units, bool count_lines,
|
||||
if (elide_from_end)
|
||||
{
|
||||
if (count_lines)
|
||||
{
|
||||
return elide_tail_lines_file (filename, fd, n_units);
|
||||
}
|
||||
{
|
||||
return elide_tail_lines_file (filename, fd, n_units);
|
||||
}
|
||||
else
|
||||
{
|
||||
return elide_tail_bytes_file (filename, fd, n_units);
|
||||
}
|
||||
{
|
||||
return elide_tail_bytes_file (filename, fd, n_units);
|
||||
}
|
||||
}
|
||||
if (count_lines)
|
||||
return head_lines (filename, fd, n_units);
|
||||
@@ -828,7 +828,7 @@ head (const char *filename, int fd, uintmax_t n_units, bool count_lines,
|
||||
|
||||
static bool
|
||||
head_file (const char *filename, uintmax_t n_units, bool count_lines,
|
||||
bool elide_from_end)
|
||||
bool elide_from_end)
|
||||
{
|
||||
int fd;
|
||||
bool ok;
|
||||
@@ -840,16 +840,16 @@ head_file (const char *filename, uintmax_t n_units, bool count_lines,
|
||||
fd = STDIN_FILENO;
|
||||
filename = _("standard input");
|
||||
if (O_BINARY && ! isatty (STDIN_FILENO))
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = open (filename, O_RDONLY | O_BINARY);
|
||||
if (fd < 0)
|
||||
{
|
||||
error (0, errno, _("cannot open %s for reading"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot open %s for reading"), quote (filename));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ok = head (filename, fd, n_units, count_lines, elide_from_end);
|
||||
@@ -878,16 +878,16 @@ string_to_integer (bool count_lines, const char *n_string)
|
||||
if (s_err == LONGINT_OVERFLOW)
|
||||
{
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%s: %s is so large that it is not representable"), n_string,
|
||||
count_lines ? _("number of lines") : _("number of bytes"));
|
||||
_("%s: %s is so large that it is not representable"), n_string,
|
||||
count_lines ? _("number of lines") : _("number of bytes"));
|
||||
}
|
||||
|
||||
if (s_err != LONGINT_OK)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, "%s: %s", n_string,
|
||||
(count_lines
|
||||
? _("invalid number of lines")
|
||||
: _("invalid number of bytes")));
|
||||
(count_lines
|
||||
? _("invalid number of lines")
|
||||
: _("invalid number of bytes")));
|
||||
}
|
||||
|
||||
return n;
|
||||
@@ -937,7 +937,7 @@ main (int argc, char **argv)
|
||||
char multiplier_char = 0;
|
||||
|
||||
/* Old option syntax; a dash, one or more digits, and one or
|
||||
more option letters. Move past the number. */
|
||||
more option letters. Move past the number. */
|
||||
do ++a;
|
||||
while (ISDIGIT (*a));
|
||||
|
||||
@@ -946,44 +946,44 @@ main (int argc, char **argv)
|
||||
|
||||
/* Parse any appended option letters. */
|
||||
for (; *a; a++)
|
||||
{
|
||||
switch (*a)
|
||||
{
|
||||
case 'c':
|
||||
count_lines = false;
|
||||
multiplier_char = 0;
|
||||
break;
|
||||
{
|
||||
switch (*a)
|
||||
{
|
||||
case 'c':
|
||||
count_lines = false;
|
||||
multiplier_char = 0;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
case 'k':
|
||||
case 'm':
|
||||
count_lines = false;
|
||||
multiplier_char = *a;
|
||||
break;
|
||||
case 'b':
|
||||
case 'k':
|
||||
case 'm':
|
||||
count_lines = false;
|
||||
multiplier_char = *a;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
count_lines = true;
|
||||
break;
|
||||
case 'l':
|
||||
count_lines = true;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
header_mode = never;
|
||||
break;
|
||||
case 'q':
|
||||
header_mode = never;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
header_mode = always;
|
||||
break;
|
||||
case 'v':
|
||||
header_mode = always;
|
||||
break;
|
||||
|
||||
default:
|
||||
error (0, 0, _("invalid trailing option -- %c"), *a);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
default:
|
||||
error (0, 0, _("invalid trailing option -- %c"), *a);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Append the multiplier character (if any) onto the end of
|
||||
the digit string. Then add NUL byte if necessary. */
|
||||
the digit string. Then add NUL byte if necessary. */
|
||||
*end_n_string = multiplier_char;
|
||||
if (multiplier_char)
|
||||
*(++end_n_string) = 0;
|
||||
*(++end_n_string) = 0;
|
||||
|
||||
n_units = string_to_integer (count_lines, n_string);
|
||||
|
||||
@@ -994,47 +994,47 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
while ((c = getopt_long (argc, argv, "c:n:qv0123456789", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case PRESUME_INPUT_PIPE_OPTION:
|
||||
presume_input_pipe = true;
|
||||
break;
|
||||
{
|
||||
case PRESUME_INPUT_PIPE_OPTION:
|
||||
presume_input_pipe = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
count_lines = false;
|
||||
elide_from_end = (*optarg == '-');
|
||||
if (elide_from_end)
|
||||
++optarg;
|
||||
n_units = string_to_integer (count_lines, optarg);
|
||||
break;
|
||||
case 'c':
|
||||
count_lines = false;
|
||||
elide_from_end = (*optarg == '-');
|
||||
if (elide_from_end)
|
||||
++optarg;
|
||||
n_units = string_to_integer (count_lines, optarg);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
count_lines = true;
|
||||
elide_from_end = (*optarg == '-');
|
||||
if (elide_from_end)
|
||||
++optarg;
|
||||
n_units = string_to_integer (count_lines, optarg);
|
||||
break;
|
||||
case 'n':
|
||||
count_lines = true;
|
||||
elide_from_end = (*optarg == '-');
|
||||
if (elide_from_end)
|
||||
++optarg;
|
||||
n_units = string_to_integer (count_lines, optarg);
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
header_mode = never;
|
||||
break;
|
||||
case 'q':
|
||||
header_mode = never;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
header_mode = always;
|
||||
break;
|
||||
case 'v':
|
||||
header_mode = always;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
if (ISDIGIT (c))
|
||||
error (0, 0, _("invalid trailing option -- %c"), c);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
if (ISDIGIT (c))
|
||||
error (0, 0, _("invalid trailing option -- %c"), c);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (header_mode == always
|
||||
@@ -1045,12 +1045,12 @@ main (int argc, char **argv)
|
||||
{
|
||||
char umax_buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
error (EXIT_FAILURE, 0, _("%s: number of bytes is too large"),
|
||||
umaxtostr (n_units, umax_buf));
|
||||
umaxtostr (n_units, umax_buf));
|
||||
}
|
||||
|
||||
file_list = (optind < argc
|
||||
? (char const *const *) &argv[optind]
|
||||
: default_file_list);
|
||||
? (char const *const *) &argv[optind]
|
||||
: default_file_list);
|
||||
|
||||
if (O_BINARY && ! isatty (STDOUT_FILENO))
|
||||
xfreopen (NULL, "wb", stdout);
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -67,7 +67,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
|
||||
+5
-5
@@ -51,7 +51,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -82,7 +82,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
@@ -92,10 +92,10 @@ main (int argc, char **argv)
|
||||
/* Set hostname to operand. */
|
||||
char const *name = argv[optind];
|
||||
if (sethostname (name, strlen (name)) != 0)
|
||||
error (EXIT_FAILURE, errno, _("cannot set name to %s"), quote (name));
|
||||
error (EXIT_FAILURE, errno, _("cannot set name to %s"), quote (name));
|
||||
#else
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot set hostname; this system lacks the functionality"));
|
||||
_("cannot set hostname; this system lacks the functionality"));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
hostname = xgethostname ();
|
||||
if (hostname == NULL)
|
||||
error (EXIT_FAILURE, errno, _("cannot determine hostname"));
|
||||
error (EXIT_FAILURE, errno, _("cannot determine hostname"));
|
||||
printf ("%s\n", hostname);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... [USERNAME]\n"), program_name);
|
||||
@@ -129,39 +129,39 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "agnruGZ", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'a':
|
||||
/* Ignore -a, for compatibility with SVR4. */
|
||||
break;
|
||||
{
|
||||
case 'a':
|
||||
/* Ignore -a, for compatibility with SVR4. */
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
/* politely decline if we're not on a selinux-enabled kernel. */
|
||||
if (!selinux_enabled)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("--context (-Z) works only on an SELinux-enabled kernel"));
|
||||
/* politely decline if we're not on a selinux-enabled kernel. */
|
||||
if (!selinux_enabled)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("--context (-Z) works only on an SELinux-enabled kernel"));
|
||||
just_context = 1;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
just_group = true;
|
||||
break;
|
||||
case 'n':
|
||||
use_name = true;
|
||||
break;
|
||||
case 'r':
|
||||
use_real = true;
|
||||
break;
|
||||
case 'u':
|
||||
just_user = true;
|
||||
break;
|
||||
case 'G':
|
||||
just_group_list = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
case 'g':
|
||||
just_group = true;
|
||||
break;
|
||||
case 'n':
|
||||
use_name = true;
|
||||
break;
|
||||
case 'r':
|
||||
use_real = true;
|
||||
break;
|
||||
case 'u':
|
||||
just_user = true;
|
||||
break;
|
||||
case 'G':
|
||||
just_group_list = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (1 < argc - optind)
|
||||
@@ -172,7 +172,7 @@ main (int argc, char **argv)
|
||||
|
||||
if (argc - optind == 1 && just_context)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot print security context when user specified"));
|
||||
_("cannot print security context when user specified"));
|
||||
|
||||
/* If we are on a selinux-enabled kernel and no user is specified,
|
||||
get our context. Otherwise, leave the context variable alone -
|
||||
@@ -189,13 +189,13 @@ main (int argc, char **argv)
|
||||
|
||||
if (just_user + just_group + just_group_list == 0 && (use_real | use_name))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot print only names or real IDs in default format"));
|
||||
_("cannot print only names or real IDs in default format"));
|
||||
|
||||
if (argc - optind == 1)
|
||||
{
|
||||
struct passwd *pwd = getpwnam (argv[optind]);
|
||||
if (pwd == NULL)
|
||||
error (EXIT_FAILURE, 0, _("%s: No such user"), argv[optind]);
|
||||
error (EXIT_FAILURE, 0, _("%s: No such user"), argv[optind]);
|
||||
ruid = euid = pwd->pw_uid;
|
||||
rgid = egid = pwd->pw_gid;
|
||||
}
|
||||
@@ -214,12 +214,12 @@ main (int argc, char **argv)
|
||||
else if (just_group)
|
||||
{
|
||||
if (!print_group (use_real ? rgid : egid, use_name))
|
||||
ok = false;
|
||||
ok = false;
|
||||
}
|
||||
else if (just_group_list)
|
||||
{
|
||||
if (!print_group_list (argv[optind], ruid, rgid, egid, use_name))
|
||||
ok = false;
|
||||
ok = false;
|
||||
}
|
||||
else if (just_context)
|
||||
{
|
||||
@@ -245,11 +245,11 @@ print_user (uid_t uid)
|
||||
{
|
||||
pwd = getpwuid (uid);
|
||||
if (pwd == NULL)
|
||||
{
|
||||
error (0, 0, _("cannot find name for user ID %lu"),
|
||||
(unsigned long int) uid);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("cannot find name for user ID %lu"),
|
||||
(unsigned long int) uid);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (pwd == NULL)
|
||||
@@ -281,7 +281,7 @@ print_full_info (const char *username)
|
||||
printf (_(" euid=%lu"), (unsigned long int) euid);
|
||||
pwd = getpwuid (euid);
|
||||
if (pwd)
|
||||
printf ("(%s)", pwd->pw_name);
|
||||
printf ("(%s)", pwd->pw_name);
|
||||
}
|
||||
|
||||
if (egid != rgid)
|
||||
@@ -289,7 +289,7 @@ print_full_info (const char *username)
|
||||
printf (_(" egid=%lu"), (unsigned long int) egid);
|
||||
grp = getgrgid (egid);
|
||||
if (grp)
|
||||
printf ("(%s)", grp->gr_name);
|
||||
printf ("(%s)", grp->gr_name);
|
||||
}
|
||||
|
||||
#if HAVE_GETGROUPS
|
||||
@@ -298,32 +298,32 @@ print_full_info (const char *username)
|
||||
int i;
|
||||
|
||||
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
|
||||
&groups);
|
||||
&groups);
|
||||
if (n_groups < 0)
|
||||
{
|
||||
if (username)
|
||||
{
|
||||
error (0, errno, _("failed to get groups for user %s"),
|
||||
quote (username));
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno, _("failed to get groups for the current process"));
|
||||
}
|
||||
ok = false;
|
||||
return;
|
||||
if (username)
|
||||
{
|
||||
error (0, errno, _("failed to get groups for user %s"),
|
||||
quote (username));
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno, _("failed to get groups for the current process"));
|
||||
}
|
||||
ok = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (n_groups > 0)
|
||||
fputs (_(" groups="), stdout);
|
||||
for (i = 0; i < n_groups; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
putchar (',');
|
||||
printf ("%lu", (unsigned long int) groups[i]);
|
||||
grp = getgrgid (groups[i]);
|
||||
if (grp)
|
||||
printf ("(%s)", grp->gr_name);
|
||||
if (i > 0)
|
||||
putchar (',');
|
||||
printf ("%lu", (unsigned long int) groups[i]);
|
||||
grp = getgrgid (groups[i]);
|
||||
if (grp)
|
||||
printf ("(%s)", grp->gr_name);
|
||||
}
|
||||
free (groups);
|
||||
}
|
||||
|
||||
+202
-202
@@ -74,18 +74,18 @@ static bool use_default_selinux_context = true;
|
||||
static bool change_timestamps (struct stat const *from_sb, char const *to);
|
||||
static bool change_attributes (char const *name);
|
||||
static bool copy_file (const char *from, const char *to,
|
||||
const struct cp_options *x);
|
||||
const struct cp_options *x);
|
||||
static bool install_file_in_file_parents (char const *from, char *to,
|
||||
struct cp_options *x);
|
||||
struct cp_options *x);
|
||||
static bool install_file_in_dir (const char *from, const char *to_dir,
|
||||
const struct cp_options *x);
|
||||
const struct cp_options *x);
|
||||
static bool install_file_in_file (const char *from, const char *to,
|
||||
const struct cp_options *x);
|
||||
const struct cp_options *x);
|
||||
static void get_ids (void);
|
||||
static void strip (char const *name);
|
||||
static void announce_mkdir (char const *dir, void *options);
|
||||
static int make_ancestor (char const *dir, char const *component,
|
||||
void *options);
|
||||
void *options);
|
||||
void usage (int status);
|
||||
|
||||
/* The user name that will own the files, or NULL to make the owner
|
||||
@@ -195,7 +195,7 @@ extra_mode (mode_t input)
|
||||
/* Return true if copy of file SRC_NAME to file DEST_NAME is necessary. */
|
||||
static bool
|
||||
need_copy (const char *src_name, const char *dest_name,
|
||||
const struct cp_options *x)
|
||||
const struct cp_options *x)
|
||||
{
|
||||
struct stat src_sb, dest_sb;
|
||||
int src_fd, dest_fd;
|
||||
@@ -229,20 +229,20 @@ need_copy (const char *src_name, const char *dest_name,
|
||||
bool scontext_match;
|
||||
|
||||
if (getfilecon (src_name, &file_scontext) == -1)
|
||||
return true;
|
||||
return true;
|
||||
|
||||
if (getfilecon (dest_name, &to_scontext) == -1)
|
||||
{
|
||||
freecon (file_scontext);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
freecon (file_scontext);
|
||||
return true;
|
||||
}
|
||||
|
||||
scontext_match = STREQ (file_scontext, to_scontext);
|
||||
|
||||
freecon (file_scontext);
|
||||
freecon (to_scontext);
|
||||
if (!scontext_match)
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* compare files content */
|
||||
@@ -328,37 +328,37 @@ setdefaultfilecon (char const *file)
|
||||
if (first_call && IS_ABSOLUTE_FILE_NAME (file))
|
||||
{
|
||||
/* Calling matchpathcon_init_prefix (NULL, "/first_component/")
|
||||
is an optimization to minimize the expense of the following
|
||||
matchpathcon call. Do it only once, just before the first
|
||||
matchpathcon call. We *could* call matchpathcon_fini after
|
||||
the final matchpathcon call, but that's not necessary, since
|
||||
by then we're about to exit, and besides, the buffers it
|
||||
would free are still reachable. */
|
||||
is an optimization to minimize the expense of the following
|
||||
matchpathcon call. Do it only once, just before the first
|
||||
matchpathcon call. We *could* call matchpathcon_fini after
|
||||
the final matchpathcon call, but that's not necessary, since
|
||||
by then we're about to exit, and besides, the buffers it
|
||||
would free are still reachable. */
|
||||
char const *p0;
|
||||
char const *p = file + 1;
|
||||
while (ISSLASH (*p))
|
||||
++p;
|
||||
++p;
|
||||
|
||||
/* Record final leading slash, for when FILE starts with two or more. */
|
||||
p0 = p - 1;
|
||||
|
||||
if (*p)
|
||||
{
|
||||
char *prefix;
|
||||
do
|
||||
{
|
||||
++p;
|
||||
}
|
||||
while (*p && !ISSLASH (*p));
|
||||
{
|
||||
char *prefix;
|
||||
do
|
||||
{
|
||||
++p;
|
||||
}
|
||||
while (*p && !ISSLASH (*p));
|
||||
|
||||
prefix = malloc (p - p0 + 2);
|
||||
if (prefix)
|
||||
{
|
||||
stpcpy (stpncpy (prefix, p0, p - p0), "/");
|
||||
matchpathcon_init_prefix (NULL, prefix);
|
||||
free (prefix);
|
||||
}
|
||||
}
|
||||
prefix = malloc (p - p0 + 2);
|
||||
if (prefix)
|
||||
{
|
||||
stpcpy (stpncpy (prefix, p0, p - p0), "/");
|
||||
matchpathcon_init_prefix (NULL, prefix);
|
||||
free (prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
first_call = false;
|
||||
|
||||
@@ -368,14 +368,14 @@ setdefaultfilecon (char const *file)
|
||||
STREQ (scontext, "<<none>>"))
|
||||
{
|
||||
if (scontext != NULL)
|
||||
freecon (scontext);
|
||||
freecon (scontext);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lsetfilecon (file, scontext) < 0 && errno != ENOTSUP)
|
||||
error (0, errno,
|
||||
_("warning: %s: failed to change context to %s"),
|
||||
quotearg_colon (file), scontext);
|
||||
_("warning: %s: failed to change context to %s"),
|
||||
quotearg_colon (file), scontext);
|
||||
|
||||
freecon (scontext);
|
||||
return;
|
||||
@@ -414,11 +414,11 @@ static int
|
||||
process_dir (char *dir, struct savewd *wd, void *options)
|
||||
{
|
||||
return (make_dir_parents (dir, wd,
|
||||
make_ancestor, options,
|
||||
dir_mode, announce_mkdir,
|
||||
dir_mode_bits, owner_id, group_id, false)
|
||||
? EXIT_SUCCESS
|
||||
: EXIT_FAILURE);
|
||||
make_ancestor, options,
|
||||
dir_mode, announce_mkdir,
|
||||
dir_mode_bits, owner_id, group_id, false)
|
||||
? EXIT_SUCCESS
|
||||
: EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -462,131 +462,131 @@ main (int argc, char **argv)
|
||||
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z:", long_options,
|
||||
NULL)) != -1)
|
||||
NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'b':
|
||||
make_backups = true;
|
||||
if (optarg)
|
||||
version_control_string = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
break;
|
||||
case 'C':
|
||||
copy_only_if_needed = true;
|
||||
break;
|
||||
case 's':
|
||||
strip_files = true;
|
||||
{
|
||||
case 'b':
|
||||
make_backups = true;
|
||||
if (optarg)
|
||||
version_control_string = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
break;
|
||||
case 'C':
|
||||
copy_only_if_needed = true;
|
||||
break;
|
||||
case 's':
|
||||
strip_files = true;
|
||||
#ifdef SIGCHLD
|
||||
/* System V fork+wait does not work if SIGCHLD is ignored. */
|
||||
signal (SIGCHLD, SIG_DFL);
|
||||
/* System V fork+wait does not work if SIGCHLD is ignored. */
|
||||
signal (SIGCHLD, SIG_DFL);
|
||||
#endif
|
||||
break;
|
||||
case STRIP_PROGRAM_OPTION:
|
||||
strip_program = xstrdup (optarg);
|
||||
strip_program_specified = true;
|
||||
break;
|
||||
case 'd':
|
||||
dir_arg = true;
|
||||
break;
|
||||
case 'D':
|
||||
mkdir_and_install = true;
|
||||
break;
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
case 'g':
|
||||
group_name = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
owner_name = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
x.preserve_timestamps = true;
|
||||
break;
|
||||
case 'S':
|
||||
make_backups = true;
|
||||
backup_suffix_string = optarg;
|
||||
break;
|
||||
case 't':
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("multiple target directories specified"));
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat (optarg, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (optarg));
|
||||
}
|
||||
target_directory = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
no_target_directory = true;
|
||||
break;
|
||||
break;
|
||||
case STRIP_PROGRAM_OPTION:
|
||||
strip_program = xstrdup (optarg);
|
||||
strip_program_specified = true;
|
||||
break;
|
||||
case 'd':
|
||||
dir_arg = true;
|
||||
break;
|
||||
case 'D':
|
||||
mkdir_and_install = true;
|
||||
break;
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
case 'g':
|
||||
group_name = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
owner_name = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
x.preserve_timestamps = true;
|
||||
break;
|
||||
case 'S':
|
||||
make_backups = true;
|
||||
backup_suffix_string = optarg;
|
||||
break;
|
||||
case 't':
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("multiple target directories specified"));
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat (optarg, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (optarg));
|
||||
}
|
||||
target_directory = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
no_target_directory = true;
|
||||
break;
|
||||
|
||||
case PRESERVE_CONTEXT_OPTION_DEPRECATED:
|
||||
error (0, 0, _("WARNING: --preserve_context is deprecated; "
|
||||
"use --preserve-context instead"));
|
||||
/* fall through */
|
||||
case PRESERVE_CONTEXT_OPTION:
|
||||
if ( ! selinux_enabled)
|
||||
{
|
||||
error (0, 0, _("WARNING: ignoring --preserve-context; "
|
||||
"this kernel is not SELinux-enabled"));
|
||||
break;
|
||||
}
|
||||
x.preserve_security_context = true;
|
||||
use_default_selinux_context = false;
|
||||
break;
|
||||
case 'Z':
|
||||
if ( ! selinux_enabled)
|
||||
{
|
||||
error (0, 0, _("WARNING: ignoring --context (-Z); "
|
||||
"this kernel is not SELinux-enabled"));
|
||||
break;
|
||||
}
|
||||
scontext = optarg;
|
||||
use_default_selinux_context = false;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
case PRESERVE_CONTEXT_OPTION_DEPRECATED:
|
||||
error (0, 0, _("WARNING: --preserve_context is deprecated; "
|
||||
"use --preserve-context instead"));
|
||||
/* fall through */
|
||||
case PRESERVE_CONTEXT_OPTION:
|
||||
if ( ! selinux_enabled)
|
||||
{
|
||||
error (0, 0, _("WARNING: ignoring --preserve-context; "
|
||||
"this kernel is not SELinux-enabled"));
|
||||
break;
|
||||
}
|
||||
x.preserve_security_context = true;
|
||||
use_default_selinux_context = false;
|
||||
break;
|
||||
case 'Z':
|
||||
if ( ! selinux_enabled)
|
||||
{
|
||||
error (0, 0, _("WARNING: ignoring --context (-Z); "
|
||||
"this kernel is not SELinux-enabled"));
|
||||
break;
|
||||
}
|
||||
scontext = optarg;
|
||||
use_default_selinux_context = false;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for invalid combinations of arguments. */
|
||||
if (dir_arg & strip_files)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("the strip option may not be used when installing a directory"));
|
||||
_("the strip option may not be used when installing a directory"));
|
||||
if (dir_arg && target_directory)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("target directory not allowed when installing a directory"));
|
||||
_("target directory not allowed when installing a directory"));
|
||||
|
||||
if (x.preserve_security_context && scontext != NULL)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot force target context to %s and preserve it"),
|
||||
quote (scontext));
|
||||
_("cannot force target context to %s and preserve it"),
|
||||
quote (scontext));
|
||||
|
||||
if (backup_suffix_string)
|
||||
simple_backup_suffix = xstrdup (backup_suffix_string);
|
||||
|
||||
x.backup_type = (make_backups
|
||||
? xget_version (_("backup type"),
|
||||
version_control_string)
|
||||
: no_backups);
|
||||
? xget_version (_("backup type"),
|
||||
version_control_string)
|
||||
: no_backups);
|
||||
|
||||
if (scontext && setfscreatecon (scontext) < 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
|
||||
n_files = argc - optind;
|
||||
file = argv + optind;
|
||||
@@ -594,39 +594,39 @@ main (int argc, char **argv)
|
||||
if (n_files <= ! (dir_arg || target_directory))
|
||||
{
|
||||
if (n_files <= 0)
|
||||
error (0, 0, _("missing file operand"));
|
||||
error (0, 0, _("missing file operand"));
|
||||
else
|
||||
error (0, 0, _("missing destination file operand after %s"),
|
||||
quote (file[0]));
|
||||
error (0, 0, _("missing destination file operand after %s"),
|
||||
quote (file[0]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (no_target_directory)
|
||||
{
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot combine --target-directory (-t) "
|
||||
"and --no-target-directory (-T)"));
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot combine --target-directory (-t) "
|
||||
"and --no-target-directory (-T)"));
|
||||
if (2 < n_files)
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (file[2]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (file[2]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if (! (dir_arg || target_directory))
|
||||
{
|
||||
if (2 <= n_files && target_directory_operand (file[n_files - 1]))
|
||||
target_directory = file[--n_files];
|
||||
target_directory = file[--n_files];
|
||||
else if (2 < n_files)
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (file[n_files - 1]));
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (file[n_files - 1]));
|
||||
}
|
||||
|
||||
if (specified_mode)
|
||||
{
|
||||
struct mode_change *change = mode_compile (specified_mode);
|
||||
if (!change)
|
||||
error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode));
|
||||
error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode));
|
||||
mode = mode_adjust (0, false, 0, change, NULL);
|
||||
dir_mode = mode_adjust (0, true, 0, change, &dir_mode_bits);
|
||||
free (change);
|
||||
@@ -634,25 +634,25 @@ main (int argc, char **argv)
|
||||
|
||||
if (strip_program_specified && !strip_files)
|
||||
error (0, 0, _("WARNING: ignoring --strip-program option as -s option was "
|
||||
"not specified"));
|
||||
"not specified"));
|
||||
|
||||
if (copy_only_if_needed && x.preserve_timestamps)
|
||||
{
|
||||
error (0, 0, _("options --compare (-C) and --preserve-timestamps are "
|
||||
"mutually exclusive"));
|
||||
"mutually exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (copy_only_if_needed && strip_files)
|
||||
{
|
||||
error (0, 0, _("options --compare (-C) and --strip are mutually "
|
||||
"exclusive"));
|
||||
"exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (copy_only_if_needed && extra_mode (mode))
|
||||
error (0, 0, _("the --compare (-C) option is ignored when you"
|
||||
" specify a mode with non-permission bits"));
|
||||
" specify a mode with non-permission bits"));
|
||||
|
||||
get_ids ();
|
||||
|
||||
@@ -661,24 +661,24 @@ main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
/* FIXME: it's a little gross that this initialization is
|
||||
required by copy.c::copy. */
|
||||
required by copy.c::copy. */
|
||||
hash_init ();
|
||||
|
||||
if (!target_directory)
|
||||
{
|
||||
if (! (mkdir_and_install
|
||||
? install_file_in_file_parents (file[0], file[1], &x)
|
||||
: install_file_in_file (file[0], file[1], &x)))
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
? install_file_in_file_parents (file[0], file[1], &x)
|
||||
: install_file_in_file (file[0], file[1], &x)))
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
dest_info_init (&x);
|
||||
for (i = 0; i < n_files; i++)
|
||||
if (! install_file_in_dir (file[i], target_directory, &x))
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
{
|
||||
int i;
|
||||
dest_info_init (&x);
|
||||
for (i = 0; i < n_files; i++)
|
||||
if (! install_file_in_dir (file[i], target_directory, &x))
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
exit (exit_status);
|
||||
@@ -689,7 +689,7 @@ main (int argc, char **argv)
|
||||
|
||||
static bool
|
||||
install_file_in_file_parents (char const *from, char *to,
|
||||
struct cp_options *x)
|
||||
struct cp_options *x)
|
||||
{
|
||||
bool save_working_directory =
|
||||
! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to));
|
||||
@@ -712,12 +712,12 @@ install_file_in_file_parents (char const *from, char *to,
|
||||
int restore_errno = errno;
|
||||
savewd_finish (&wd);
|
||||
if (EXIT_SUCCESS < restore_result)
|
||||
return false;
|
||||
return false;
|
||||
if (restore_result < 0 && status == EXIT_SUCCESS)
|
||||
{
|
||||
error (0, restore_errno, _("cannot create directory %s"), to);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, restore_errno, _("cannot create directory %s"), to);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return (status == EXIT_SUCCESS && install_file_in_file (from, to, x));
|
||||
@@ -729,7 +729,7 @@ install_file_in_file_parents (char const *from, char *to,
|
||||
|
||||
static bool
|
||||
install_file_in_file (const char *from, const char *to,
|
||||
const struct cp_options *x)
|
||||
const struct cp_options *x)
|
||||
{
|
||||
struct stat from_sb;
|
||||
if (x->preserve_timestamps && stat (from, &from_sb) != 0)
|
||||
@@ -753,7 +753,7 @@ install_file_in_file (const char *from, const char *to,
|
||||
|
||||
static bool
|
||||
install_file_in_dir (const char *from, const char *to_dir,
|
||||
const struct cp_options *x)
|
||||
const struct cp_options *x)
|
||||
{
|
||||
const char *from_base = last_component (from);
|
||||
char *to = file_name_concat (to_dir, from_base, NULL);
|
||||
@@ -856,9 +856,9 @@ strip (char const *name)
|
||||
break;
|
||||
default: /* Parent. */
|
||||
if (waitpid (pid, &status, 0) < 0)
|
||||
error (EXIT_FAILURE, errno, _("waiting for strip"));
|
||||
error (EXIT_FAILURE, errno, _("waiting for strip"));
|
||||
else if (! WIFEXITED (status) || WEXITSTATUS (status))
|
||||
error (EXIT_FAILURE, 0, _("strip process terminated abnormally"));
|
||||
error (EXIT_FAILURE, 0, _("strip process terminated abnormally"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -875,15 +875,15 @@ get_ids (void)
|
||||
{
|
||||
pw = getpwnam (owner_name);
|
||||
if (pw == NULL)
|
||||
{
|
||||
unsigned long int tmp;
|
||||
if (xstrtoul (owner_name, NULL, 0, &tmp, NULL) != LONGINT_OK
|
||||
|| UID_T_MAX < tmp)
|
||||
error (EXIT_FAILURE, 0, _("invalid user %s"), quote (owner_name));
|
||||
owner_id = tmp;
|
||||
}
|
||||
{
|
||||
unsigned long int tmp;
|
||||
if (xstrtoul (owner_name, NULL, 0, &tmp, NULL) != LONGINT_OK
|
||||
|| UID_T_MAX < tmp)
|
||||
error (EXIT_FAILURE, 0, _("invalid user %s"), quote (owner_name));
|
||||
owner_id = tmp;
|
||||
}
|
||||
else
|
||||
owner_id = pw->pw_uid;
|
||||
owner_id = pw->pw_uid;
|
||||
endpwent ();
|
||||
}
|
||||
else
|
||||
@@ -893,15 +893,15 @@ get_ids (void)
|
||||
{
|
||||
gr = getgrnam (group_name);
|
||||
if (gr == NULL)
|
||||
{
|
||||
unsigned long int tmp;
|
||||
if (xstrtoul (group_name, NULL, 0, &tmp, NULL) != LONGINT_OK
|
||||
|| GID_T_MAX < tmp)
|
||||
error (EXIT_FAILURE, 0, _("invalid group %s"), quote (group_name));
|
||||
group_id = tmp;
|
||||
}
|
||||
{
|
||||
unsigned long int tmp;
|
||||
if (xstrtoul (group_name, NULL, 0, &tmp, NULL) != LONGINT_OK
|
||||
|| GID_T_MAX < tmp)
|
||||
error (EXIT_FAILURE, 0, _("invalid group %s"), quote (group_name));
|
||||
group_id = tmp;
|
||||
}
|
||||
else
|
||||
group_id = gr->gr_gid;
|
||||
group_id = gr->gr_gid;
|
||||
endgrent ();
|
||||
}
|
||||
else
|
||||
@@ -934,7 +934,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -943,7 +943,7 @@ Usage: %s [OPTION]... [-T] SOURCE DEST\n\
|
||||
or: %s [OPTION]... -t DIRECTORY SOURCE...\n\
|
||||
or: %s [OPTION]... -d DIRECTORY...\n\
|
||||
"),
|
||||
program_name, program_name, program_name, program_name);
|
||||
program_name, program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
\n\
|
||||
This install program copies files (often just compiled) into destination\n\
|
||||
|
||||
+273
-273
@@ -161,13 +161,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... FILE1 FILE2\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
For each pair of input lines with identical join fields, write a line to\n\
|
||||
standard output. The default join field is the first, delimited\n\
|
||||
@@ -242,26 +242,26 @@ xfields (struct line *line)
|
||||
{
|
||||
char *sep;
|
||||
for (; (sep = memchr (ptr, tab, lim - ptr)) != NULL; ptr = sep + 1)
|
||||
extract_field (line, ptr, sep - ptr);
|
||||
extract_field (line, ptr, sep - ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Skip leading blanks before the first field. */
|
||||
while (isblank (to_uchar (*ptr)))
|
||||
if (++ptr == lim)
|
||||
return;
|
||||
if (++ptr == lim)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
char *sep;
|
||||
for (sep = ptr + 1; sep != lim && ! isblank (to_uchar (*sep)); sep++)
|
||||
continue;
|
||||
extract_field (line, ptr, sep - ptr);
|
||||
if (sep == lim)
|
||||
return;
|
||||
for (ptr = sep + 1; ptr != lim && isblank (to_uchar (*ptr)); ptr++)
|
||||
continue;
|
||||
}
|
||||
{
|
||||
char *sep;
|
||||
for (sep = ptr + 1; sep != lim && ! isblank (to_uchar (*sep)); sep++)
|
||||
continue;
|
||||
extract_field (line, ptr, sep - ptr);
|
||||
if (sep == lim)
|
||||
return;
|
||||
for (ptr = sep + 1; ptr != lim && isblank (to_uchar (*ptr)); ptr++)
|
||||
continue;
|
||||
}
|
||||
while (ptr != lim);
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ freeline (struct line *line)
|
||||
|
||||
static int
|
||||
keycmp (struct line const *line1, struct line const *line2,
|
||||
size_t jf_1, size_t jf_2)
|
||||
size_t jf_1, size_t jf_2)
|
||||
{
|
||||
/* Start of field to compare in each file. */
|
||||
char *beg1;
|
||||
@@ -329,7 +329,7 @@ keycmp (struct line const *line1, struct line const *line2,
|
||||
else
|
||||
{
|
||||
if (hard_LC_COLLATE)
|
||||
return xmemcoll (beg1, len1, beg2, len2);
|
||||
return xmemcoll (beg1, len1, beg2, len2);
|
||||
diff = memcmp (beg1, beg2, MIN (len1, len2));
|
||||
}
|
||||
|
||||
@@ -351,26 +351,26 @@ keycmp (struct line const *line1, struct line const *line2,
|
||||
|
||||
static void
|
||||
check_order (const struct line *prev,
|
||||
const struct line *current,
|
||||
int whatfile)
|
||||
const struct line *current,
|
||||
int whatfile)
|
||||
{
|
||||
if (check_input_order != CHECK_ORDER_DISABLED
|
||||
&& ((check_input_order == CHECK_ORDER_ENABLED) || seen_unpairable))
|
||||
{
|
||||
if (!issued_disorder_warning[whatfile-1])
|
||||
{
|
||||
size_t join_field = whatfile == 1 ? join_field_1 : join_field_2;
|
||||
if (keycmp (prev, current, join_field, join_field) > 0)
|
||||
{
|
||||
error ((check_input_order == CHECK_ORDER_ENABLED
|
||||
? EXIT_FAILURE : 0),
|
||||
0, _("file %d is not in sorted order"), whatfile);
|
||||
{
|
||||
size_t join_field = whatfile == 1 ? join_field_1 : join_field_2;
|
||||
if (keycmp (prev, current, join_field, join_field) > 0)
|
||||
{
|
||||
error ((check_input_order == CHECK_ORDER_ENABLED
|
||||
? EXIT_FAILURE : 0),
|
||||
0, _("file %d is not in sorted order"), whatfile);
|
||||
|
||||
/* If we get to here, the message was just a warning, but we
|
||||
want only to issue it once. */
|
||||
issued_disorder_warning[whatfile-1] = true;
|
||||
}
|
||||
}
|
||||
/* If we get to here, the message was just a warning, but we
|
||||
want only to issue it once. */
|
||||
issued_disorder_warning[whatfile-1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ get_line (FILE *fp, struct line **linep, int which)
|
||||
if (! readlinebuffer (&line->buf, fp))
|
||||
{
|
||||
if (ferror (fp))
|
||||
error (EXIT_FAILURE, errno, _("read error"));
|
||||
error (EXIT_FAILURE, errno, _("read error"));
|
||||
freeline (line);
|
||||
return false;
|
||||
}
|
||||
@@ -433,10 +433,10 @@ free_spareline (void)
|
||||
for (i = 0; i < ARRAY_CARDINALITY (spareline); i++)
|
||||
{
|
||||
if (spareline[i])
|
||||
{
|
||||
freeline (spareline[i]);
|
||||
free (spareline[i]);
|
||||
}
|
||||
{
|
||||
freeline (spareline[i]);
|
||||
free (spareline[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ getseq (FILE *fp, struct seq *seq, int whichfile)
|
||||
size_t i;
|
||||
seq->lines = X2NREALLOC (seq->lines, &seq->alloc);
|
||||
for (i = seq->count; i < seq->alloc; i++)
|
||||
seq->lines[i] = NULL;
|
||||
seq->lines[i] = NULL;
|
||||
}
|
||||
|
||||
if (get_line (fp, &seq->lines[seq->count], whichfile))
|
||||
@@ -487,9 +487,9 @@ delseq (struct seq *seq)
|
||||
for (i = 0; i < seq->alloc; i++)
|
||||
if (seq->lines[i])
|
||||
{
|
||||
if (seq->lines[i]->buf.buffer)
|
||||
freeline (seq->lines[i]);
|
||||
free (seq->lines[i]);
|
||||
if (seq->lines[i]->buf.buffer)
|
||||
freeline (seq->lines[i]);
|
||||
free (seq->lines[i]);
|
||||
}
|
||||
free (seq->lines);
|
||||
}
|
||||
@@ -507,9 +507,9 @@ prfield (size_t n, struct line const *line)
|
||||
{
|
||||
len = line->fields[n].len;
|
||||
if (len)
|
||||
fwrite (line->fields[n].beg, 1, len, stdout);
|
||||
fwrite (line->fields[n].beg, 1, len, stdout);
|
||||
else if (empty_filler)
|
||||
fputs (empty_filler, stdout);
|
||||
fputs (empty_filler, stdout);
|
||||
}
|
||||
else if (empty_filler)
|
||||
fputs (empty_filler, stdout);
|
||||
@@ -530,34 +530,34 @@ prjoin (struct line const *line1, struct line const *line2)
|
||||
|
||||
o = outlist;
|
||||
while (1)
|
||||
{
|
||||
size_t field;
|
||||
struct line const *line;
|
||||
{
|
||||
size_t field;
|
||||
struct line const *line;
|
||||
|
||||
if (o->file == 0)
|
||||
{
|
||||
if (line1 == &uni_blank)
|
||||
{
|
||||
line = line2;
|
||||
field = join_field_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
line = line1;
|
||||
field = join_field_1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line = (o->file == 1 ? line1 : line2);
|
||||
field = o->field;
|
||||
}
|
||||
prfield (field, line);
|
||||
o = o->next;
|
||||
if (o == NULL)
|
||||
break;
|
||||
putchar (output_separator);
|
||||
}
|
||||
if (o->file == 0)
|
||||
{
|
||||
if (line1 == &uni_blank)
|
||||
{
|
||||
line = line2;
|
||||
field = join_field_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
line = line1;
|
||||
field = join_field_1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line = (o->file == 1 ? line1 : line2);
|
||||
field = o->field;
|
||||
}
|
||||
prfield (field, line);
|
||||
o = o->next;
|
||||
if (o == NULL)
|
||||
break;
|
||||
putchar (output_separator);
|
||||
}
|
||||
putchar ('\n');
|
||||
}
|
||||
else
|
||||
@@ -565,34 +565,34 @@ prjoin (struct line const *line1, struct line const *line2)
|
||||
size_t i;
|
||||
|
||||
if (line1 == &uni_blank)
|
||||
{
|
||||
struct line const *t;
|
||||
t = line1;
|
||||
line1 = line2;
|
||||
line2 = t;
|
||||
}
|
||||
{
|
||||
struct line const *t;
|
||||
t = line1;
|
||||
line1 = line2;
|
||||
line2 = t;
|
||||
}
|
||||
prfield (join_field_1, line1);
|
||||
for (i = 0; i < join_field_1 && i < line1->nfields; ++i)
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line1);
|
||||
}
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line1);
|
||||
}
|
||||
for (i = join_field_1 + 1; i < line1->nfields; ++i)
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line1);
|
||||
}
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line1);
|
||||
}
|
||||
|
||||
for (i = 0; i < join_field_2 && i < line2->nfields; ++i)
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line2);
|
||||
}
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line2);
|
||||
}
|
||||
for (i = join_field_2 + 1; i < line2->nfields; ++i)
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line2);
|
||||
}
|
||||
{
|
||||
putchar (output_separator);
|
||||
prfield (i, line2);
|
||||
}
|
||||
putchar ('\n');
|
||||
}
|
||||
}
|
||||
@@ -619,75 +619,75 @@ join (FILE *fp1, FILE *fp2)
|
||||
{
|
||||
size_t i;
|
||||
diff = keycmp (seq1.lines[0], seq2.lines[0],
|
||||
join_field_1, join_field_2);
|
||||
join_field_1, join_field_2);
|
||||
if (diff < 0)
|
||||
{
|
||||
if (print_unpairables_1)
|
||||
prjoin (seq1.lines[0], &uni_blank);
|
||||
advance_seq (fp1, &seq1, true, 1);
|
||||
seen_unpairable = true;
|
||||
continue;
|
||||
}
|
||||
{
|
||||
if (print_unpairables_1)
|
||||
prjoin (seq1.lines[0], &uni_blank);
|
||||
advance_seq (fp1, &seq1, true, 1);
|
||||
seen_unpairable = true;
|
||||
continue;
|
||||
}
|
||||
if (diff > 0)
|
||||
{
|
||||
if (print_unpairables_2)
|
||||
prjoin (&uni_blank, seq2.lines[0]);
|
||||
advance_seq (fp2, &seq2, true, 2);
|
||||
seen_unpairable = true;
|
||||
continue;
|
||||
}
|
||||
{
|
||||
if (print_unpairables_2)
|
||||
prjoin (&uni_blank, seq2.lines[0]);
|
||||
advance_seq (fp2, &seq2, true, 2);
|
||||
seen_unpairable = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Keep reading lines from file1 as long as they continue to
|
||||
match the current line from file2. */
|
||||
eof1 = false;
|
||||
do
|
||||
if (!advance_seq (fp1, &seq1, false, 1))
|
||||
{
|
||||
eof1 = true;
|
||||
++seq1.count;
|
||||
break;
|
||||
}
|
||||
if (!advance_seq (fp1, &seq1, false, 1))
|
||||
{
|
||||
eof1 = true;
|
||||
++seq1.count;
|
||||
break;
|
||||
}
|
||||
while (!keycmp (seq1.lines[seq1.count - 1], seq2.lines[0],
|
||||
join_field_1, join_field_2));
|
||||
join_field_1, join_field_2));
|
||||
|
||||
/* Keep reading lines from file2 as long as they continue to
|
||||
match the current line from file1. */
|
||||
eof2 = false;
|
||||
do
|
||||
if (!advance_seq (fp2, &seq2, false, 2))
|
||||
{
|
||||
eof2 = true;
|
||||
++seq2.count;
|
||||
break;
|
||||
}
|
||||
if (!advance_seq (fp2, &seq2, false, 2))
|
||||
{
|
||||
eof2 = true;
|
||||
++seq2.count;
|
||||
break;
|
||||
}
|
||||
while (!keycmp (seq1.lines[0], seq2.lines[seq2.count - 1],
|
||||
join_field_1, join_field_2));
|
||||
join_field_1, join_field_2));
|
||||
|
||||
if (print_pairables)
|
||||
{
|
||||
for (i = 0; i < seq1.count - 1; ++i)
|
||||
{
|
||||
size_t j;
|
||||
for (j = 0; j < seq2.count - 1; ++j)
|
||||
prjoin (seq1.lines[i], seq2.lines[j]);
|
||||
}
|
||||
}
|
||||
{
|
||||
for (i = 0; i < seq1.count - 1; ++i)
|
||||
{
|
||||
size_t j;
|
||||
for (j = 0; j < seq2.count - 1; ++j)
|
||||
prjoin (seq1.lines[i], seq2.lines[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!eof1)
|
||||
{
|
||||
SWAPLINES (seq1.lines[0], seq1.lines[seq1.count - 1]);
|
||||
seq1.count = 1;
|
||||
}
|
||||
{
|
||||
SWAPLINES (seq1.lines[0], seq1.lines[seq1.count - 1]);
|
||||
seq1.count = 1;
|
||||
}
|
||||
else
|
||||
seq1.count = 0;
|
||||
seq1.count = 0;
|
||||
|
||||
if (!eof2)
|
||||
{
|
||||
SWAPLINES (seq2.lines[0], seq2.lines[seq2.count - 1]);
|
||||
seq2.count = 1;
|
||||
}
|
||||
{
|
||||
SWAPLINES (seq2.lines[0], seq2.lines[seq2.count - 1]);
|
||||
seq2.count = 1;
|
||||
}
|
||||
else
|
||||
seq2.count = 0;
|
||||
seq2.count = 0;
|
||||
}
|
||||
|
||||
/* If the user did not specify --check-order, and the we read the
|
||||
@@ -703,29 +703,29 @@ join (FILE *fp1, FILE *fp2)
|
||||
if ((print_unpairables_1 || checktail) && seq1.count)
|
||||
{
|
||||
if (print_unpairables_1)
|
||||
prjoin (seq1.lines[0], &uni_blank);
|
||||
prjoin (seq1.lines[0], &uni_blank);
|
||||
seen_unpairable = true;
|
||||
while (get_line (fp1, linep, 1))
|
||||
{
|
||||
if (print_unpairables_1)
|
||||
prjoin (*linep, &uni_blank);
|
||||
if (issued_disorder_warning[0] && !print_unpairables_1)
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (print_unpairables_1)
|
||||
prjoin (*linep, &uni_blank);
|
||||
if (issued_disorder_warning[0] && !print_unpairables_1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((print_unpairables_2 || checktail) && seq2.count)
|
||||
{
|
||||
if (print_unpairables_2)
|
||||
prjoin (&uni_blank, seq2.lines[0]);
|
||||
prjoin (&uni_blank, seq2.lines[0]);
|
||||
seen_unpairable = true;
|
||||
while (get_line (fp2, linep, 2))
|
||||
{
|
||||
if (print_unpairables_2)
|
||||
prjoin (&uni_blank, *linep);
|
||||
if (issued_disorder_warning[1] && !print_unpairables_2)
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (print_unpairables_2)
|
||||
prjoin (&uni_blank, *linep);
|
||||
if (issued_disorder_warning[1] && !print_unpairables_2)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free (*linep);
|
||||
@@ -792,9 +792,9 @@ decode_field_spec (const char *s, int *file_index, size_t *field_index)
|
||||
case '0':
|
||||
if (s[1])
|
||||
{
|
||||
/* `0' must be all alone -- no `.FIELD'. */
|
||||
error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
|
||||
}
|
||||
/* `0' must be all alone -- no `.FIELD'. */
|
||||
error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
|
||||
}
|
||||
*file_index = 0;
|
||||
*field_index = 0;
|
||||
break;
|
||||
@@ -802,18 +802,18 @@ decode_field_spec (const char *s, int *file_index, size_t *field_index)
|
||||
case '1':
|
||||
case '2':
|
||||
if (s[1] != '.')
|
||||
error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
|
||||
error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
|
||||
*file_index = s[0] - '0';
|
||||
*field_index = string_to_join_field (s + 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid file number in field spec: %s"), quote (s));
|
||||
_("invalid file number in field spec: %s"), quote (s));
|
||||
|
||||
/* Tell gcc -W -Wall that we can't get beyond this point.
|
||||
This avoids a warning (otherwise legit) that the caller's copies
|
||||
of *file_index and *field_index might be used uninitialized. */
|
||||
This avoids a warning (otherwise legit) that the caller's copies
|
||||
of *file_index and *field_index might be used uninitialized. */
|
||||
abort ();
|
||||
|
||||
break;
|
||||
@@ -853,7 +853,7 @@ set_join_field (size_t *var, size_t val)
|
||||
unsigned long int var1 = *var + 1;
|
||||
unsigned long int val1 = val + 1;
|
||||
error (EXIT_FAILURE, 0, _("incompatible join fields %lu, %lu"),
|
||||
var1, val1);
|
||||
var1, val1);
|
||||
}
|
||||
*var = val;
|
||||
}
|
||||
@@ -881,8 +881,8 @@ enum operand_status
|
||||
|
||||
static void
|
||||
add_file_name (char *name, char *names[2],
|
||||
int operand_status[2], int joption_count[2], int *nfiles,
|
||||
int *prev_optc_status, int *optc_status)
|
||||
int operand_status[2], int joption_count[2], int *nfiles,
|
||||
int *prev_optc_status, int *optc_status)
|
||||
{
|
||||
int n = *nfiles;
|
||||
|
||||
@@ -891,30 +891,30 @@ add_file_name (char *name, char *names[2],
|
||||
bool op0 = (operand_status[0] == MUST_BE_OPERAND);
|
||||
char *arg = names[op0];
|
||||
switch (operand_status[op0])
|
||||
{
|
||||
case MUST_BE_OPERAND:
|
||||
error (0, 0, _("extra operand %s"), quote (name));
|
||||
usage (EXIT_FAILURE);
|
||||
{
|
||||
case MUST_BE_OPERAND:
|
||||
error (0, 0, _("extra operand %s"), quote (name));
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
case MIGHT_BE_J1_ARG:
|
||||
joption_count[0]--;
|
||||
set_join_field (&join_field_1, string_to_join_field (arg));
|
||||
break;
|
||||
case MIGHT_BE_J1_ARG:
|
||||
joption_count[0]--;
|
||||
set_join_field (&join_field_1, string_to_join_field (arg));
|
||||
break;
|
||||
|
||||
case MIGHT_BE_J2_ARG:
|
||||
joption_count[1]--;
|
||||
set_join_field (&join_field_2, string_to_join_field (arg));
|
||||
break;
|
||||
case MIGHT_BE_J2_ARG:
|
||||
joption_count[1]--;
|
||||
set_join_field (&join_field_2, string_to_join_field (arg));
|
||||
break;
|
||||
|
||||
case MIGHT_BE_O_ARG:
|
||||
add_field_list (arg);
|
||||
break;
|
||||
}
|
||||
case MIGHT_BE_O_ARG:
|
||||
add_field_list (arg);
|
||||
break;
|
||||
}
|
||||
if (!op0)
|
||||
{
|
||||
operand_status[0] = operand_status[1];
|
||||
names[0] = names[1];
|
||||
}
|
||||
{
|
||||
operand_status[0] = operand_status[1];
|
||||
names[0] = names[1];
|
||||
}
|
||||
n = 1;
|
||||
}
|
||||
|
||||
@@ -954,110 +954,110 @@ main (int argc, char **argv)
|
||||
check_input_order = CHECK_ORDER_DEFAULT;
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "-a:e:i1:2:j:o:t:v:",
|
||||
longopts, NULL))
|
||||
!= -1)
|
||||
longopts, NULL))
|
||||
!= -1)
|
||||
{
|
||||
optc_status = MUST_BE_OPERAND;
|
||||
|
||||
switch (optc)
|
||||
{
|
||||
case 'v':
|
||||
print_pairables = false;
|
||||
/* Fall through. */
|
||||
{
|
||||
case 'v':
|
||||
print_pairables = false;
|
||||
/* Fall through. */
|
||||
|
||||
case 'a':
|
||||
{
|
||||
unsigned long int val;
|
||||
if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
|
||||
|| (val != 1 && val != 2))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid field number: %s"), quote (optarg));
|
||||
if (val == 1)
|
||||
print_unpairables_1 = true;
|
||||
else
|
||||
print_unpairables_2 = true;
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
{
|
||||
unsigned long int val;
|
||||
if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
|
||||
|| (val != 1 && val != 2))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid field number: %s"), quote (optarg));
|
||||
if (val == 1)
|
||||
print_unpairables_1 = true;
|
||||
else
|
||||
print_unpairables_2 = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
if (empty_filler && ! STREQ (empty_filler, optarg))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("conflicting empty-field replacement strings"));
|
||||
empty_filler = optarg;
|
||||
break;
|
||||
case 'e':
|
||||
if (empty_filler && ! STREQ (empty_filler, optarg))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("conflicting empty-field replacement strings"));
|
||||
empty_filler = optarg;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
ignore_case = true;
|
||||
break;
|
||||
case 'i':
|
||||
ignore_case = true;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
set_join_field (&join_field_1, string_to_join_field (optarg));
|
||||
break;
|
||||
case '1':
|
||||
set_join_field (&join_field_1, string_to_join_field (optarg));
|
||||
break;
|
||||
|
||||
case '2':
|
||||
set_join_field (&join_field_2, string_to_join_field (optarg));
|
||||
break;
|
||||
case '2':
|
||||
set_join_field (&join_field_2, string_to_join_field (optarg));
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
if ((optarg[0] == '1' || optarg[0] == '2') && !optarg[1]
|
||||
&& optarg == argv[optind - 1] + 2)
|
||||
{
|
||||
/* The argument was either "-j1" or "-j2". */
|
||||
bool is_j2 = (optarg[0] == '2');
|
||||
joption_count[is_j2]++;
|
||||
optc_status = MIGHT_BE_J1_ARG + is_j2;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_join_field (&join_field_1, string_to_join_field (optarg));
|
||||
set_join_field (&join_field_2, join_field_1);
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
if ((optarg[0] == '1' || optarg[0] == '2') && !optarg[1]
|
||||
&& optarg == argv[optind - 1] + 2)
|
||||
{
|
||||
/* The argument was either "-j1" or "-j2". */
|
||||
bool is_j2 = (optarg[0] == '2');
|
||||
joption_count[is_j2]++;
|
||||
optc_status = MIGHT_BE_J1_ARG + is_j2;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_join_field (&join_field_1, string_to_join_field (optarg));
|
||||
set_join_field (&join_field_2, join_field_1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
add_field_list (optarg);
|
||||
optc_status = MIGHT_BE_O_ARG;
|
||||
break;
|
||||
case 'o':
|
||||
add_field_list (optarg);
|
||||
optc_status = MIGHT_BE_O_ARG;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
{
|
||||
unsigned char newtab = optarg[0];
|
||||
if (! newtab)
|
||||
error (EXIT_FAILURE, 0, _("empty tab"));
|
||||
if (optarg[1])
|
||||
{
|
||||
if (STREQ (optarg, "\\0"))
|
||||
newtab = '\0';
|
||||
else
|
||||
error (EXIT_FAILURE, 0, _("multi-character tab %s"),
|
||||
quote (optarg));
|
||||
}
|
||||
if (0 <= tab && tab != newtab)
|
||||
error (EXIT_FAILURE, 0, _("incompatible tabs"));
|
||||
tab = newtab;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
unsigned char newtab = optarg[0];
|
||||
if (! newtab)
|
||||
error (EXIT_FAILURE, 0, _("empty tab"));
|
||||
if (optarg[1])
|
||||
{
|
||||
if (STREQ (optarg, "\\0"))
|
||||
newtab = '\0';
|
||||
else
|
||||
error (EXIT_FAILURE, 0, _("multi-character tab %s"),
|
||||
quote (optarg));
|
||||
}
|
||||
if (0 <= tab && tab != newtab)
|
||||
error (EXIT_FAILURE, 0, _("incompatible tabs"));
|
||||
tab = newtab;
|
||||
}
|
||||
break;
|
||||
|
||||
case NOCHECK_ORDER_OPTION:
|
||||
check_input_order = CHECK_ORDER_DISABLED;
|
||||
break;
|
||||
case NOCHECK_ORDER_OPTION:
|
||||
check_input_order = CHECK_ORDER_DISABLED;
|
||||
break;
|
||||
|
||||
case CHECK_ORDER_OPTION:
|
||||
check_input_order = CHECK_ORDER_ENABLED;
|
||||
break;
|
||||
case CHECK_ORDER_OPTION:
|
||||
check_input_order = CHECK_ORDER_ENABLED;
|
||||
break;
|
||||
|
||||
case 1: /* Non-option argument. */
|
||||
add_file_name (optarg, names, operand_status, joption_count,
|
||||
&nfiles, &prev_optc_status, &optc_status);
|
||||
break;
|
||||
case 1: /* Non-option argument. */
|
||||
add_file_name (optarg, names, operand_status, joption_count,
|
||||
&nfiles, &prev_optc_status, &optc_status);
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
prev_optc_status = optc_status;
|
||||
}
|
||||
@@ -1066,14 +1066,14 @@ main (int argc, char **argv)
|
||||
prev_optc_status = MUST_BE_OPERAND;
|
||||
while (optind < argc)
|
||||
add_file_name (argv[optind++], names, operand_status, joption_count,
|
||||
&nfiles, &prev_optc_status, &optc_status);
|
||||
&nfiles, &prev_optc_status, &optc_status);
|
||||
|
||||
if (nfiles != 2)
|
||||
{
|
||||
if (nfiles == 0)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -1082,8 +1082,8 @@ main (int argc, char **argv)
|
||||
for (i = 0; i < 2; i++)
|
||||
if (joption_count[i] != 0)
|
||||
{
|
||||
set_join_field (&join_field_1, i);
|
||||
set_join_field (&join_field_2, i);
|
||||
set_join_field (&join_field_1, i);
|
||||
set_join_field (&join_field_2, i);
|
||||
}
|
||||
|
||||
if (join_field_1 == SIZE_MAX)
|
||||
|
||||
+86
-86
@@ -52,8 +52,8 @@
|
||||
# endif
|
||||
# if HAVE_DECL_SYS_SIGLIST || defined sys_siglist
|
||||
# define strsignal(signum) (0 <= (signum) && (signum) <= SIGNUM_BOUND \
|
||||
? sys_siglist[signum] \
|
||||
: 0)
|
||||
? sys_siglist[signum] \
|
||||
: 0)
|
||||
# endif
|
||||
# ifndef strsignal
|
||||
# define strsignal(signum) 0
|
||||
@@ -81,7 +81,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -89,7 +89,7 @@ Usage: %s [-s SIGNAL | -SIGNAL] PID...\n\
|
||||
or: %s -l [SIGNAL]...\n\
|
||||
or: %s -t [SIGNAL]...\n\
|
||||
"),
|
||||
program_name, program_name, program_name);
|
||||
program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
Send signals to processes, or list signals.\n\
|
||||
\n\
|
||||
@@ -122,11 +122,11 @@ PID is an integer; if negative it identifies a process group.\n\
|
||||
|
||||
static void
|
||||
print_table_row (unsigned int num_width, int signum,
|
||||
unsigned int name_width, char const *signame)
|
||||
unsigned int name_width, char const *signame)
|
||||
{
|
||||
char const *description = strsignal (signum);
|
||||
printf ("%*d %-*s %s\n", num_width, signum, name_width, signame,
|
||||
description ? description : "?");
|
||||
description ? description : "?");
|
||||
}
|
||||
|
||||
/* Print a list of signal names. If TABLE, print a table.
|
||||
@@ -147,51 +147,51 @@ list_signals (bool table, char *const *argv)
|
||||
/* Compute the maximum width of a signal number. */
|
||||
unsigned int num_width = 1;
|
||||
for (signum = 1; signum <= SIGNUM_BOUND / 10; signum *= 10)
|
||||
num_width++;
|
||||
num_width++;
|
||||
|
||||
/* Compute the maximum width of a signal name. */
|
||||
for (signum = 1; signum <= SIGNUM_BOUND; signum++)
|
||||
if (sig2str (signum, signame) == 0)
|
||||
{
|
||||
size_t len = strlen (signame);
|
||||
if (name_width < len)
|
||||
name_width = len;
|
||||
}
|
||||
if (sig2str (signum, signame) == 0)
|
||||
{
|
||||
size_t len = strlen (signame);
|
||||
if (name_width < len)
|
||||
name_width = len;
|
||||
}
|
||||
|
||||
if (argv)
|
||||
for (; *argv; argv++)
|
||||
{
|
||||
signum = operand2sig (*argv, signame);
|
||||
if (signum < 0)
|
||||
status = EXIT_FAILURE;
|
||||
else
|
||||
print_table_row (num_width, signum, name_width, signame);
|
||||
}
|
||||
for (; *argv; argv++)
|
||||
{
|
||||
signum = operand2sig (*argv, signame);
|
||||
if (signum < 0)
|
||||
status = EXIT_FAILURE;
|
||||
else
|
||||
print_table_row (num_width, signum, name_width, signame);
|
||||
}
|
||||
else
|
||||
for (signum = 1; signum <= SIGNUM_BOUND; signum++)
|
||||
if (sig2str (signum, signame) == 0)
|
||||
print_table_row (num_width, signum, name_width, signame);
|
||||
for (signum = 1; signum <= SIGNUM_BOUND; signum++)
|
||||
if (sig2str (signum, signame) == 0)
|
||||
print_table_row (num_width, signum, name_width, signame);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (argv)
|
||||
for (; *argv; argv++)
|
||||
{
|
||||
signum = operand2sig (*argv, signame);
|
||||
if (signum < 0)
|
||||
status = EXIT_FAILURE;
|
||||
else
|
||||
{
|
||||
if (ISDIGIT (**argv))
|
||||
puts (signame);
|
||||
else
|
||||
printf ("%d\n", signum);
|
||||
}
|
||||
}
|
||||
for (; *argv; argv++)
|
||||
{
|
||||
signum = operand2sig (*argv, signame);
|
||||
if (signum < 0)
|
||||
status = EXIT_FAILURE;
|
||||
else
|
||||
{
|
||||
if (ISDIGIT (**argv))
|
||||
puts (signame);
|
||||
else
|
||||
printf ("%d\n", signum);
|
||||
}
|
||||
}
|
||||
else
|
||||
for (signum = 1; signum <= SIGNUM_BOUND; signum++)
|
||||
if (sig2str (signum, signame) == 0)
|
||||
puts (signame);
|
||||
for (signum = 1; signum <= SIGNUM_BOUND; signum++)
|
||||
if (sig2str (signum, signame) == 0)
|
||||
puts (signame);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -213,15 +213,15 @@ send_signals (int signum, char *const *argv)
|
||||
pid_t pid = n;
|
||||
|
||||
if (errno == ERANGE || pid != n || arg == endp || *endp)
|
||||
{
|
||||
error (0, 0, _("%s: invalid process id"), arg);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("%s: invalid process id"), arg);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
else if (kill (pid, signum) != 0)
|
||||
{
|
||||
error (0, errno, "%s", arg);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", arg);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
while ((arg = *++argv));
|
||||
|
||||
@@ -246,61 +246,61 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, short_options, long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
switch (optc)
|
||||
{
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
if (optind != 2)
|
||||
{
|
||||
/* This option is actually a process-id. */
|
||||
optind--;
|
||||
goto no_more_options;
|
||||
}
|
||||
/* Fall through. */
|
||||
if (optind != 2)
|
||||
{
|
||||
/* This option is actually a process-id. */
|
||||
optind--;
|
||||
goto no_more_options;
|
||||
}
|
||||
/* Fall through. */
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E':
|
||||
case 'F': case 'G': case 'H': case 'I': case 'J':
|
||||
case 'K': case 'L': case 'M': case 'N': case 'O':
|
||||
case 'P': case 'Q': case 'R': case 'S': case 'T':
|
||||
case 'U': case 'V': case 'W': case 'X': case 'Y':
|
||||
case 'Z':
|
||||
if (! optarg)
|
||||
optarg = argv[optind - 1] + strlen (argv[optind - 1]);
|
||||
if (optarg != argv[optind - 1] + 2)
|
||||
{
|
||||
error (0, 0, _("invalid option -- %c"), optc);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
optarg--;
|
||||
/* Fall through. */
|
||||
if (! optarg)
|
||||
optarg = argv[optind - 1] + strlen (argv[optind - 1]);
|
||||
if (optarg != argv[optind - 1] + 2)
|
||||
{
|
||||
error (0, 0, _("invalid option -- %c"), optc);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
optarg--;
|
||||
/* Fall through. */
|
||||
case 'n': /* -n is not documented, but is for Bash compatibility. */
|
||||
case 's':
|
||||
if (0 <= signum)
|
||||
{
|
||||
error (0, 0, _("%s: multiple signals specified"), optarg);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
signum = operand2sig (optarg, signame);
|
||||
if (signum < 0)
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
if (0 <= signum)
|
||||
{
|
||||
error (0, 0, _("%s: multiple signals specified"), optarg);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
signum = operand2sig (optarg, signame);
|
||||
if (signum < 0)
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
table = true;
|
||||
/* Fall through. */
|
||||
table = true;
|
||||
/* Fall through. */
|
||||
case 'l':
|
||||
if (list)
|
||||
{
|
||||
error (0, 0, _("multiple -l or -t options specified"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
list = true;
|
||||
break;
|
||||
if (list)
|
||||
{
|
||||
error (0, 0, _("multiple -l or -t options specified"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
list = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
no_more_options:;
|
||||
|
||||
@@ -319,6 +319,6 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
return (list
|
||||
? list_signals (table, optind < argc ? argv + optind : NULL)
|
||||
: send_signals (signum, argv + optind));
|
||||
? list_signals (table, optind < argc ? argv + optind : NULL)
|
||||
: send_signals (signum, argv + optind));
|
||||
}
|
||||
+6
-6
@@ -40,7 +40,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -48,7 +48,7 @@ Usage: %s FILE1 FILE2\n\
|
||||
or: %s OPTION\n"), program_name, program_name);
|
||||
fputs (_("Call the link function to create a link named FILE2\
|
||||
to an existing FILE1.\n\n"),
|
||||
stdout);
|
||||
stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
emit_bug_reporting_address ();
|
||||
@@ -68,16 +68,16 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
if (argc < optind + 2)
|
||||
{
|
||||
if (argc < optind + 1)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[optind]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[optind]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ main (int argc, char **argv)
|
||||
|
||||
if (link (argv[optind], argv[optind + 1]) != 0)
|
||||
error (EXIT_FAILURE, errno, _("cannot create link %s to %s"),
|
||||
quote_n (0, argv[optind + 1]), quote_n (1, argv[optind]));
|
||||
quote_n (0, argv[optind + 1]), quote_n (1, argv[optind]));
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -154,39 +154,39 @@ do_link (const char *source, const char *dest)
|
||||
if (!symbolic_link)
|
||||
{
|
||||
if (STAT_LIKE_LINK (source, &source_stats) != 0)
|
||||
{
|
||||
error (0, errno, _("accessing %s"), quote (source));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("accessing %s"), quote (source));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ENABLE_HARD_LINK_TO_SYMLINK_WARNING
|
||||
&& S_ISLNK (source_stats.st_mode))
|
||||
{
|
||||
error (0, 0, _("%s: warning: making a hard link to a symbolic link\
|
||||
&& S_ISLNK (source_stats.st_mode))
|
||||
{
|
||||
error (0, 0, _("%s: warning: making a hard link to a symbolic link\
|
||||
is not portable"),
|
||||
quote (source));
|
||||
}
|
||||
quote (source));
|
||||
}
|
||||
|
||||
if (S_ISDIR (source_stats.st_mode))
|
||||
{
|
||||
source_is_dir = true;
|
||||
if (! hard_dir_link)
|
||||
{
|
||||
error (0, 0, _("%s: hard link not allowed for directory"),
|
||||
quote (source));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
{
|
||||
source_is_dir = true;
|
||||
if (! hard_dir_link)
|
||||
{
|
||||
error (0, 0, _("%s: hard link not allowed for directory"),
|
||||
quote (source));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (remove_existing_files || interactive || backup_type != no_backups)
|
||||
{
|
||||
dest_lstat_ok = (lstat (dest, &dest_stats) == 0);
|
||||
if (!dest_lstat_ok && errno != ENOENT)
|
||||
{
|
||||
error (0, errno, _("accessing %s"), quote (dest));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("accessing %s"), quote (dest));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the current target was created as a hard link to another
|
||||
@@ -196,8 +196,8 @@ do_link (const char *source, const char *dest)
|
||||
&& seen_file (dest_set, dest, &dest_stats))
|
||||
{
|
||||
error (0, 0,
|
||||
_("will not overwrite just-created %s with %s"),
|
||||
quote_n (0, dest), quote_n (1, source));
|
||||
_("will not overwrite just-created %s with %s"),
|
||||
quote_n (0, dest), quote_n (1, source));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -208,65 +208,65 @@ do_link (const char *source, const char *dest)
|
||||
anything and fail right here. */
|
||||
if ((remove_existing_files
|
||||
/* Ensure that "ln --backup f f" fails here, with the
|
||||
"... same file" diagnostic, below. Otherwise, subsequent
|
||||
code would give a misleading "file not found" diagnostic.
|
||||
This case is different than the others handled here, since
|
||||
the command in question doesn't use --force. */
|
||||
"... same file" diagnostic, below. Otherwise, subsequent
|
||||
code would give a misleading "file not found" diagnostic.
|
||||
This case is different than the others handled here, since
|
||||
the command in question doesn't use --force. */
|
||||
|| (!symbolic_link && backup_type != no_backups))
|
||||
&& dest_lstat_ok
|
||||
/* Allow `ln -sf --backup k k' to succeed in creating the
|
||||
self-referential symlink, but don't allow the hard-linking
|
||||
equivalent: `ln -f k k' (with or without --backup) to get
|
||||
beyond this point, because the error message you'd get is
|
||||
misleading. */
|
||||
self-referential symlink, but don't allow the hard-linking
|
||||
equivalent: `ln -f k k' (with or without --backup) to get
|
||||
beyond this point, because the error message you'd get is
|
||||
misleading. */
|
||||
&& (backup_type == no_backups || !symbolic_link)
|
||||
&& (!symbolic_link || stat (source, &source_stats) == 0)
|
||||
&& SAME_INODE (source_stats, dest_stats)
|
||||
/* The following detects whether removing DEST will also remove
|
||||
SOURCE. If the file has only one link then both are surely
|
||||
the same link. Otherwise check whether they point to the same
|
||||
name in the same directory. */
|
||||
SOURCE. If the file has only one link then both are surely
|
||||
the same link. Otherwise check whether they point to the same
|
||||
name in the same directory. */
|
||||
&& (source_stats.st_nlink == 1 || same_name (source, dest)))
|
||||
{
|
||||
error (0, 0, _("%s and %s are the same file"),
|
||||
quote_n (0, source), quote_n (1, dest));
|
||||
quote_n (0, source), quote_n (1, dest));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dest_lstat_ok)
|
||||
{
|
||||
if (S_ISDIR (dest_stats.st_mode))
|
||||
{
|
||||
error (0, 0, _("%s: cannot overwrite directory"), quote (dest));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("%s: cannot overwrite directory"), quote (dest));
|
||||
return false;
|
||||
}
|
||||
if (interactive)
|
||||
{
|
||||
fprintf (stderr, _("%s: replace %s? "), program_name, quote (dest));
|
||||
if (!yesno ())
|
||||
return true;
|
||||
remove_existing_files = true;
|
||||
}
|
||||
{
|
||||
fprintf (stderr, _("%s: replace %s? "), program_name, quote (dest));
|
||||
if (!yesno ())
|
||||
return true;
|
||||
remove_existing_files = true;
|
||||
}
|
||||
|
||||
if (backup_type != no_backups)
|
||||
{
|
||||
dest_backup = find_backup_file_name (dest, backup_type);
|
||||
if (rename (dest, dest_backup) != 0)
|
||||
{
|
||||
int rename_errno = errno;
|
||||
free (dest_backup);
|
||||
dest_backup = NULL;
|
||||
if (rename_errno != ENOENT)
|
||||
{
|
||||
error (0, rename_errno, _("cannot backup %s"), quote (dest));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
dest_backup = find_backup_file_name (dest, backup_type);
|
||||
if (rename (dest, dest_backup) != 0)
|
||||
{
|
||||
int rename_errno = errno;
|
||||
free (dest_backup);
|
||||
dest_backup = NULL;
|
||||
if (rename_errno != ENOENT)
|
||||
{
|
||||
error (0, rename_errno, _("cannot backup %s"), quote (dest));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ok = ((symbolic_link ? symlink (source, dest) : link (source, dest))
|
||||
== 0);
|
||||
== 0);
|
||||
|
||||
/* If the attempt to create a link failed and we are removing or
|
||||
backing up destinations, unlink the destination and try again.
|
||||
@@ -289,50 +289,50 @@ do_link (const char *source, const char *dest)
|
||||
if (!ok && errno == EEXIST && (remove_existing_files || dest_backup))
|
||||
{
|
||||
if (unlink (dest) != 0)
|
||||
{
|
||||
error (0, errno, _("cannot remove %s"), quote (dest));
|
||||
free (dest_backup);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("cannot remove %s"), quote (dest));
|
||||
free (dest_backup);
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = ((symbolic_link ? symlink (source, dest) : link (source, dest))
|
||||
== 0);
|
||||
== 0);
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
/* Right after creating a hard link, do this: (note dest name and
|
||||
source_stats, which are also the just-linked-destinations stats) */
|
||||
source_stats, which are also the just-linked-destinations stats) */
|
||||
record_file (dest_set, dest, &source_stats);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
if (dest_backup)
|
||||
printf ("%s ~ ", quote (dest_backup));
|
||||
printf ("%s %c> %s\n", quote_n (0, dest), (symbolic_link ? '-' : '='),
|
||||
quote_n (1, source));
|
||||
}
|
||||
{
|
||||
if (dest_backup)
|
||||
printf ("%s ~ ", quote (dest_backup));
|
||||
printf ("%s %c> %s\n", quote_n (0, dest), (symbolic_link ? '-' : '='),
|
||||
quote_n (1, source));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno,
|
||||
(symbolic_link
|
||||
? (errno != ENAMETOOLONG && *source
|
||||
? _("creating symbolic link %s")
|
||||
: _("creating symbolic link %s -> %s"))
|
||||
: (errno == EMLINK && !source_is_dir
|
||||
? _("creating hard link to %.0s%s")
|
||||
: (errno == EDQUOT || errno == EEXIST || errno == ENOSPC
|
||||
|| errno == EROFS)
|
||||
? _("creating hard link %s")
|
||||
: _("creating hard link %s => %s"))),
|
||||
quote_n (0, dest), quote_n (1, source));
|
||||
(symbolic_link
|
||||
? (errno != ENAMETOOLONG && *source
|
||||
? _("creating symbolic link %s")
|
||||
: _("creating symbolic link %s -> %s"))
|
||||
: (errno == EMLINK && !source_is_dir
|
||||
? _("creating hard link to %.0s%s")
|
||||
: (errno == EDQUOT || errno == EEXIST || errno == ENOSPC
|
||||
|| errno == EROFS)
|
||||
? _("creating hard link %s")
|
||||
: _("creating hard link %s => %s"))),
|
||||
quote_n (0, dest), quote_n (1, source));
|
||||
|
||||
if (dest_backup)
|
||||
{
|
||||
if (rename (dest_backup, dest) != 0)
|
||||
error (0, errno, _("cannot un-backup %s"), quote (dest));
|
||||
}
|
||||
{
|
||||
if (rename (dest_backup, dest) != 0)
|
||||
error (0, errno, _("cannot un-backup %s"), quote (dest));
|
||||
}
|
||||
}
|
||||
|
||||
free (dest_backup);
|
||||
@@ -344,7 +344,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -353,7 +353,7 @@ Usage: %s [OPTION]... [-T] TARGET LINK_NAME (1st form)\n\
|
||||
or: %s [OPTION]... TARGET... DIRECTORY (3rd form)\n\
|
||||
or: %s [OPTION]... -t DIRECTORY TARGET... (4th form)\n\
|
||||
"),
|
||||
program_name, program_name, program_name, program_name);
|
||||
program_name, program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
In the 1st form, create a link to TARGET with the name LINK_NAME.\n\
|
||||
In the 2nd form, create a link to TARGET in the current directory.\n\
|
||||
@@ -437,63 +437,63 @@ main (int argc, char **argv)
|
||||
= hard_dir_link = false;
|
||||
|
||||
while ((c = getopt_long (argc, argv, "bdfinst:vFS:T", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
make_backups = true;
|
||||
if (optarg)
|
||||
version_control_string = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
case 'F':
|
||||
hard_dir_link = true;
|
||||
break;
|
||||
case 'f':
|
||||
remove_existing_files = true;
|
||||
interactive = false;
|
||||
break;
|
||||
case 'i':
|
||||
remove_existing_files = false;
|
||||
interactive = true;
|
||||
break;
|
||||
case 'n':
|
||||
dereference_dest_dir_symlinks = false;
|
||||
break;
|
||||
case 's':
|
||||
symbolic_link = true;
|
||||
break;
|
||||
case 't':
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0, _("multiple target directories specified"));
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat (optarg, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (optarg));
|
||||
}
|
||||
target_directory = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
no_target_directory = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case 'S':
|
||||
make_backups = true;
|
||||
backup_suffix_string = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
{
|
||||
case 'b':
|
||||
make_backups = true;
|
||||
if (optarg)
|
||||
version_control_string = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
case 'F':
|
||||
hard_dir_link = true;
|
||||
break;
|
||||
case 'f':
|
||||
remove_existing_files = true;
|
||||
interactive = false;
|
||||
break;
|
||||
case 'i':
|
||||
remove_existing_files = false;
|
||||
interactive = true;
|
||||
break;
|
||||
case 'n':
|
||||
dereference_dest_dir_symlinks = false;
|
||||
break;
|
||||
case 's':
|
||||
symbolic_link = true;
|
||||
break;
|
||||
case 't':
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0, _("multiple target directories specified"));
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat (optarg, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (optarg));
|
||||
}
|
||||
target_directory = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
no_target_directory = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case 'S':
|
||||
make_backups = true;
|
||||
backup_suffix_string = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
n_files = argc - optind;
|
||||
@@ -508,75 +508,75 @@ main (int argc, char **argv)
|
||||
if (no_target_directory)
|
||||
{
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot combine --target-directory "
|
||||
"and --no-target-directory"));
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot combine --target-directory "
|
||||
"and --no-target-directory"));
|
||||
if (n_files != 2)
|
||||
{
|
||||
if (n_files < 2)
|
||||
error (0, 0,
|
||||
_("missing destination file operand after %s"),
|
||||
quote (file[0]));
|
||||
else
|
||||
error (0, 0, _("extra operand %s"), quote (file[2]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
if (n_files < 2)
|
||||
error (0, 0,
|
||||
_("missing destination file operand after %s"),
|
||||
quote (file[0]));
|
||||
else
|
||||
error (0, 0, _("extra operand %s"), quote (file[2]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if (!target_directory)
|
||||
{
|
||||
if (n_files < 2)
|
||||
target_directory = ".";
|
||||
target_directory = ".";
|
||||
else if (2 <= n_files && target_directory_operand (file[n_files - 1]))
|
||||
target_directory = file[--n_files];
|
||||
target_directory = file[--n_files];
|
||||
else if (2 < n_files)
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (file[n_files - 1]));
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (file[n_files - 1]));
|
||||
}
|
||||
|
||||
if (backup_suffix_string)
|
||||
simple_backup_suffix = xstrdup (backup_suffix_string);
|
||||
|
||||
backup_type = (make_backups
|
||||
? xget_version (_("backup type"), version_control_string)
|
||||
: no_backups);
|
||||
? xget_version (_("backup type"), version_control_string)
|
||||
: no_backups);
|
||||
|
||||
if (target_directory)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Create the data structure we'll use to record which hard links we
|
||||
create. Used to ensure that ln detects an obscure corner case that
|
||||
might result in user data loss. Create it only if needed. */
|
||||
create. Used to ensure that ln detects an obscure corner case that
|
||||
might result in user data loss. Create it only if needed. */
|
||||
if (2 <= n_files
|
||||
&& remove_existing_files
|
||||
/* Don't bother trying to protect symlinks, since ln clobbering
|
||||
a just-created symlink won't ever lead to real data loss. */
|
||||
&& ! symbolic_link
|
||||
/* No destination hard link can be clobbered when making
|
||||
numbered backups. */
|
||||
&& backup_type != numbered_backups)
|
||||
&& remove_existing_files
|
||||
/* Don't bother trying to protect symlinks, since ln clobbering
|
||||
a just-created symlink won't ever lead to real data loss. */
|
||||
&& ! symbolic_link
|
||||
/* No destination hard link can be clobbered when making
|
||||
numbered backups. */
|
||||
&& backup_type != numbered_backups)
|
||||
|
||||
{
|
||||
dest_set = hash_initialize (DEST_INFO_INITIAL_CAPACITY,
|
||||
NULL,
|
||||
triple_hash,
|
||||
triple_compare,
|
||||
triple_free);
|
||||
if (dest_set == NULL)
|
||||
xalloc_die ();
|
||||
}
|
||||
{
|
||||
dest_set = hash_initialize (DEST_INFO_INITIAL_CAPACITY,
|
||||
NULL,
|
||||
triple_hash,
|
||||
triple_compare,
|
||||
triple_free);
|
||||
if (dest_set == NULL)
|
||||
xalloc_die ();
|
||||
}
|
||||
|
||||
ok = true;
|
||||
for (i = 0; i < n_files; ++i)
|
||||
{
|
||||
char *dest_base;
|
||||
char *dest = file_name_concat (target_directory,
|
||||
last_component (file[i]),
|
||||
&dest_base);
|
||||
strip_trailing_slashes (dest_base);
|
||||
ok &= do_link (file[i], dest);
|
||||
free (dest);
|
||||
}
|
||||
{
|
||||
char *dest_base;
|
||||
char *dest = file_name_concat (target_directory,
|
||||
last_component (file[i]),
|
||||
&dest_base);
|
||||
strip_trailing_slashes (dest_base);
|
||||
ok &= do_link (file[i], dest);
|
||||
free (dest);
|
||||
}
|
||||
}
|
||||
else
|
||||
ok = do_link (file[0], file[1]);
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]\n"), program_name);
|
||||
@@ -63,7 +63,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "", NULL, NULL) != -1)
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
|
||||
+209
-209
@@ -147,7 +147,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -156,26 +156,26 @@ Print or check %s (%d-bit) checksums.\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n\
|
||||
\n\
|
||||
"),
|
||||
program_name,
|
||||
DIGEST_TYPE_STRING,
|
||||
DIGEST_BITS);
|
||||
program_name,
|
||||
DIGEST_TYPE_STRING,
|
||||
DIGEST_BITS);
|
||||
if (O_BINARY)
|
||||
fputs (_("\
|
||||
fputs (_("\
|
||||
-b, --binary read in binary mode (default unless reading tty stdin)\n\
|
||||
"), stdout);
|
||||
else
|
||||
fputs (_("\
|
||||
fputs (_("\
|
||||
-b, --binary read in binary mode\n\
|
||||
"), stdout);
|
||||
printf (_("\
|
||||
-c, --check read %s sums from the FILEs and check them\n"),
|
||||
DIGEST_TYPE_STRING);
|
||||
DIGEST_TYPE_STRING);
|
||||
if (O_BINARY)
|
||||
fputs (_("\
|
||||
fputs (_("\
|
||||
-t, --text read in text mode (default if reading tty stdin)\n\
|
||||
"), stdout);
|
||||
else
|
||||
fputs (_("\
|
||||
fputs (_("\
|
||||
-t, --text read in text mode (default)\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
@@ -194,7 +194,7 @@ The sums are computed as described in %s. When checking, the input\n\
|
||||
should be a former output of this program. The default mode is to print\n\
|
||||
a line with checksum, a character indicating type (`*' for binary, ` ' for\n\
|
||||
text), and name for each FILE.\n"),
|
||||
DIGEST_REFERENCE);
|
||||
DIGEST_REFERENCE);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ bsd_split_3 (char *s, size_t s_len, unsigned char **hex_digest, char **file_name
|
||||
|
||||
static bool
|
||||
split_3 (char *s, size_t s_len,
|
||||
unsigned char **hex_digest, int *binary, char **file_name)
|
||||
unsigned char **hex_digest, int *binary, char **file_name)
|
||||
{
|
||||
size_t i;
|
||||
bool escaped_filename = false;
|
||||
@@ -264,12 +264,12 @@ split_3 (char *s, size_t s_len,
|
||||
if (strncmp (s + i, DIGEST_TYPE_STRING, algo_name_len) == 0)
|
||||
{
|
||||
if (strncmp (s + i + algo_name_len, " (", 2) == 0)
|
||||
{
|
||||
*binary = 0;
|
||||
return bsd_split_3 (s + i + algo_name_len + 2,
|
||||
s_len - (i + algo_name_len + 2),
|
||||
hex_digest, file_name);
|
||||
}
|
||||
{
|
||||
*binary = 0;
|
||||
return bsd_split_3 (s + i + algo_name_len + 2,
|
||||
s_len - (i + algo_name_len + 2),
|
||||
hex_digest, file_name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ignore this line if it is too short.
|
||||
@@ -306,45 +306,45 @@ split_3 (char *s, size_t s_len,
|
||||
if (escaped_filename)
|
||||
{
|
||||
/* Translate each `\n' string in the file name to a NEWLINE,
|
||||
and each `\\' string to a backslash. */
|
||||
and each `\\' string to a backslash. */
|
||||
|
||||
char *dst = &s[i];
|
||||
|
||||
while (i < s_len)
|
||||
{
|
||||
switch (s[i])
|
||||
{
|
||||
case '\\':
|
||||
if (i == s_len - 1)
|
||||
{
|
||||
/* A valid line does not end with a backslash. */
|
||||
return false;
|
||||
}
|
||||
++i;
|
||||
switch (s[i++])
|
||||
{
|
||||
case 'n':
|
||||
*dst++ = '\n';
|
||||
break;
|
||||
case '\\':
|
||||
*dst++ = '\\';
|
||||
break;
|
||||
default:
|
||||
/* Only `\' or `n' may follow a backslash. */
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
{
|
||||
switch (s[i])
|
||||
{
|
||||
case '\\':
|
||||
if (i == s_len - 1)
|
||||
{
|
||||
/* A valid line does not end with a backslash. */
|
||||
return false;
|
||||
}
|
||||
++i;
|
||||
switch (s[i++])
|
||||
{
|
||||
case 'n':
|
||||
*dst++ = '\n';
|
||||
break;
|
||||
case '\\':
|
||||
*dst++ = '\\';
|
||||
break;
|
||||
default:
|
||||
/* Only `\' or `n' may follow a backslash. */
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
/* The file name may not contain a NUL. */
|
||||
return false;
|
||||
break;
|
||||
case '\0':
|
||||
/* The file name may not contain a NUL. */
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
*dst++ = s[i++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
*dst++ = s[i++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
*dst = '\0';
|
||||
}
|
||||
return true;
|
||||
@@ -388,21 +388,21 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result)
|
||||
have_read_stdin = true;
|
||||
fp = stdin;
|
||||
if (O_BINARY && *binary)
|
||||
{
|
||||
if (*binary < 0)
|
||||
*binary = ! isatty (STDIN_FILENO);
|
||||
if (*binary)
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
{
|
||||
if (*binary < 0)
|
||||
*binary = ! isatty (STDIN_FILENO);
|
||||
if (*binary)
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = fopen (filename, (O_BINARY && *binary ? "rb" : "r"));
|
||||
if (fp == NULL)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
err = DIGEST_STREAM (fp, bin_result);
|
||||
@@ -410,7 +410,7 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
if (fp != stdin)
|
||||
fclose (fp);
|
||||
fclose (fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -448,10 +448,10 @@ digest_check (const char *checkfile_name)
|
||||
{
|
||||
checkfile_stream = fopen (checkfile_name, "r");
|
||||
if (checkfile_stream == NULL)
|
||||
{
|
||||
error (0, errno, "%s", checkfile_name);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", checkfile_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
line_number = 0;
|
||||
@@ -466,82 +466,82 @@ digest_check (const char *checkfile_name)
|
||||
|
||||
++line_number;
|
||||
if (line_number == 0)
|
||||
error (EXIT_FAILURE, 0, _("%s: too many checksum lines"),
|
||||
checkfile_name);
|
||||
error (EXIT_FAILURE, 0, _("%s: too many checksum lines"),
|
||||
checkfile_name);
|
||||
|
||||
line_length = getline (&line, &line_chars_allocated, checkfile_stream);
|
||||
if (line_length <= 0)
|
||||
break;
|
||||
break;
|
||||
|
||||
/* Ignore comment lines, which begin with a '#' character. */
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
continue;
|
||||
|
||||
/* Remove any trailing newline. */
|
||||
if (line[line_length - 1] == '\n')
|
||||
line[--line_length] = '\0';
|
||||
line[--line_length] = '\0';
|
||||
|
||||
if (! (split_3 (line, line_length, &hex_digest, &binary, &filename)
|
||||
&& ! (is_stdin && STREQ (filename, "-"))
|
||||
&& hex_digits (hex_digest)))
|
||||
{
|
||||
if (warn)
|
||||
{
|
||||
error (0, 0,
|
||||
_("%s: %" PRIuMAX
|
||||
": improperly formatted %s checksum line"),
|
||||
checkfile_name, line_number,
|
||||
DIGEST_TYPE_STRING);
|
||||
}
|
||||
}
|
||||
&& ! (is_stdin && STREQ (filename, "-"))
|
||||
&& hex_digits (hex_digest)))
|
||||
{
|
||||
if (warn)
|
||||
{
|
||||
error (0, 0,
|
||||
_("%s: %" PRIuMAX
|
||||
": improperly formatted %s checksum line"),
|
||||
checkfile_name, line_number,
|
||||
DIGEST_TYPE_STRING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static const char bin2hex[] = { '0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b',
|
||||
'c', 'd', 'e', 'f' };
|
||||
bool ok;
|
||||
{
|
||||
static const char bin2hex[] = { '0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b',
|
||||
'c', 'd', 'e', 'f' };
|
||||
bool ok;
|
||||
|
||||
++n_properly_formatted_lines;
|
||||
++n_properly_formatted_lines;
|
||||
|
||||
ok = digest_file (filename, &binary, bin_buffer);
|
||||
ok = digest_file (filename, &binary, bin_buffer);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
++n_open_or_read_failures;
|
||||
if (!status_only)
|
||||
{
|
||||
printf (_("%s: FAILED open or read\n"), filename);
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t digest_bin_bytes = digest_hex_bytes / 2;
|
||||
size_t cnt;
|
||||
/* Compare generated binary number with text representation
|
||||
in check file. Ignore case of hex digits. */
|
||||
for (cnt = 0; cnt < digest_bin_bytes; ++cnt)
|
||||
{
|
||||
if (tolower (hex_digest[2 * cnt])
|
||||
!= bin2hex[bin_buffer[cnt] >> 4]
|
||||
|| (tolower (hex_digest[2 * cnt + 1])
|
||||
!= (bin2hex[bin_buffer[cnt] & 0xf])))
|
||||
break;
|
||||
}
|
||||
if (cnt != digest_bin_bytes)
|
||||
++n_mismatched_checksums;
|
||||
if (!ok)
|
||||
{
|
||||
++n_open_or_read_failures;
|
||||
if (!status_only)
|
||||
{
|
||||
printf (_("%s: FAILED open or read\n"), filename);
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t digest_bin_bytes = digest_hex_bytes / 2;
|
||||
size_t cnt;
|
||||
/* Compare generated binary number with text representation
|
||||
in check file. Ignore case of hex digits. */
|
||||
for (cnt = 0; cnt < digest_bin_bytes; ++cnt)
|
||||
{
|
||||
if (tolower (hex_digest[2 * cnt])
|
||||
!= bin2hex[bin_buffer[cnt] >> 4]
|
||||
|| (tolower (hex_digest[2 * cnt + 1])
|
||||
!= (bin2hex[bin_buffer[cnt] & 0xf])))
|
||||
break;
|
||||
}
|
||||
if (cnt != digest_bin_bytes)
|
||||
++n_mismatched_checksums;
|
||||
|
||||
if (!status_only)
|
||||
{
|
||||
if (cnt != digest_bin_bytes)
|
||||
printf ("%s: %s\n", filename, _("FAILED"));
|
||||
else if (!quiet)
|
||||
printf ("%s: %s\n", filename, _("OK"));
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!status_only)
|
||||
{
|
||||
if (cnt != digest_bin_bytes)
|
||||
printf ("%s: %s\n", filename, _("FAILED"));
|
||||
else if (!quiet)
|
||||
printf ("%s: %s\n", filename, _("OK"));
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!feof (checkfile_stream) && !ferror (checkfile_stream));
|
||||
|
||||
@@ -563,39 +563,39 @@ digest_check (const char *checkfile_name)
|
||||
{
|
||||
/* Warn if no tests are found. */
|
||||
error (0, 0, _("%s: no properly formatted %s checksum lines found"),
|
||||
checkfile_name, DIGEST_TYPE_STRING);
|
||||
checkfile_name, DIGEST_TYPE_STRING);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!status_only)
|
||||
{
|
||||
if (n_open_or_read_failures != 0)
|
||||
error (0, 0,
|
||||
ngettext ("WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" listed file could not be read",
|
||||
"WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" listed files could not be read",
|
||||
select_plural (n_properly_formatted_lines)),
|
||||
n_open_or_read_failures, n_properly_formatted_lines);
|
||||
{
|
||||
if (n_open_or_read_failures != 0)
|
||||
error (0, 0,
|
||||
ngettext ("WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" listed file could not be read",
|
||||
"WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" listed files could not be read",
|
||||
select_plural (n_properly_formatted_lines)),
|
||||
n_open_or_read_failures, n_properly_formatted_lines);
|
||||
|
||||
if (n_mismatched_checksums != 0)
|
||||
{
|
||||
uintmax_t n_computed_checksums =
|
||||
(n_properly_formatted_lines - n_open_or_read_failures);
|
||||
error (0, 0,
|
||||
ngettext ("WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" computed checksum did NOT match",
|
||||
"WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" computed checksums did NOT match",
|
||||
select_plural (n_computed_checksums)),
|
||||
n_mismatched_checksums, n_computed_checksums);
|
||||
}
|
||||
}
|
||||
if (n_mismatched_checksums != 0)
|
||||
{
|
||||
uintmax_t n_computed_checksums =
|
||||
(n_properly_formatted_lines - n_open_or_read_failures);
|
||||
error (0, 0,
|
||||
ngettext ("WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" computed checksum did NOT match",
|
||||
"WARNING: %" PRIuMAX " of %" PRIuMAX
|
||||
" computed checksums did NOT match",
|
||||
select_plural (n_computed_checksums)),
|
||||
n_mismatched_checksums, n_computed_checksums);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (n_properly_formatted_lines != 0
|
||||
&& n_mismatched_checksums == 0
|
||||
&& n_open_or_read_failures == 0);
|
||||
&& n_mismatched_checksums == 0
|
||||
&& n_open_or_read_failures == 0);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -622,33 +622,33 @@ main (int argc, char **argv)
|
||||
switch (opt)
|
||||
{
|
||||
case 'b':
|
||||
binary = 1;
|
||||
break;
|
||||
binary = 1;
|
||||
break;
|
||||
case 'c':
|
||||
do_check = true;
|
||||
break;
|
||||
do_check = true;
|
||||
break;
|
||||
case STATUS_OPTION:
|
||||
status_only = true;
|
||||
warn = false;
|
||||
quiet = false;
|
||||
break;
|
||||
status_only = true;
|
||||
warn = false;
|
||||
quiet = false;
|
||||
break;
|
||||
case 't':
|
||||
binary = 0;
|
||||
break;
|
||||
binary = 0;
|
||||
break;
|
||||
case 'w':
|
||||
status_only = false;
|
||||
warn = true;
|
||||
quiet = false;
|
||||
break;
|
||||
status_only = false;
|
||||
warn = true;
|
||||
quiet = false;
|
||||
break;
|
||||
case QUIET_OPTION:
|
||||
status_only = false;
|
||||
warn = false;
|
||||
quiet = true;
|
||||
break;
|
||||
status_only = false;
|
||||
warn = false;
|
||||
quiet = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
min_digest_line_length = MIN_DIGEST_LINE_LENGTH;
|
||||
@@ -657,7 +657,7 @@ main (int argc, char **argv)
|
||||
if (0 <= binary && do_check)
|
||||
{
|
||||
error (0, 0, _("the --binary and --text options are meaningless when "
|
||||
"verifying checksums"));
|
||||
"verifying checksums"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -693,53 +693,53 @@ main (int argc, char **argv)
|
||||
char *file = argv[optind];
|
||||
|
||||
if (do_check)
|
||||
ok &= digest_check (file);
|
||||
ok &= digest_check (file);
|
||||
else
|
||||
{
|
||||
int file_is_binary = binary;
|
||||
{
|
||||
int file_is_binary = binary;
|
||||
|
||||
if (! digest_file (file, &file_is_binary, bin_buffer))
|
||||
ok = false;
|
||||
else
|
||||
{
|
||||
size_t i;
|
||||
if (! digest_file (file, &file_is_binary, bin_buffer))
|
||||
ok = false;
|
||||
else
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* Output a leading backslash if the file name contains
|
||||
a newline or backslash. */
|
||||
if (strchr (file, '\n') || strchr (file, '\\'))
|
||||
putchar ('\\');
|
||||
/* Output a leading backslash if the file name contains
|
||||
a newline or backslash. */
|
||||
if (strchr (file, '\n') || strchr (file, '\\'))
|
||||
putchar ('\\');
|
||||
|
||||
for (i = 0; i < (digest_hex_bytes / 2); ++i)
|
||||
printf ("%02x", bin_buffer[i]);
|
||||
for (i = 0; i < (digest_hex_bytes / 2); ++i)
|
||||
printf ("%02x", bin_buffer[i]);
|
||||
|
||||
putchar (' ');
|
||||
if (file_is_binary)
|
||||
putchar ('*');
|
||||
else
|
||||
putchar (' ');
|
||||
putchar (' ');
|
||||
if (file_is_binary)
|
||||
putchar ('*');
|
||||
else
|
||||
putchar (' ');
|
||||
|
||||
/* Translate each NEWLINE byte to the string, "\\n",
|
||||
and each backslash to "\\\\". */
|
||||
for (i = 0; i < strlen (file); ++i)
|
||||
{
|
||||
switch (file[i])
|
||||
{
|
||||
case '\n':
|
||||
fputs ("\\n", stdout);
|
||||
break;
|
||||
/* Translate each NEWLINE byte to the string, "\\n",
|
||||
and each backslash to "\\\\". */
|
||||
for (i = 0; i < strlen (file); ++i)
|
||||
{
|
||||
switch (file[i])
|
||||
{
|
||||
case '\n':
|
||||
fputs ("\\n", stdout);
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
fputs ("\\\\", stdout);
|
||||
break;
|
||||
case '\\':
|
||||
fputs ("\\\\", stdout);
|
||||
break;
|
||||
|
||||
default:
|
||||
putchar (file[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar ('\n');
|
||||
}
|
||||
}
|
||||
default:
|
||||
putchar (file[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar ('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (have_read_stdin && fclose (stdin) == EOF)
|
||||
|
||||
+36
-36
@@ -51,7 +51,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... DIRECTORY...\n"), program_name);
|
||||
@@ -129,10 +129,10 @@ process_dir (char *dir, struct savewd *wd, void *options)
|
||||
{
|
||||
struct mkdir_options const *o = options;
|
||||
return (make_dir_parents (dir, wd, o->make_ancestor_function, options,
|
||||
o->mode, announce_mkdir,
|
||||
o->mode_bits, (uid_t) -1, (gid_t) -1, true)
|
||||
? EXIT_SUCCESS
|
||||
: EXIT_FAILURE);
|
||||
o->mode, announce_mkdir,
|
||||
o->mode_bits, (uid_t) -1, (gid_t) -1, true)
|
||||
? EXIT_SUCCESS
|
||||
: EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -159,24 +159,24 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "pm:vZ:", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'p':
|
||||
options.make_ancestor_function = make_ancestor;
|
||||
break;
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'v': /* --verbose */
|
||||
options.created_directory_format = _("created directory %s");
|
||||
break;
|
||||
case 'Z':
|
||||
scontext = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'p':
|
||||
options.make_ancestor_function = make_ancestor;
|
||||
break;
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'v': /* --verbose */
|
||||
options.created_directory_format = _("created directory %s");
|
||||
break;
|
||||
case 'Z':
|
||||
scontext = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
@@ -187,8 +187,8 @@ main (int argc, char **argv)
|
||||
|
||||
if (scontext && setfscreatecon (scontext) < 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
|
||||
if (options.make_ancestor_function || specified_mode)
|
||||
{
|
||||
@@ -197,19 +197,19 @@ main (int argc, char **argv)
|
||||
options.ancestor_mode = (S_IRWXUGO & ~umask_value) | (S_IWUSR | S_IXUSR);
|
||||
|
||||
if (specified_mode)
|
||||
{
|
||||
struct mode_change *change = mode_compile (specified_mode);
|
||||
if (!change)
|
||||
error (EXIT_FAILURE, 0, _("invalid mode %s"),
|
||||
quote (specified_mode));
|
||||
options.mode = mode_adjust (S_IRWXUGO, true, umask_value, change,
|
||||
&options.mode_bits);
|
||||
free (change);
|
||||
}
|
||||
{
|
||||
struct mode_change *change = mode_compile (specified_mode);
|
||||
if (!change)
|
||||
error (EXIT_FAILURE, 0, _("invalid mode %s"),
|
||||
quote (specified_mode));
|
||||
options.mode = mode_adjust (S_IRWXUGO, true, umask_value, change,
|
||||
&options.mode_bits);
|
||||
free (change);
|
||||
}
|
||||
else
|
||||
options.mode = S_IRWXUGO & ~umask_value;
|
||||
options.mode = S_IRWXUGO & ~umask_value;
|
||||
}
|
||||
|
||||
exit (savewd_process_files (argc - optind, argv + optind,
|
||||
process_dir, &options));
|
||||
process_dir, &options));
|
||||
}
|
||||
+20
-20
@@ -46,7 +46,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... NAME...\n"), program_name);
|
||||
@@ -90,18 +90,18 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "m:Z:", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'Z':
|
||||
scontext = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'Z':
|
||||
scontext = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
@@ -112,27 +112,27 @@ main (int argc, char **argv)
|
||||
|
||||
if (scontext && setfscreatecon (scontext) < 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
|
||||
newmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (specified_mode)
|
||||
{
|
||||
struct mode_change *change = mode_compile (specified_mode);
|
||||
if (!change)
|
||||
error (EXIT_FAILURE, 0, _("invalid mode"));
|
||||
error (EXIT_FAILURE, 0, _("invalid mode"));
|
||||
newmode = mode_adjust (newmode, false, umask (0), change, NULL);
|
||||
free (change);
|
||||
if (newmode & ~S_IRWXUGO)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("mode must specify only file permission bits"));
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("mode must specify only file permission bits"));
|
||||
}
|
||||
|
||||
for (; optind < argc; ++optind)
|
||||
if (mkfifo (argv[optind], newmode) != 0)
|
||||
{
|
||||
error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
|
||||
exit_status = EXIT_FAILURE;
|
||||
error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
exit (exit_status);
|
||||
|
||||
+46
-46
@@ -47,11 +47,11 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... NAME TYPE [MAJOR MINOR]\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Create the special file NAME of the given TYPE.\n\
|
||||
\n\
|
||||
@@ -107,18 +107,18 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "m:Z:", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'Z':
|
||||
scontext = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'm':
|
||||
specified_mode = optarg;
|
||||
break;
|
||||
case 'Z':
|
||||
scontext = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
newmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
@@ -126,47 +126,47 @@ main (int argc, char **argv)
|
||||
{
|
||||
struct mode_change *change = mode_compile (specified_mode);
|
||||
if (!change)
|
||||
error (EXIT_FAILURE, 0, _("invalid mode"));
|
||||
error (EXIT_FAILURE, 0, _("invalid mode"));
|
||||
newmode = mode_adjust (newmode, false, umask (0), change, NULL);
|
||||
free (change);
|
||||
if (newmode & ~S_IRWXUGO)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("mode must specify only file permission bits"));
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("mode must specify only file permission bits"));
|
||||
}
|
||||
|
||||
/* If the number of arguments is 0 or 1,
|
||||
or (if it's 2 or more and the second one starts with `p'), then there
|
||||
must be exactly two operands. Otherwise, there must be four. */
|
||||
expected_operands = (argc <= optind
|
||||
|| (optind + 1 < argc && argv[optind + 1][0] == 'p')
|
||||
? 2 : 4);
|
||||
|| (optind + 1 < argc && argv[optind + 1][0] == 'p')
|
||||
? 2 : 4);
|
||||
|
||||
if (argc - optind < expected_operands)
|
||||
{
|
||||
if (argc <= optind)
|
||||
error (0, 0, _("missing operand"));
|
||||
error (0, 0, _("missing operand"));
|
||||
else
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
|
||||
if (expected_operands == 4 && argc - optind == 2)
|
||||
fprintf (stderr, "%s\n",
|
||||
_("Special files require major and minor device numbers."));
|
||||
fprintf (stderr, "%s\n",
|
||||
_("Special files require major and minor device numbers."));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (expected_operands < argc - optind)
|
||||
{
|
||||
error (0, 0, _("extra operand %s"),
|
||||
quote (argv[optind + expected_operands]));
|
||||
quote (argv[optind + expected_operands]));
|
||||
if (expected_operands == 2 && argc - optind == 4)
|
||||
fprintf (stderr, "%s\n",
|
||||
_("Fifos do not have major and minor device numbers."));
|
||||
fprintf (stderr, "%s\n",
|
||||
_("Fifos do not have major and minor device numbers."));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (scontext && setfscreatecon (scontext) < 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (scontext));
|
||||
|
||||
/* Only check the first character, to allow mnemonic usage like
|
||||
`mknod /dev/rst0 character 18 0'. */
|
||||
@@ -192,35 +192,35 @@ main (int argc, char **argv)
|
||||
|
||||
block_or_character:
|
||||
{
|
||||
char const *s_major = argv[optind + 2];
|
||||
char const *s_minor = argv[optind + 3];
|
||||
uintmax_t i_major, i_minor;
|
||||
dev_t device;
|
||||
char const *s_major = argv[optind + 2];
|
||||
char const *s_minor = argv[optind + 3];
|
||||
uintmax_t i_major, i_minor;
|
||||
dev_t device;
|
||||
|
||||
if (xstrtoumax (s_major, NULL, 0, &i_major, NULL) != LONGINT_OK
|
||||
|| i_major != (major_t) i_major)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid major device number %s"), quote (s_major));
|
||||
if (xstrtoumax (s_major, NULL, 0, &i_major, NULL) != LONGINT_OK
|
||||
|| i_major != (major_t) i_major)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid major device number %s"), quote (s_major));
|
||||
|
||||
if (xstrtoumax (s_minor, NULL, 0, &i_minor, NULL) != LONGINT_OK
|
||||
|| i_minor != (minor_t) i_minor)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid minor device number %s"), quote (s_minor));
|
||||
if (xstrtoumax (s_minor, NULL, 0, &i_minor, NULL) != LONGINT_OK
|
||||
|| i_minor != (minor_t) i_minor)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("invalid minor device number %s"), quote (s_minor));
|
||||
|
||||
device = makedev (i_major, i_minor);
|
||||
device = makedev (i_major, i_minor);
|
||||
#ifdef NODEV
|
||||
if (device == NODEV)
|
||||
error (EXIT_FAILURE, 0, _("invalid device %s %s"), s_major, s_minor);
|
||||
if (device == NODEV)
|
||||
error (EXIT_FAILURE, 0, _("invalid device %s %s"), s_major, s_minor);
|
||||
#endif
|
||||
|
||||
if (mknod (argv[optind], newmode | node_type, device) != 0)
|
||||
error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
|
||||
if (mknod (argv[optind], newmode | node_type, device) != 0)
|
||||
error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p': /* `pipe' */
|
||||
if (mkfifo (argv[optind], newmode) != 0)
|
||||
error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
|
||||
error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -94,7 +94,7 @@ rm_option_init (struct rm_options *x)
|
||||
x->root_dev_ino = get_root_dev_ino (&dev_ino_buf);
|
||||
if (x->root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
quote ("/"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,67 +167,67 @@ do_move (const char *source, const char *dest, const struct cp_options *x)
|
||||
{
|
||||
char const *dir_to_remove;
|
||||
if (copy_into_self)
|
||||
{
|
||||
/* In general, when copy returns with copy_into_self set, SOURCE is
|
||||
the same as, or a parent of DEST. In this case we know it's a
|
||||
parent. It doesn't make sense to move a directory into itself, and
|
||||
besides in some situations doing so would give highly nonintuitive
|
||||
results. Run this `mkdir b; touch a c; mv * b' in an empty
|
||||
directory. Here's the result of running echo `find b -print`:
|
||||
b b/a b/b b/b/a b/c. Notice that only file `a' was copied
|
||||
into b/b. Handle this by giving a diagnostic, removing the
|
||||
copied-into-self directory, DEST (`b/b' in the example),
|
||||
and failing. */
|
||||
{
|
||||
/* In general, when copy returns with copy_into_self set, SOURCE is
|
||||
the same as, or a parent of DEST. In this case we know it's a
|
||||
parent. It doesn't make sense to move a directory into itself, and
|
||||
besides in some situations doing so would give highly nonintuitive
|
||||
results. Run this `mkdir b; touch a c; mv * b' in an empty
|
||||
directory. Here's the result of running echo `find b -print`:
|
||||
b b/a b/b b/b/a b/c. Notice that only file `a' was copied
|
||||
into b/b. Handle this by giving a diagnostic, removing the
|
||||
copied-into-self directory, DEST (`b/b' in the example),
|
||||
and failing. */
|
||||
|
||||
dir_to_remove = NULL;
|
||||
ok = false;
|
||||
}
|
||||
dir_to_remove = NULL;
|
||||
ok = false;
|
||||
}
|
||||
else if (rename_succeeded)
|
||||
{
|
||||
/* No need to remove anything. SOURCE was successfully
|
||||
renamed to DEST. Or the user declined to rename a file. */
|
||||
dir_to_remove = NULL;
|
||||
}
|
||||
{
|
||||
/* No need to remove anything. SOURCE was successfully
|
||||
renamed to DEST. Or the user declined to rename a file. */
|
||||
dir_to_remove = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This may mean SOURCE and DEST referred to different devices.
|
||||
It may also conceivably mean that even though they referred
|
||||
to the same device, rename wasn't implemented for that device.
|
||||
{
|
||||
/* This may mean SOURCE and DEST referred to different devices.
|
||||
It may also conceivably mean that even though they referred
|
||||
to the same device, rename wasn't implemented for that device.
|
||||
|
||||
E.g., (from Joel N. Weber),
|
||||
[...] there might someday be cases where you can't rename
|
||||
but you can copy where the device name is the same, especially
|
||||
on Hurd. Consider an ftpfs with a primitive ftp server that
|
||||
supports uploading, downloading and deleting, but not renaming.
|
||||
E.g., (from Joel N. Weber),
|
||||
[...] there might someday be cases where you can't rename
|
||||
but you can copy where the device name is the same, especially
|
||||
on Hurd. Consider an ftpfs with a primitive ftp server that
|
||||
supports uploading, downloading and deleting, but not renaming.
|
||||
|
||||
Also, note that comparing device numbers is not a reliable
|
||||
check for `can-rename'. Some systems can be set up so that
|
||||
files from many different physical devices all have the same
|
||||
st_dev field. This is a feature of some NFS mounting
|
||||
configurations.
|
||||
Also, note that comparing device numbers is not a reliable
|
||||
check for `can-rename'. Some systems can be set up so that
|
||||
files from many different physical devices all have the same
|
||||
st_dev field. This is a feature of some NFS mounting
|
||||
configurations.
|
||||
|
||||
We reach this point if SOURCE has been successfully copied
|
||||
to DEST. Now we have to remove SOURCE.
|
||||
We reach this point if SOURCE has been successfully copied
|
||||
to DEST. Now we have to remove SOURCE.
|
||||
|
||||
This function used to resort to copying only when rename
|
||||
failed and set errno to EXDEV. */
|
||||
This function used to resort to copying only when rename
|
||||
failed and set errno to EXDEV. */
|
||||
|
||||
dir_to_remove = source;
|
||||
}
|
||||
dir_to_remove = source;
|
||||
}
|
||||
|
||||
if (dir_to_remove != NULL)
|
||||
{
|
||||
struct rm_options rm_options;
|
||||
enum RM_status status;
|
||||
{
|
||||
struct rm_options rm_options;
|
||||
enum RM_status status;
|
||||
|
||||
rm_option_init (&rm_options);
|
||||
rm_options.verbose = x->verbose;
|
||||
rm_option_init (&rm_options);
|
||||
rm_options.verbose = x->verbose;
|
||||
|
||||
status = rm (1, &dir_to_remove, &rm_options);
|
||||
assert (VALID_STATUS (status));
|
||||
if (status == RM_ERROR)
|
||||
ok = false;
|
||||
}
|
||||
status = rm (1, &dir_to_remove, &rm_options);
|
||||
assert (VALID_STATUS (status));
|
||||
if (status == RM_ERROR)
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
@@ -239,7 +239,7 @@ do_move (const char *source, const char *dest, const struct cp_options *x)
|
||||
|
||||
static bool
|
||||
movefile (char *source, char *dest, bool dest_is_dir,
|
||||
const struct cp_options *x)
|
||||
const struct cp_options *x)
|
||||
{
|
||||
bool ok;
|
||||
|
||||
@@ -275,7 +275,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -283,7 +283,7 @@ Usage: %s [OPTION]... [-T] SOURCE DEST\n\
|
||||
or: %s [OPTION]... SOURCE... DIRECTORY\n\
|
||||
or: %s [OPTION]... -t DIRECTORY SOURCE...\n\
|
||||
"),
|
||||
program_name, program_name, program_name);
|
||||
program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\
|
||||
\n\
|
||||
@@ -364,59 +364,59 @@ main (int argc, char **argv)
|
||||
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
|
||||
|
||||
while ((c = getopt_long (argc, argv, "bfint:uvS:T", long_options, NULL))
|
||||
!= -1)
|
||||
!= -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
make_backups = true;
|
||||
if (optarg)
|
||||
version_control_string = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
x.interactive = I_ALWAYS_YES;
|
||||
break;
|
||||
case 'i':
|
||||
x.interactive = I_ASK_USER;
|
||||
break;
|
||||
case 'n':
|
||||
x.interactive = I_ALWAYS_NO;
|
||||
break;
|
||||
case STRIP_TRAILING_SLASHES_OPTION:
|
||||
remove_trailing_slashes = true;
|
||||
break;
|
||||
case 't':
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0, _("multiple target directories specified"));
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat (optarg, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (optarg));
|
||||
}
|
||||
target_directory = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
no_target_directory = true;
|
||||
break;
|
||||
case 'u':
|
||||
x.update = true;
|
||||
break;
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
case 'S':
|
||||
make_backups = true;
|
||||
backup_suffix_string = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'b':
|
||||
make_backups = true;
|
||||
if (optarg)
|
||||
version_control_string = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
x.interactive = I_ALWAYS_YES;
|
||||
break;
|
||||
case 'i':
|
||||
x.interactive = I_ASK_USER;
|
||||
break;
|
||||
case 'n':
|
||||
x.interactive = I_ALWAYS_NO;
|
||||
break;
|
||||
case STRIP_TRAILING_SLASHES_OPTION:
|
||||
remove_trailing_slashes = true;
|
||||
break;
|
||||
case 't':
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0, _("multiple target directories specified"));
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat (optarg, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (optarg));
|
||||
}
|
||||
target_directory = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
no_target_directory = true;
|
||||
break;
|
||||
case 'u':
|
||||
x.update = true;
|
||||
break;
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
case 'S':
|
||||
make_backups = true;
|
||||
backup_suffix_string = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
n_files = argc - optind;
|
||||
@@ -425,39 +425,39 @@ main (int argc, char **argv)
|
||||
if (n_files <= !target_directory)
|
||||
{
|
||||
if (n_files <= 0)
|
||||
error (0, 0, _("missing file operand"));
|
||||
error (0, 0, _("missing file operand"));
|
||||
else
|
||||
error (0, 0, _("missing destination file operand after %s"),
|
||||
quote (file[0]));
|
||||
error (0, 0, _("missing destination file operand after %s"),
|
||||
quote (file[0]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (no_target_directory)
|
||||
{
|
||||
if (target_directory)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot combine --target-directory (-t) "
|
||||
"and --no-target-directory (-T)"));
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("cannot combine --target-directory (-t) "
|
||||
"and --no-target-directory (-T)"));
|
||||
if (2 < n_files)
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (file[2]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("extra operand %s"), quote (file[2]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if (!target_directory)
|
||||
{
|
||||
assert (2 <= n_files);
|
||||
if (target_directory_operand (file[n_files - 1]))
|
||||
target_directory = file[--n_files];
|
||||
target_directory = file[--n_files];
|
||||
else if (2 < n_files)
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (file[n_files - 1]));
|
||||
error (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
quote (file[n_files - 1]));
|
||||
}
|
||||
|
||||
if (make_backups && x.interactive == I_ALWAYS_NO)
|
||||
{
|
||||
error (0, 0,
|
||||
_("options --backup and --no-clobber are mutually exclusive"));
|
||||
_("options --backup and --no-clobber are mutually exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -465,9 +465,9 @@ main (int argc, char **argv)
|
||||
simple_backup_suffix = xstrdup (backup_suffix_string);
|
||||
|
||||
x.backup_type = (make_backups
|
||||
? xget_version (_("backup type"),
|
||||
version_control_string)
|
||||
: no_backups);
|
||||
? xget_version (_("backup type"),
|
||||
version_control_string)
|
||||
: no_backups);
|
||||
|
||||
hash_init ();
|
||||
|
||||
@@ -476,14 +476,14 @@ main (int argc, char **argv)
|
||||
int i;
|
||||
|
||||
/* Initialize the hash table only if we'll need it.
|
||||
The problem it is used to detect can arise only if there are
|
||||
two or more files to move. */
|
||||
The problem it is used to detect can arise only if there are
|
||||
two or more files to move. */
|
||||
if (2 <= n_files)
|
||||
dest_info_init (&x);
|
||||
dest_info_init (&x);
|
||||
|
||||
ok = true;
|
||||
for (i = 0; i < n_files; ++i)
|
||||
ok &= movefile (file[i], target_directory, true, &x);
|
||||
ok &= movefile (file[i], target_directory, true, &x);
|
||||
}
|
||||
else
|
||||
ok = movefile (file[0], file[1], false, &x);
|
||||
|
||||
+33
-33
@@ -66,7 +66,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION] [COMMAND [ARG]...]\n"), program_name);
|
||||
@@ -77,7 +77,7 @@ With no COMMAND, print the current niceness. Nicenesses range from\n\
|
||||
\n\
|
||||
-n, --adjustment=N add integer N to the niceness (default 10)\n\
|
||||
"),
|
||||
- NZERO, NZERO - 1);
|
||||
- NZERO, NZERO - 1);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
|
||||
@@ -105,66 +105,66 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
|
||||
for (i = 1; i < argc; /* empty */)
|
||||
{
|
||||
char const *s = argv[i];
|
||||
|
||||
if (s[0] == '-' && ISDIGIT (s[1 + (s[1] == '-' || s[1] == '+')]))
|
||||
{
|
||||
adjustment_given = s + 1;
|
||||
++i;
|
||||
}
|
||||
{
|
||||
adjustment_given = s + 1;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
int optc;
|
||||
int fake_argc = argc - (i - 1);
|
||||
char **fake_argv = argv + (i - 1);
|
||||
{
|
||||
int optc;
|
||||
int fake_argc = argc - (i - 1);
|
||||
char **fake_argv = argv + (i - 1);
|
||||
|
||||
/* Ensure that any getopt diagnostics use the right name. */
|
||||
fake_argv[0] = argv[0];
|
||||
/* Ensure that any getopt diagnostics use the right name. */
|
||||
fake_argv[0] = argv[0];
|
||||
|
||||
/* Initialize getopt_long's internal state. */
|
||||
optind = 0;
|
||||
/* Initialize getopt_long's internal state. */
|
||||
optind = 0;
|
||||
|
||||
optc = getopt_long (fake_argc, fake_argv, "+n:", longopts, NULL);
|
||||
i += optind - 1;
|
||||
optc = getopt_long (fake_argc, fake_argv, "+n:", longopts, NULL);
|
||||
i += optind - 1;
|
||||
|
||||
if (optc == '?')
|
||||
usage (EXIT_FAILURE);
|
||||
else if (optc == 'n')
|
||||
adjustment_given = optarg;
|
||||
else /* optc == -1 */
|
||||
break;
|
||||
}
|
||||
if (optc == '?')
|
||||
usage (EXIT_FAILURE);
|
||||
else if (optc == 'n')
|
||||
adjustment_given = optarg;
|
||||
else /* optc == -1 */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (adjustment_given)
|
||||
{
|
||||
/* If the requested adjustment is outside the valid range,
|
||||
silently bring it to just within range; this mimics what
|
||||
"setpriority" and "nice" do. */
|
||||
silently bring it to just within range; this mimics what
|
||||
"setpriority" and "nice" do. */
|
||||
enum { MIN_ADJUSTMENT = 1 - 2 * NZERO, MAX_ADJUSTMENT = 2 * NZERO - 1 };
|
||||
long int tmp;
|
||||
if (LONGINT_OVERFLOW < xstrtol (adjustment_given, NULL, 10, &tmp, ""))
|
||||
error (EXIT_FAILURE, 0, _("invalid adjustment %s"),
|
||||
quote (adjustment_given));
|
||||
error (EXIT_FAILURE, 0, _("invalid adjustment %s"),
|
||||
quote (adjustment_given));
|
||||
adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT));
|
||||
}
|
||||
|
||||
if (i == argc)
|
||||
{
|
||||
if (adjustment_given)
|
||||
{
|
||||
error (0, 0, _("a command must be given with an adjustment"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("a command must be given with an adjustment"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
/* No command given; print the niceness. */
|
||||
errno = 0;
|
||||
current_niceness = GET_NICENESS ();
|
||||
if (current_niceness == -1 && errno != 0)
|
||||
error (EXIT_FAILURE, errno, _("cannot get niceness"));
|
||||
error (EXIT_FAILURE, errno, _("cannot get niceness"));
|
||||
printf ("%d\n", current_niceness);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -176,13 +176,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Write each FILE to standard output, with line numbers added.\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n\
|
||||
@@ -241,7 +241,7 @@ FORMAT is one of:\n\
|
||||
|
||||
static bool
|
||||
build_type_arg (char const **typep,
|
||||
struct re_pattern_buffer *regexp, char *fastmap)
|
||||
struct re_pattern_buffer *regexp, char *fastmap)
|
||||
{
|
||||
char const *errmsg;
|
||||
bool rval = true;
|
||||
@@ -260,10 +260,10 @@ build_type_arg (char const **typep,
|
||||
regexp->fastmap = fastmap;
|
||||
regexp->translate = NULL;
|
||||
re_syntax_options =
|
||||
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
|
||||
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
|
||||
errmsg = re_compile_pattern (optarg, strlen (optarg), regexp);
|
||||
if (errmsg)
|
||||
error (EXIT_FAILURE, 0, "%s", errmsg);
|
||||
error (EXIT_FAILURE, 0, "%s", errmsg);
|
||||
break;
|
||||
default:
|
||||
rval = false;
|
||||
@@ -330,42 +330,42 @@ proc_text (void)
|
||||
{
|
||||
case 'a':
|
||||
if (blank_join > 1)
|
||||
{
|
||||
if (1 < line_buf.length || ++blank_lines == blank_join)
|
||||
{
|
||||
print_lineno ();
|
||||
blank_lines = 0;
|
||||
}
|
||||
else
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
}
|
||||
{
|
||||
if (1 < line_buf.length || ++blank_lines == blank_join)
|
||||
{
|
||||
print_lineno ();
|
||||
blank_lines = 0;
|
||||
}
|
||||
else
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
}
|
||||
else
|
||||
print_lineno ();
|
||||
print_lineno ();
|
||||
break;
|
||||
case 't':
|
||||
if (1 < line_buf.length)
|
||||
print_lineno ();
|
||||
print_lineno ();
|
||||
else
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
break;
|
||||
case 'n':
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
break;
|
||||
case 'p':
|
||||
switch (re_search (current_regex, line_buf.buffer, line_buf.length - 1,
|
||||
0, line_buf.length - 1, NULL))
|
||||
{
|
||||
case -2:
|
||||
error (EXIT_FAILURE, errno, _("error in regular expression search"));
|
||||
0, line_buf.length - 1, NULL))
|
||||
{
|
||||
case -2:
|
||||
error (EXIT_FAILURE, errno, _("error in regular expression search"));
|
||||
|
||||
case -1:
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
break;
|
||||
case -1:
|
||||
fputs (print_no_line_fmt, stdout);
|
||||
break;
|
||||
|
||||
default:
|
||||
print_lineno ();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
print_lineno ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
fwrite (line_buf.buffer, sizeof (char), line_buf.length, stdout);
|
||||
}
|
||||
@@ -399,20 +399,20 @@ process_file (FILE *fp)
|
||||
while (readlinebuffer (&line_buf, fp))
|
||||
{
|
||||
switch (check_section ())
|
||||
{
|
||||
case Header:
|
||||
proc_header ();
|
||||
break;
|
||||
case Body:
|
||||
proc_body ();
|
||||
break;
|
||||
case Footer:
|
||||
proc_footer ();
|
||||
break;
|
||||
case Text:
|
||||
proc_text ();
|
||||
break;
|
||||
}
|
||||
{
|
||||
case Header:
|
||||
proc_header ();
|
||||
break;
|
||||
case Body:
|
||||
proc_body ();
|
||||
break;
|
||||
case Footer:
|
||||
proc_footer ();
|
||||
break;
|
||||
case Text:
|
||||
proc_text ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,10 +433,10 @@ nl_file (char const *file)
|
||||
{
|
||||
stream = fopen (file, "r");
|
||||
if (stream == NULL)
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
process_file (stream);
|
||||
@@ -474,110 +474,110 @@ main (int argc, char **argv)
|
||||
have_read_stdin = false;
|
||||
|
||||
while ((c = getopt_long (argc, argv, "h:b:f:v:i:pl:s:w:n:d:", longopts,
|
||||
NULL)) != -1)
|
||||
NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'h':
|
||||
if (! build_type_arg (&header_type, &header_regex, header_fastmap))
|
||||
{
|
||||
error (0, 0, _("invalid header numbering style: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if (! build_type_arg (&body_type, &body_regex, body_fastmap))
|
||||
{
|
||||
error (0, 0, _("invalid body numbering style: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
if (! build_type_arg (&footer_type, &footer_regex, footer_fastmap))
|
||||
{
|
||||
error (0, 0, _("invalid footer numbering style: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
if (xstrtoimax (optarg, NULL, 10, &starting_line_number, "")
|
||||
!= LONGINT_OK)
|
||||
{
|
||||
error (0, 0, _("invalid starting line number: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
{
|
||||
case 'h':
|
||||
if (! build_type_arg (&header_type, &header_regex, header_fastmap))
|
||||
{
|
||||
error (0, 0, _("invalid header numbering style: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if (! build_type_arg (&body_type, &body_regex, body_fastmap))
|
||||
{
|
||||
error (0, 0, _("invalid body numbering style: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
if (! build_type_arg (&footer_type, &footer_regex, footer_fastmap))
|
||||
{
|
||||
error (0, 0, _("invalid footer numbering style: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
if (xstrtoimax (optarg, NULL, 10, &starting_line_number, "")
|
||||
!= LONGINT_OK)
|
||||
{
|
||||
error (0, 0, _("invalid starting line number: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case PAGE_INCREMENT_OPTION_DEPRECATED:
|
||||
error (0, 0, _("WARNING: --page-increment is deprecated; "
|
||||
"use --line-increment instead"));
|
||||
/* fall through */
|
||||
case 'i':
|
||||
if (! (xstrtoimax (optarg, NULL, 10, &page_incr, "") == LONGINT_OK
|
||||
&& 0 < page_incr))
|
||||
{
|
||||
error (0, 0, _("invalid line number increment: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
reset_numbers = false;
|
||||
break;
|
||||
case 'l':
|
||||
if (! (xstrtoimax (optarg, NULL, 10, &blank_join, "") == LONGINT_OK
|
||||
&& 0 < blank_join))
|
||||
{
|
||||
error (0, 0, _("invalid number of blank lines: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
separator_str = optarg;
|
||||
break;
|
||||
case 'w':
|
||||
{
|
||||
long int tmp_long;
|
||||
if (xstrtol (optarg, NULL, 10, &tmp_long, "") != LONGINT_OK
|
||||
|| tmp_long <= 0 || tmp_long > INT_MAX)
|
||||
{
|
||||
error (0, 0, _("invalid line number field width: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
lineno_width = tmp_long;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (STREQ (optarg, "ln"))
|
||||
lineno_format = FORMAT_LEFT;
|
||||
else if (STREQ (optarg, "rn"))
|
||||
lineno_format = FORMAT_RIGHT_NOLZ;
|
||||
else if (STREQ (optarg, "rz"))
|
||||
lineno_format = FORMAT_RIGHT_LZ;
|
||||
else
|
||||
{
|
||||
error (0, 0, _("invalid line numbering format: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
section_del = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
case 'i':
|
||||
if (! (xstrtoimax (optarg, NULL, 10, &page_incr, "") == LONGINT_OK
|
||||
&& 0 < page_incr))
|
||||
{
|
||||
error (0, 0, _("invalid line number increment: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
reset_numbers = false;
|
||||
break;
|
||||
case 'l':
|
||||
if (! (xstrtoimax (optarg, NULL, 10, &blank_join, "") == LONGINT_OK
|
||||
&& 0 < blank_join))
|
||||
{
|
||||
error (0, 0, _("invalid number of blank lines: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
separator_str = optarg;
|
||||
break;
|
||||
case 'w':
|
||||
{
|
||||
long int tmp_long;
|
||||
if (xstrtol (optarg, NULL, 10, &tmp_long, "") != LONGINT_OK
|
||||
|| tmp_long <= 0 || tmp_long > INT_MAX)
|
||||
{
|
||||
error (0, 0, _("invalid line number field width: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
lineno_width = tmp_long;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (STREQ (optarg, "ln"))
|
||||
lineno_format = FORMAT_LEFT;
|
||||
else if (STREQ (optarg, "rn"))
|
||||
lineno_format = FORMAT_RIGHT_NOLZ;
|
||||
else if (STREQ (optarg, "rz"))
|
||||
lineno_format = FORMAT_RIGHT_LZ;
|
||||
else
|
||||
{
|
||||
error (0, 0, _("invalid line numbering format: %s"),
|
||||
quote (optarg));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
section_del = optarg;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
|
||||
+45
-45
@@ -48,14 +48,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s COMMAND [ARG]...\n\
|
||||
or: %s OPTION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
|
||||
fputs (_("\
|
||||
Run COMMAND, ignoring hangup signals.\n\
|
||||
@@ -69,7 +69,7 @@ If standard output is a terminal, append output to `nohup.out' if possible,\n\
|
||||
`$HOME/nohup.out' otherwise.\n\
|
||||
If standard error is a terminal, redirect it to standard output.\n\
|
||||
To save output to FILE, use `%s COMMAND > FILE'.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
@@ -96,7 +96,7 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
|
||||
usage (NOHUP_FAILURE);
|
||||
|
||||
@@ -118,7 +118,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
fd_reopen (STDIN_FILENO, "/dev/null", O_WRONLY, 0);
|
||||
if (!redirecting_stdout && !redirecting_stderr)
|
||||
error (0, 0, _("ignoring input"));
|
||||
error (0, 0, _("ignoring input"));
|
||||
}
|
||||
|
||||
/* If standard output is a tty, redirect it (appending) to a file.
|
||||
@@ -133,38 +133,38 @@ main (int argc, char **argv)
|
||||
mode_t mode = S_IRUSR | S_IWUSR;
|
||||
mode_t umask_value = umask (~mode);
|
||||
out_fd = (redirecting_stdout
|
||||
? fd_reopen (STDOUT_FILENO, file, flags, mode)
|
||||
: open (file, flags, mode));
|
||||
? fd_reopen (STDOUT_FILENO, file, flags, mode)
|
||||
: open (file, flags, mode));
|
||||
|
||||
if (out_fd < 0)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
char const *home = getenv ("HOME");
|
||||
if (home)
|
||||
{
|
||||
in_home = file_name_concat (home, file, NULL);
|
||||
out_fd = (redirecting_stdout
|
||||
? fd_reopen (STDOUT_FILENO, in_home, flags, mode)
|
||||
: open (in_home, flags, mode));
|
||||
}
|
||||
if (out_fd < 0)
|
||||
{
|
||||
int saved_errno2 = errno;
|
||||
error (0, saved_errno, _("failed to open %s"), quote (file));
|
||||
if (in_home)
|
||||
error (0, saved_errno2, _("failed to open %s"),
|
||||
quote (in_home));
|
||||
exit (NOHUP_FAILURE);
|
||||
}
|
||||
file = in_home;
|
||||
}
|
||||
{
|
||||
int saved_errno = errno;
|
||||
char const *home = getenv ("HOME");
|
||||
if (home)
|
||||
{
|
||||
in_home = file_name_concat (home, file, NULL);
|
||||
out_fd = (redirecting_stdout
|
||||
? fd_reopen (STDOUT_FILENO, in_home, flags, mode)
|
||||
: open (in_home, flags, mode));
|
||||
}
|
||||
if (out_fd < 0)
|
||||
{
|
||||
int saved_errno2 = errno;
|
||||
error (0, saved_errno, _("failed to open %s"), quote (file));
|
||||
if (in_home)
|
||||
error (0, saved_errno2, _("failed to open %s"),
|
||||
quote (in_home));
|
||||
exit (NOHUP_FAILURE);
|
||||
}
|
||||
file = in_home;
|
||||
}
|
||||
|
||||
umask (umask_value);
|
||||
error (0, 0,
|
||||
_(ignoring_input
|
||||
? N_("ignoring input and appending output to %s")
|
||||
: N_("appending output to %s")),
|
||||
quote (file));
|
||||
_(ignoring_input
|
||||
? N_("ignoring input and appending output to %s")
|
||||
: N_("appending output to %s")),
|
||||
quote (file));
|
||||
free (in_home);
|
||||
}
|
||||
|
||||
@@ -172,27 +172,27 @@ main (int argc, char **argv)
|
||||
if (redirecting_stderr)
|
||||
{
|
||||
/* Save a copy of stderr before redirecting, so we can use the original
|
||||
if execve fails. It's no big deal if this dup fails. It might
|
||||
not change anything, and at worst, it'll lead to suppression of
|
||||
the post-failed-execve diagnostic. */
|
||||
if execve fails. It's no big deal if this dup fails. It might
|
||||
not change anything, and at worst, it'll lead to suppression of
|
||||
the post-failed-execve diagnostic. */
|
||||
saved_stderr_fd = dup (STDERR_FILENO);
|
||||
|
||||
if (0 <= saved_stderr_fd
|
||||
&& set_cloexec_flag (saved_stderr_fd, true) != 0)
|
||||
error (NOHUP_FAILURE, errno,
|
||||
_("failed to set the copy of stderr to close on exec"));
|
||||
&& set_cloexec_flag (saved_stderr_fd, true) != 0)
|
||||
error (NOHUP_FAILURE, errno,
|
||||
_("failed to set the copy of stderr to close on exec"));
|
||||
|
||||
if (!redirecting_stdout)
|
||||
error (0, 0,
|
||||
_(ignoring_input
|
||||
? N_("ignoring input and redirecting stderr to stdout")
|
||||
: N_("redirecting stderr to stdout")));
|
||||
error (0, 0,
|
||||
_(ignoring_input
|
||||
? N_("ignoring input and redirecting stderr to stdout")
|
||||
: N_("redirecting stderr to stdout")));
|
||||
|
||||
if (dup2 (out_fd, STDERR_FILENO) < 0)
|
||||
error (NOHUP_FAILURE, errno, _("failed to redirect standard error"));
|
||||
error (NOHUP_FAILURE, errno, _("failed to redirect standard error"));
|
||||
|
||||
if (stdout_is_closed)
|
||||
close (out_fd);
|
||||
close (out_fd);
|
||||
}
|
||||
|
||||
signal (SIGHUP, SIG_IGN);
|
||||
@@ -209,7 +209,7 @@ main (int argc, char **argv)
|
||||
/* The execve failed. Output a diagnostic to stderr only if:
|
||||
- stderr was initially redirected to a non-tty, or
|
||||
- stderr was initially directed to a tty, and we
|
||||
can dup2 it to point back to that same tty.
|
||||
can dup2 it to point back to that same tty.
|
||||
In other words, output the diagnostic if possible, but only if
|
||||
it will go to the original stderr. */
|
||||
if (dup2 (saved_stderr_fd, STDERR_FILENO) == STDERR_FILENO)
|
||||
|
||||
+212
-212
@@ -26,12 +26,12 @@
|
||||
Options:
|
||||
--serial
|
||||
-s Paste one file at a time rather than
|
||||
one line from each file.
|
||||
one line from each file.
|
||||
--delimiters=delim-list
|
||||
-d delim-list Consecutively use the characters in
|
||||
DELIM-LIST instead of tab to separate
|
||||
merged lines. When DELIM-LIST is exhausted,
|
||||
start again at its beginning.
|
||||
DELIM-LIST instead of tab to separate
|
||||
merged lines. When DELIM-LIST is exhausted,
|
||||
start again at its beginning.
|
||||
A FILE of `-' means standard input.
|
||||
If no FILEs are given, standard input is used. */
|
||||
|
||||
@@ -95,53 +95,53 @@ collapse_escapes (char const *strptr)
|
||||
while (*strptr)
|
||||
{
|
||||
if (*strptr != '\\') /* Is it an escape character? */
|
||||
*strout++ = *strptr++; /* No, just transfer it. */
|
||||
*strout++ = *strptr++; /* No, just transfer it. */
|
||||
else
|
||||
{
|
||||
switch (*++strptr)
|
||||
{
|
||||
case '0':
|
||||
*strout++ = EMPTY_DELIM;
|
||||
break;
|
||||
{
|
||||
switch (*++strptr)
|
||||
{
|
||||
case '0':
|
||||
*strout++ = EMPTY_DELIM;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
*strout++ = '\b';
|
||||
break;
|
||||
case 'b':
|
||||
*strout++ = '\b';
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
*strout++ = '\f';
|
||||
break;
|
||||
case 'f':
|
||||
*strout++ = '\f';
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
*strout++ = '\n';
|
||||
break;
|
||||
case 'n':
|
||||
*strout++ = '\n';
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
*strout++ = '\r';
|
||||
break;
|
||||
case 'r':
|
||||
*strout++ = '\r';
|
||||
break;
|
||||
|
||||
case 't':
|
||||
*strout++ = '\t';
|
||||
break;
|
||||
case 't':
|
||||
*strout++ = '\t';
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
*strout++ = '\v';
|
||||
break;
|
||||
case 'v':
|
||||
*strout++ = '\v';
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
*strout++ = '\\';
|
||||
break;
|
||||
case '\\':
|
||||
*strout++ = '\\';
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
backslash_at_end = true;
|
||||
goto done;
|
||||
case '\0':
|
||||
backslash_at_end = true;
|
||||
goto done;
|
||||
|
||||
default:
|
||||
*strout++ = *strptr;
|
||||
break;
|
||||
}
|
||||
strptr++;
|
||||
}
|
||||
default:
|
||||
*strout++ = *strptr;
|
||||
break;
|
||||
}
|
||||
strptr++;
|
||||
}
|
||||
}
|
||||
|
||||
done:;
|
||||
@@ -200,18 +200,18 @@ paste_parallel (size_t nfiles, char **fnamptr)
|
||||
for (files_open = 0; files_open < nfiles; ++files_open)
|
||||
{
|
||||
if (STREQ (fnamptr[files_open], "-"))
|
||||
{
|
||||
have_read_stdin = true;
|
||||
fileptr[files_open] = stdin;
|
||||
}
|
||||
{
|
||||
have_read_stdin = true;
|
||||
fileptr[files_open] = stdin;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileptr[files_open] = fopen (fnamptr[files_open], "r");
|
||||
if (fileptr[files_open] == NULL)
|
||||
error (EXIT_FAILURE, errno, "%s", fnamptr[files_open]);
|
||||
else if (fileno (fileptr[files_open]) == STDIN_FILENO)
|
||||
opened_stdin = true;
|
||||
}
|
||||
{
|
||||
fileptr[files_open] = fopen (fnamptr[files_open], "r");
|
||||
if (fileptr[files_open] == NULL)
|
||||
error (EXIT_FAILURE, errno, "%s", fnamptr[files_open]);
|
||||
else if (fileno (fileptr[files_open]) == STDIN_FILENO)
|
||||
opened_stdin = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (opened_stdin && have_read_stdin)
|
||||
@@ -230,107 +230,107 @@ paste_parallel (size_t nfiles, char **fnamptr)
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nfiles && files_open; i++)
|
||||
{
|
||||
int chr IF_LINT (= 0); /* Input character. */
|
||||
int err IF_LINT (= 0); /* Input errno value. */
|
||||
size_t line_length = 0; /* Number of chars in line. */
|
||||
{
|
||||
int chr IF_LINT (= 0); /* Input character. */
|
||||
int err IF_LINT (= 0); /* Input errno value. */
|
||||
size_t line_length = 0; /* Number of chars in line. */
|
||||
|
||||
if (fileptr[i])
|
||||
{
|
||||
chr = getc (fileptr[i]);
|
||||
err = errno;
|
||||
if (chr != EOF && delims_saved)
|
||||
{
|
||||
if (fwrite (delbuf, 1, delims_saved, stdout) != delims_saved)
|
||||
write_error ();
|
||||
delims_saved = 0;
|
||||
}
|
||||
if (fileptr[i])
|
||||
{
|
||||
chr = getc (fileptr[i]);
|
||||
err = errno;
|
||||
if (chr != EOF && delims_saved)
|
||||
{
|
||||
if (fwrite (delbuf, 1, delims_saved, stdout) != delims_saved)
|
||||
write_error ();
|
||||
delims_saved = 0;
|
||||
}
|
||||
|
||||
while (chr != EOF)
|
||||
{
|
||||
line_length++;
|
||||
if (chr == '\n')
|
||||
break;
|
||||
xputchar (chr);
|
||||
chr = getc (fileptr[i]);
|
||||
err = errno;
|
||||
}
|
||||
}
|
||||
while (chr != EOF)
|
||||
{
|
||||
line_length++;
|
||||
if (chr == '\n')
|
||||
break;
|
||||
xputchar (chr);
|
||||
chr = getc (fileptr[i]);
|
||||
err = errno;
|
||||
}
|
||||
}
|
||||
|
||||
if (line_length == 0)
|
||||
{
|
||||
/* EOF, read error, or closed file.
|
||||
If an EOF or error, close the file. */
|
||||
if (fileptr[i])
|
||||
{
|
||||
if (ferror (fileptr[i]))
|
||||
{
|
||||
error (0, err, "%s", fnamptr[i]);
|
||||
ok = false;
|
||||
}
|
||||
if (fileptr[i] == stdin)
|
||||
clearerr (fileptr[i]); /* Also clear EOF. */
|
||||
else if (fclose (fileptr[i]) == EOF)
|
||||
{
|
||||
error (0, errno, "%s", fnamptr[i]);
|
||||
ok = false;
|
||||
}
|
||||
if (line_length == 0)
|
||||
{
|
||||
/* EOF, read error, or closed file.
|
||||
If an EOF or error, close the file. */
|
||||
if (fileptr[i])
|
||||
{
|
||||
if (ferror (fileptr[i]))
|
||||
{
|
||||
error (0, err, "%s", fnamptr[i]);
|
||||
ok = false;
|
||||
}
|
||||
if (fileptr[i] == stdin)
|
||||
clearerr (fileptr[i]); /* Also clear EOF. */
|
||||
else if (fclose (fileptr[i]) == EOF)
|
||||
{
|
||||
error (0, errno, "%s", fnamptr[i]);
|
||||
ok = false;
|
||||
}
|
||||
|
||||
fileptr[i] = NULL;
|
||||
files_open--;
|
||||
}
|
||||
fileptr[i] = NULL;
|
||||
files_open--;
|
||||
}
|
||||
|
||||
if (i + 1 == nfiles)
|
||||
{
|
||||
/* End of this output line.
|
||||
Is this the end of the whole thing? */
|
||||
if (somedone)
|
||||
{
|
||||
/* No. Some files were not closed for this line. */
|
||||
if (delims_saved)
|
||||
{
|
||||
if (fwrite (delbuf, 1, delims_saved, stdout)
|
||||
!= delims_saved)
|
||||
write_error ();
|
||||
delims_saved = 0;
|
||||
}
|
||||
xputchar ('\n');
|
||||
}
|
||||
continue; /* Next read of files, or exit. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Closed file; add delimiter to `delbuf'. */
|
||||
if (*delimptr != EMPTY_DELIM)
|
||||
delbuf[delims_saved++] = *delimptr;
|
||||
if (++delimptr == delim_end)
|
||||
delimptr = delims;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Some data read. */
|
||||
somedone = true;
|
||||
if (i + 1 == nfiles)
|
||||
{
|
||||
/* End of this output line.
|
||||
Is this the end of the whole thing? */
|
||||
if (somedone)
|
||||
{
|
||||
/* No. Some files were not closed for this line. */
|
||||
if (delims_saved)
|
||||
{
|
||||
if (fwrite (delbuf, 1, delims_saved, stdout)
|
||||
!= delims_saved)
|
||||
write_error ();
|
||||
delims_saved = 0;
|
||||
}
|
||||
xputchar ('\n');
|
||||
}
|
||||
continue; /* Next read of files, or exit. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Closed file; add delimiter to `delbuf'. */
|
||||
if (*delimptr != EMPTY_DELIM)
|
||||
delbuf[delims_saved++] = *delimptr;
|
||||
if (++delimptr == delim_end)
|
||||
delimptr = delims;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Some data read. */
|
||||
somedone = true;
|
||||
|
||||
/* Except for last file, replace last newline with delim. */
|
||||
if (i + 1 != nfiles)
|
||||
{
|
||||
if (chr != '\n' && chr != EOF)
|
||||
xputchar (chr);
|
||||
if (*delimptr != EMPTY_DELIM)
|
||||
xputchar (*delimptr);
|
||||
if (++delimptr == delim_end)
|
||||
delimptr = delims;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If the last line of the last file lacks a newline,
|
||||
print one anyhow. POSIX requires this. */
|
||||
char c = (chr == EOF ? '\n' : chr);
|
||||
xputchar (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Except for last file, replace last newline with delim. */
|
||||
if (i + 1 != nfiles)
|
||||
{
|
||||
if (chr != '\n' && chr != EOF)
|
||||
xputchar (chr);
|
||||
if (*delimptr != EMPTY_DELIM)
|
||||
xputchar (*delimptr);
|
||||
if (++delimptr == delim_end)
|
||||
delimptr = delims;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If the last line of the last file lacks a newline,
|
||||
print one anyhow. POSIX requires this. */
|
||||
char c = (chr == EOF ? '\n' : chr);
|
||||
xputchar (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free (fileptr);
|
||||
free (delbuf);
|
||||
@@ -354,70 +354,70 @@ paste_serial (size_t nfiles, char **fnamptr)
|
||||
int saved_errno;
|
||||
bool is_stdin = STREQ (*fnamptr, "-");
|
||||
if (is_stdin)
|
||||
{
|
||||
have_read_stdin = true;
|
||||
fileptr = stdin;
|
||||
}
|
||||
{
|
||||
have_read_stdin = true;
|
||||
fileptr = stdin;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileptr = fopen (*fnamptr, "r");
|
||||
if (fileptr == NULL)
|
||||
{
|
||||
error (0, errno, "%s", *fnamptr);
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
{
|
||||
fileptr = fopen (*fnamptr, "r");
|
||||
if (fileptr == NULL)
|
||||
{
|
||||
error (0, errno, "%s", *fnamptr);
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
delimptr = delims; /* Set up for delimiter string. */
|
||||
|
||||
charold = getc (fileptr);
|
||||
saved_errno = errno;
|
||||
if (charold != EOF)
|
||||
{
|
||||
/* `charold' is set up. Hit it!
|
||||
Keep reading characters, stashing them in `charnew';
|
||||
output `charold', converting to the appropriate delimiter
|
||||
character if needed. After the EOF, output `charold'
|
||||
if it's a newline; otherwise, output it and then a newline. */
|
||||
{
|
||||
/* `charold' is set up. Hit it!
|
||||
Keep reading characters, stashing them in `charnew';
|
||||
output `charold', converting to the appropriate delimiter
|
||||
character if needed. After the EOF, output `charold'
|
||||
if it's a newline; otherwise, output it and then a newline. */
|
||||
|
||||
while ((charnew = getc (fileptr)) != EOF)
|
||||
{
|
||||
/* Process the old character. */
|
||||
if (charold == '\n')
|
||||
{
|
||||
if (*delimptr != EMPTY_DELIM)
|
||||
xputchar (*delimptr);
|
||||
while ((charnew = getc (fileptr)) != EOF)
|
||||
{
|
||||
/* Process the old character. */
|
||||
if (charold == '\n')
|
||||
{
|
||||
if (*delimptr != EMPTY_DELIM)
|
||||
xputchar (*delimptr);
|
||||
|
||||
if (++delimptr == delim_end)
|
||||
delimptr = delims;
|
||||
}
|
||||
else
|
||||
xputchar (charold);
|
||||
if (++delimptr == delim_end)
|
||||
delimptr = delims;
|
||||
}
|
||||
else
|
||||
xputchar (charold);
|
||||
|
||||
charold = charnew;
|
||||
}
|
||||
saved_errno = errno;
|
||||
charold = charnew;
|
||||
}
|
||||
saved_errno = errno;
|
||||
|
||||
/* Hit EOF. Process that last character. */
|
||||
xputchar (charold);
|
||||
}
|
||||
/* Hit EOF. Process that last character. */
|
||||
xputchar (charold);
|
||||
}
|
||||
|
||||
if (charold != '\n')
|
||||
xputchar ('\n');
|
||||
xputchar ('\n');
|
||||
|
||||
if (ferror (fileptr))
|
||||
{
|
||||
error (0, saved_errno, "%s", *fnamptr);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
error (0, saved_errno, "%s", *fnamptr);
|
||||
ok = false;
|
||||
}
|
||||
if (is_stdin)
|
||||
clearerr (fileptr); /* Also clear EOF. */
|
||||
clearerr (fileptr); /* Also clear EOF. */
|
||||
else if (fclose (fileptr) == EOF)
|
||||
{
|
||||
error (0, errno, "%s", *fnamptr);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", *fnamptr);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -427,13 +427,13 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [FILE]...\n\
|
||||
"),
|
||||
program_name);
|
||||
program_name);
|
||||
fputs (_("\
|
||||
Write lines consisting of the sequentially corresponding lines from\n\
|
||||
each FILE, separated by TABs, to standard output.\n\
|
||||
@@ -476,23 +476,23 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "d:s", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'd':
|
||||
/* Delimiter character(s). */
|
||||
delim_arg = (optarg[0] == '\0' ? "\\0" : optarg);
|
||||
break;
|
||||
{
|
||||
case 'd':
|
||||
/* Delimiter character(s). */
|
||||
delim_arg = (optarg[0] == '\0' ? "\\0" : optarg);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
serial_merge = true;
|
||||
break;
|
||||
case 's':
|
||||
serial_merge = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
@@ -501,11 +501,11 @@ main (int argc, char **argv)
|
||||
if (collapse_escapes (delim_arg))
|
||||
{
|
||||
/* Don't use the default quoting style, because that would double the
|
||||
number of displayed backslashes, making the diagnostic look bogus. */
|
||||
number of displayed backslashes, making the diagnostic look bogus. */
|
||||
set_quoting_style (NULL, escape_quoting_style);
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("delimiter list ends with an unescaped backslash: %s"),
|
||||
quotearg_colon (delim_arg));
|
||||
_("delimiter list ends with an unescaped backslash: %s"),
|
||||
quotearg_colon (delim_arg));
|
||||
}
|
||||
|
||||
if (!serial_merge)
|
||||
|
||||
+122
-122
@@ -91,7 +91,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... NAME...\n"), program_name);
|
||||
@@ -128,27 +128,27 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "+pP", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case PORTABILITY_OPTION:
|
||||
check_basic_portability = true;
|
||||
check_extra_portability = true;
|
||||
break;
|
||||
{
|
||||
case PORTABILITY_OPTION:
|
||||
check_basic_portability = true;
|
||||
check_extra_portability = true;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
check_basic_portability = true;
|
||||
break;
|
||||
case 'p':
|
||||
check_basic_portability = true;
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
check_extra_portability = true;
|
||||
break;
|
||||
case 'P':
|
||||
check_extra_portability = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
@@ -159,7 +159,7 @@ main (int argc, char **argv)
|
||||
|
||||
for (; optind < argc; ++optind)
|
||||
ok &= validate_file_name (argv[optind],
|
||||
check_basic_portability, check_extra_portability);
|
||||
check_basic_portability, check_extra_portability);
|
||||
|
||||
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
@@ -175,9 +175,9 @@ no_leading_hyphen (char const *file)
|
||||
for (p = file; (p = strchr (p, '-')); p++)
|
||||
if (p == file || p[-1] == '/')
|
||||
{
|
||||
error (0, 0, _("leading `-' in a component of file name %s"),
|
||||
quote (file));
|
||||
return false;
|
||||
error (0, 0, _("leading `-' in a component of file name %s"),
|
||||
quote (file));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -190,10 +190,10 @@ static bool
|
||||
portable_chars_only (char const *file, size_t filelen)
|
||||
{
|
||||
size_t validlen = strspn (file,
|
||||
("/"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789._-"));
|
||||
("/"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789._-"));
|
||||
char const *invalid = file + validlen;
|
||||
|
||||
if (*invalid)
|
||||
@@ -201,10 +201,10 @@ portable_chars_only (char const *file, size_t filelen)
|
||||
DECLARE_ZEROED_AGGREGATE (mbstate_t, mbstate);
|
||||
size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate);
|
||||
error (0, 0,
|
||||
_("nonportable character %s in file name %s"),
|
||||
quotearg_n_style_mem (1, locale_quoting_style, invalid,
|
||||
(charlen <= MB_LEN_MAX ? charlen : 1)),
|
||||
quote_n (0, file));
|
||||
_("nonportable character %s in file name %s"),
|
||||
quotearg_n_style_mem (1, locale_quoting_style, invalid,
|
||||
(charlen <= MB_LEN_MAX ? charlen : 1)),
|
||||
quote_n (0, file));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ component_len (char const *f)
|
||||
|
||||
static bool
|
||||
validate_file_name (char *file, bool check_basic_portability,
|
||||
bool check_extra_portability)
|
||||
bool check_extra_portability)
|
||||
{
|
||||
size_t filelen = strlen (file);
|
||||
|
||||
@@ -274,9 +274,9 @@ validate_file_name (char *file, bool check_basic_portability,
|
||||
&& filelen == 0)
|
||||
{
|
||||
/* Fail, since empty names are not portable. As of
|
||||
2005-01-06 POSIX does not address whether "pathchk -p ''"
|
||||
should (or is allowed to) fail, so this is not a
|
||||
conformance violation. */
|
||||
2005-01-06 POSIX does not address whether "pathchk -p ''"
|
||||
should (or is allowed to) fail, so this is not a
|
||||
conformance violation. */
|
||||
error (0, 0, _("empty file name"));
|
||||
return false;
|
||||
}
|
||||
@@ -284,23 +284,23 @@ validate_file_name (char *file, bool check_basic_portability,
|
||||
if (check_basic_portability)
|
||||
{
|
||||
if (! portable_chars_only (file, filelen))
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check whether a file name component is in a directory that
|
||||
is not searchable, or has some other serious problem.
|
||||
POSIX does not allow "" as a file name, but some non-POSIX
|
||||
hosts do (as an alias for "."), so allow "" if lstat does. */
|
||||
is not searchable, or has some other serious problem.
|
||||
POSIX does not allow "" as a file name, but some non-POSIX
|
||||
hosts do (as an alias for "."), so allow "" if lstat does. */
|
||||
|
||||
struct stat st;
|
||||
if (lstat (file, &st) == 0)
|
||||
file_exists = true;
|
||||
file_exists = true;
|
||||
else if (errno != ENOENT || filelen == 0)
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
error (0, errno, "%s", file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (check_basic_portability
|
||||
@@ -309,31 +309,31 @@ validate_file_name (char *file, bool check_basic_portability,
|
||||
size_t maxsize;
|
||||
|
||||
if (check_basic_portability)
|
||||
maxsize = _POSIX_PATH_MAX;
|
||||
maxsize = _POSIX_PATH_MAX;
|
||||
else
|
||||
{
|
||||
long int size;
|
||||
char const *dir = (*file == '/' ? "/" : ".");
|
||||
errno = 0;
|
||||
size = pathconf (dir, _PC_PATH_MAX);
|
||||
if (size < 0 && errno != 0)
|
||||
{
|
||||
error (0, errno,
|
||||
_("%s: unable to determine maximum file name length"),
|
||||
dir);
|
||||
return false;
|
||||
}
|
||||
maxsize = MIN (size, SSIZE_MAX);
|
||||
}
|
||||
{
|
||||
long int size;
|
||||
char const *dir = (*file == '/' ? "/" : ".");
|
||||
errno = 0;
|
||||
size = pathconf (dir, _PC_PATH_MAX);
|
||||
if (size < 0 && errno != 0)
|
||||
{
|
||||
error (0, errno,
|
||||
_("%s: unable to determine maximum file name length"),
|
||||
dir);
|
||||
return false;
|
||||
}
|
||||
maxsize = MIN (size, SSIZE_MAX);
|
||||
}
|
||||
|
||||
if (maxsize <= filelen)
|
||||
{
|
||||
unsigned long int len = filelen;
|
||||
unsigned long int maxlen = maxsize - 1;
|
||||
error (0, 0, _("limit %lu exceeded by length %lu of file name %s"),
|
||||
maxlen, len, quote (file));
|
||||
return false;
|
||||
}
|
||||
{
|
||||
unsigned long int len = filelen;
|
||||
unsigned long int maxlen = maxsize - 1;
|
||||
error (0, 0, _("limit %lu exceeded by length %lu of file name %s"),
|
||||
maxlen, len, quote (file));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check whether pathconf (..., _PC_NAME_MAX) can be avoided, i.e.,
|
||||
@@ -345,17 +345,17 @@ validate_file_name (char *file, bool check_basic_portability,
|
||||
if (! check_component_lengths && ! file_exists)
|
||||
{
|
||||
for (start = file; *(start = component_start (start)); )
|
||||
{
|
||||
size_t length = component_len (start);
|
||||
{
|
||||
size_t length = component_len (start);
|
||||
|
||||
if (NAME_MAX_MINIMUM < length)
|
||||
{
|
||||
check_component_lengths = true;
|
||||
break;
|
||||
}
|
||||
if (NAME_MAX_MINIMUM < length)
|
||||
{
|
||||
check_component_lengths = true;
|
||||
break;
|
||||
}
|
||||
|
||||
start += length;
|
||||
}
|
||||
start += length;
|
||||
}
|
||||
}
|
||||
|
||||
if (check_component_lengths)
|
||||
@@ -370,61 +370,61 @@ validate_file_name (char *file, bool check_basic_portability,
|
||||
size_t known_name_max = (check_basic_portability ? _POSIX_NAME_MAX : 0);
|
||||
|
||||
for (start = file; *(start = component_start (start)); )
|
||||
{
|
||||
size_t length;
|
||||
{
|
||||
size_t length;
|
||||
|
||||
if (known_name_max)
|
||||
name_max = known_name_max;
|
||||
else
|
||||
{
|
||||
long int len;
|
||||
char const *dir = (start == file ? "." : file);
|
||||
char c = *start;
|
||||
errno = 0;
|
||||
*start = '\0';
|
||||
len = pathconf (dir, _PC_NAME_MAX);
|
||||
*start = c;
|
||||
if (0 <= len)
|
||||
name_max = MIN (len, SSIZE_MAX);
|
||||
else
|
||||
switch (errno)
|
||||
{
|
||||
case 0:
|
||||
/* There is no limit. */
|
||||
name_max = SIZE_MAX;
|
||||
break;
|
||||
if (known_name_max)
|
||||
name_max = known_name_max;
|
||||
else
|
||||
{
|
||||
long int len;
|
||||
char const *dir = (start == file ? "." : file);
|
||||
char c = *start;
|
||||
errno = 0;
|
||||
*start = '\0';
|
||||
len = pathconf (dir, _PC_NAME_MAX);
|
||||
*start = c;
|
||||
if (0 <= len)
|
||||
name_max = MIN (len, SSIZE_MAX);
|
||||
else
|
||||
switch (errno)
|
||||
{
|
||||
case 0:
|
||||
/* There is no limit. */
|
||||
name_max = SIZE_MAX;
|
||||
break;
|
||||
|
||||
case ENOENT:
|
||||
/* DIR does not exist; use its parent's maximum. */
|
||||
known_name_max = name_max;
|
||||
break;
|
||||
case ENOENT:
|
||||
/* DIR does not exist; use its parent's maximum. */
|
||||
known_name_max = name_max;
|
||||
break;
|
||||
|
||||
default:
|
||||
*start = '\0';
|
||||
error (0, errno, "%s", dir);
|
||||
*start = c;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
default:
|
||||
*start = '\0';
|
||||
error (0, errno, "%s", dir);
|
||||
*start = c;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
length = component_len (start);
|
||||
length = component_len (start);
|
||||
|
||||
if (name_max < length)
|
||||
{
|
||||
unsigned long int len = length;
|
||||
unsigned long int maxlen = name_max;
|
||||
char c = start[len];
|
||||
start[len] = '\0';
|
||||
error (0, 0,
|
||||
_("limit %lu exceeded by length %lu "
|
||||
"of file name component %s"),
|
||||
maxlen, len, quote (start));
|
||||
start[len] = c;
|
||||
return false;
|
||||
}
|
||||
if (name_max < length)
|
||||
{
|
||||
unsigned long int len = length;
|
||||
unsigned long int maxlen = name_max;
|
||||
char c = start[len];
|
||||
start[len] = '\0';
|
||||
error (0, 0,
|
||||
_("limit %lu exceeded by length %lu "
|
||||
"of file name component %s"),
|
||||
maxlen, len, quote (start));
|
||||
start[len] = c;
|
||||
return false;
|
||||
}
|
||||
|
||||
start += length;
|
||||
}
|
||||
start += length;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+103
-103
@@ -92,7 +92,7 @@ count_ampersands (const char *str)
|
||||
do
|
||||
{
|
||||
if (*str == '&')
|
||||
count++;
|
||||
count++;
|
||||
} while (*str++);
|
||||
return count;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ create_fullname (const char *gecos_name, const char *user_name)
|
||||
size_t product = ampersands * ulen;
|
||||
rsize += product - ampersands;
|
||||
if (xalloc_oversized (ulen, ampersands) || rsize < product)
|
||||
xalloc_die ();
|
||||
xalloc_die ();
|
||||
}
|
||||
|
||||
r = result = xmalloc (rsize);
|
||||
@@ -125,17 +125,17 @@ create_fullname (const char *gecos_name, const char *user_name)
|
||||
while (*gecos_name)
|
||||
{
|
||||
if (*gecos_name == '&')
|
||||
{
|
||||
const char *uname = user_name;
|
||||
if (islower (to_uchar (*uname)))
|
||||
*r++ = toupper (to_uchar (*uname++));
|
||||
while (*uname)
|
||||
*r++ = *uname++;
|
||||
}
|
||||
{
|
||||
const char *uname = user_name;
|
||||
if (islower (to_uchar (*uname)))
|
||||
*r++ = toupper (to_uchar (*uname++));
|
||||
while (*uname)
|
||||
*r++ = *uname++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*r++ = *gecos_name;
|
||||
}
|
||||
{
|
||||
*r++ = *gecos_name;
|
||||
}
|
||||
|
||||
gecos_name++;
|
||||
}
|
||||
@@ -249,32 +249,32 @@ print_entry (const STRUCT_UTMP *utmp_ent)
|
||||
name[UT_USER_SIZE] = '\0';
|
||||
pw = getpwnam (name);
|
||||
if (pw == NULL)
|
||||
/* TRANSLATORS: Real name is unknown; at most 19 characters. */
|
||||
printf (" %19s", _(" ???"));
|
||||
/* TRANSLATORS: Real name is unknown; at most 19 characters. */
|
||||
printf (" %19s", _(" ???"));
|
||||
else
|
||||
{
|
||||
char *const comma = strchr (pw->pw_gecos, ',');
|
||||
char *result;
|
||||
{
|
||||
char *const comma = strchr (pw->pw_gecos, ',');
|
||||
char *result;
|
||||
|
||||
if (comma)
|
||||
*comma = '\0';
|
||||
if (comma)
|
||||
*comma = '\0';
|
||||
|
||||
result = create_fullname (pw->pw_gecos, pw->pw_name);
|
||||
printf (" %-19.19s", result);
|
||||
free (result);
|
||||
}
|
||||
result = create_fullname (pw->pw_gecos, pw->pw_name);
|
||||
printf (" %-19.19s", result);
|
||||
free (result);
|
||||
}
|
||||
}
|
||||
|
||||
printf (" %c%-8.*s",
|
||||
mesg, (int) sizeof (utmp_ent->ut_line), utmp_ent->ut_line);
|
||||
mesg, (int) sizeof (utmp_ent->ut_line), utmp_ent->ut_line);
|
||||
|
||||
if (include_idle)
|
||||
{
|
||||
if (last_change)
|
||||
printf (" %-6s", idle_string (last_change));
|
||||
printf (" %-6s", idle_string (last_change));
|
||||
else
|
||||
/* TRANSLATORS: Idle time is unknown; at most 5 characters. */
|
||||
printf (" %-6s", _("?????"));
|
||||
/* TRANSLATORS: Idle time is unknown; at most 5 characters. */
|
||||
printf (" %-6s", _("?????"));
|
||||
}
|
||||
|
||||
printf (" %s", time_string (utmp_ent));
|
||||
@@ -293,21 +293,21 @@ print_entry (const STRUCT_UTMP *utmp_ent)
|
||||
/* Look for an X display. */
|
||||
display = strchr (ut_host, ':');
|
||||
if (display)
|
||||
*display++ = '\0';
|
||||
*display++ = '\0';
|
||||
|
||||
if (*ut_host)
|
||||
/* See if we can canonicalize it. */
|
||||
host = canon_host (ut_host);
|
||||
/* See if we can canonicalize it. */
|
||||
host = canon_host (ut_host);
|
||||
if ( ! host)
|
||||
host = ut_host;
|
||||
host = ut_host;
|
||||
|
||||
if (display)
|
||||
printf (" %s:%s", host, display);
|
||||
printf (" %s:%s", host, display);
|
||||
else
|
||||
printf (" %s", host);
|
||||
printf (" %s", host);
|
||||
|
||||
if (host != ut_host)
|
||||
free (host);
|
||||
free (host);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -339,7 +339,7 @@ print_long_entry (const char name[])
|
||||
char *result;
|
||||
|
||||
if (comma)
|
||||
*comma = '\0';
|
||||
*comma = '\0';
|
||||
|
||||
result = create_fullname (pw->pw_gecos, pw->pw_name);
|
||||
printf (" %s", result);
|
||||
@@ -368,15 +368,15 @@ print_long_entry (const char name[])
|
||||
|
||||
stream = fopen (project, "r");
|
||||
if (stream)
|
||||
{
|
||||
size_t bytes;
|
||||
{
|
||||
size_t bytes;
|
||||
|
||||
printf (_("Project: "));
|
||||
printf (_("Project: "));
|
||||
|
||||
while ((bytes = fread (buf, 1, sizeof (buf), stream)) > 0)
|
||||
fwrite (buf, 1, bytes, stdout);
|
||||
fclose (stream);
|
||||
}
|
||||
while ((bytes = fread (buf, 1, sizeof (buf), stream)) > 0)
|
||||
fwrite (buf, 1, bytes, stdout);
|
||||
fclose (stream);
|
||||
}
|
||||
|
||||
free (project);
|
||||
}
|
||||
@@ -392,15 +392,15 @@ print_long_entry (const char name[])
|
||||
|
||||
stream = fopen (plan, "r");
|
||||
if (stream)
|
||||
{
|
||||
size_t bytes;
|
||||
{
|
||||
size_t bytes;
|
||||
|
||||
printf (_("Plan:\n"));
|
||||
printf (_("Plan:\n"));
|
||||
|
||||
while ((bytes = fread (buf, 1, sizeof (buf), stream)) > 0)
|
||||
fwrite (buf, 1, bytes, stdout);
|
||||
fclose (stream);
|
||||
}
|
||||
while ((bytes = fread (buf, 1, sizeof (buf), stream)) > 0)
|
||||
fwrite (buf, 1, bytes, stdout);
|
||||
fclose (stream);
|
||||
}
|
||||
|
||||
free (plan);
|
||||
}
|
||||
@@ -432,7 +432,7 @@ print_heading (void)
|
||||
|
||||
static void
|
||||
scan_entries (size_t n, const STRUCT_UTMP *utmp_buf,
|
||||
const int argc_names, char *const argv_names[])
|
||||
const int argc_names, char *const argv_names[])
|
||||
{
|
||||
if (hard_locale (LC_TIME))
|
||||
{
|
||||
@@ -451,22 +451,22 @@ scan_entries (size_t n, const STRUCT_UTMP *utmp_buf,
|
||||
while (n--)
|
||||
{
|
||||
if (IS_USER_PROCESS (utmp_buf))
|
||||
{
|
||||
if (argc_names)
|
||||
{
|
||||
int i;
|
||||
{
|
||||
if (argc_names)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < argc_names; i++)
|
||||
if (strncmp (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE)
|
||||
== 0)
|
||||
{
|
||||
print_entry (utmp_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
print_entry (utmp_buf);
|
||||
}
|
||||
for (i = 0; i < argc_names; i++)
|
||||
if (strncmp (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE)
|
||||
== 0)
|
||||
{
|
||||
print_entry (utmp_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
print_entry (utmp_buf);
|
||||
}
|
||||
utmp_buf++;
|
||||
}
|
||||
}
|
||||
@@ -475,7 +475,7 @@ scan_entries (size_t n, const STRUCT_UTMP *utmp_buf,
|
||||
|
||||
static void
|
||||
short_pinky (const char *filename,
|
||||
const int argc_names, char *const argv_names[])
|
||||
const int argc_names, char *const argv_names[])
|
||||
{
|
||||
size_t n_users;
|
||||
STRUCT_UTMP *utmp_buf;
|
||||
@@ -500,7 +500,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... [USER]...\n"), program_name);
|
||||
@@ -548,57 +548,57 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 's':
|
||||
do_short_format = true;
|
||||
break;
|
||||
{
|
||||
case 's':
|
||||
do_short_format = true;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
do_short_format = false;
|
||||
break;
|
||||
case 'l':
|
||||
do_short_format = false;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
include_heading = false;
|
||||
break;
|
||||
case 'f':
|
||||
include_heading = false;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
include_fullname = false;
|
||||
break;
|
||||
case 'w':
|
||||
include_fullname = false;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
include_fullname = false;
|
||||
case 'i':
|
||||
include_fullname = false;
|
||||
#ifdef HAVE_UT_HOST
|
||||
include_where = false;
|
||||
include_where = false;
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
include_fullname = false;
|
||||
case 'q':
|
||||
include_fullname = false;
|
||||
#ifdef HAVE_UT_HOST
|
||||
include_where = false;
|
||||
include_where = false;
|
||||
#endif
|
||||
include_idle = false;
|
||||
break;
|
||||
include_idle = false;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
include_project = false;
|
||||
break;
|
||||
case 'h':
|
||||
include_project = false;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
include_plan = false;
|
||||
break;
|
||||
case 'p':
|
||||
include_plan = false;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
include_home_and_shell = false;
|
||||
break;
|
||||
case 'b':
|
||||
include_home_and_shell = false;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
n_users = argc - optind;
|
||||
|
||||
+22
-22
@@ -52,7 +52,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -62,7 +62,7 @@ Print the values of the specified environment VARIABLE(s).\n\
|
||||
If no VARIABLE is specified, print name and value pairs for them all.\n\
|
||||
\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
|
||||
@@ -89,14 +89,14 @@ main (int argc, char **argv)
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
|
||||
usage (PRINTENV_FAILURE);
|
||||
|
||||
if (optind >= argc)
|
||||
{
|
||||
for (env = environ; *env != NULL; ++env)
|
||||
puts (*env);
|
||||
puts (*env);
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
@@ -104,26 +104,26 @@ main (int argc, char **argv)
|
||||
int matches = 0;
|
||||
|
||||
for (i = optind; i < argc; ++i)
|
||||
{
|
||||
bool matched = false;
|
||||
{
|
||||
bool matched = false;
|
||||
|
||||
for (env = environ; *env; ++env)
|
||||
{
|
||||
ep = *env;
|
||||
ap = argv[i];
|
||||
while (*ep != '\0' && *ap != '\0' && *ep++ == *ap++)
|
||||
{
|
||||
if (*ep == '=' && *ap == '\0')
|
||||
{
|
||||
puts (ep + 1);
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (env = environ; *env; ++env)
|
||||
{
|
||||
ep = *env;
|
||||
ap = argv[i];
|
||||
while (*ep != '\0' && *ap != '\0' && *ep++ == *ap++)
|
||||
{
|
||||
if (*ep == '=' && *ap == '\0')
|
||||
{
|
||||
puts (ep + 1);
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matches += matched;
|
||||
}
|
||||
matches += matched;
|
||||
}
|
||||
|
||||
ok = (matches == argc - optind);
|
||||
}
|
||||
|
||||
+245
-245
@@ -63,7 +63,7 @@
|
||||
|
||||
#define isodigit(c) ((c) >= '0' && (c) <= '7')
|
||||
#define hextobin(c) ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
|
||||
(c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
|
||||
(c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
|
||||
#define octtobin(c) ((c) - '0')
|
||||
|
||||
/* The value to return to the calling program. */
|
||||
@@ -82,14 +82,14 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s FORMAT [ARGUMENT]...\n\
|
||||
or: %s OPTION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
Print ARGUMENT(s) according to FORMAT, or execute according to OPTION:\n\
|
||||
\n\
|
||||
@@ -146,9 +146,9 @@ verify_numeric (const char *s, const char *end)
|
||||
else if (*end)
|
||||
{
|
||||
if (s == end)
|
||||
error (0, 0, _("%s: expected a numeric value"), s);
|
||||
error (0, 0, _("%s: expected a numeric value"), s);
|
||||
else
|
||||
error (0, 0, _("%s: value not completely converted"), s);
|
||||
error (0, 0, _("%s: value not completely converted"), s);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -159,17 +159,17 @@ FUNC_NAME (char const *s) \
|
||||
{ \
|
||||
char *end; \
|
||||
TYPE val; \
|
||||
\
|
||||
\
|
||||
if (*s == '\"' || *s == '\'') \
|
||||
{ \
|
||||
unsigned char ch = *++s; \
|
||||
val = ch; \
|
||||
/* If POSIXLY_CORRECT is not set, then give a warning that there \
|
||||
are characters following the character constant and that GNU \
|
||||
printf is ignoring those characters. If POSIXLY_CORRECT *is* \
|
||||
set, then don't give the warning. */ \
|
||||
are characters following the character constant and that GNU \
|
||||
printf is ignoring those characters. If POSIXLY_CORRECT *is* \
|
||||
set, then don't give the warning. */ \
|
||||
if (*++s != 0 && !posixly_correct) \
|
||||
error (0, 0, _(cfcc_msg), s); \
|
||||
error (0, 0, _(cfcc_msg), s); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
@@ -238,11 +238,11 @@ print_esc (const char *escstart, bool octal_0)
|
||||
{
|
||||
/* A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits. */
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 2 && isxdigit (to_uchar (*p));
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin (*p);
|
||||
esc_length < 2 && isxdigit (to_uchar (*p));
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin (*p);
|
||||
if (esc_length == 0)
|
||||
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
|
||||
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (isodigit (*p))
|
||||
@@ -251,9 +251,9 @@ print_esc (const char *escstart, bool octal_0)
|
||||
Allow \ooo if octal_0 && *p != '0'; this is an undocumented
|
||||
extension to POSIX that is compatible with Bash 2.05b. */
|
||||
for (esc_length = 0, p += octal_0 && *p == '0';
|
||||
esc_length < 3 && isodigit (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin (*p);
|
||||
esc_length < 3 && isodigit (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin (*p);
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (*p && strchr ("\"\\abcfnrtv", *p))
|
||||
@@ -265,24 +265,24 @@ print_esc (const char *escstart, bool octal_0)
|
||||
|
||||
uni_value = 0;
|
||||
for (esc_length = (esc_char == 'u' ? 4 : 8), ++p;
|
||||
esc_length > 0;
|
||||
--esc_length, ++p)
|
||||
{
|
||||
if (! isxdigit (to_uchar (*p)))
|
||||
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
|
||||
uni_value = uni_value * 16 + hextobin (*p);
|
||||
}
|
||||
esc_length > 0;
|
||||
--esc_length, ++p)
|
||||
{
|
||||
if (! isxdigit (to_uchar (*p)))
|
||||
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
|
||||
uni_value = uni_value * 16 + hextobin (*p);
|
||||
}
|
||||
|
||||
/* A universal character name shall not specify a character short
|
||||
identifier in the range 00000000 through 00000020, 0000007F through
|
||||
0000009F, or 0000D800 through 0000DFFF inclusive. A universal
|
||||
character name shall not designate a character in the required
|
||||
character set. */
|
||||
identifier in the range 00000000 through 00000020, 0000007F through
|
||||
0000009F, or 0000D800 through 0000DFFF inclusive. A universal
|
||||
character name shall not designate a character in the required
|
||||
character set. */
|
||||
if ((uni_value <= 0x9f
|
||||
&& uni_value != 0x24 && uni_value != 0x40 && uni_value != 0x60)
|
||||
|| (uni_value >= 0xd800 && uni_value <= 0xdfff))
|
||||
error (EXIT_FAILURE, 0, _("invalid universal character name \\%c%0*x"),
|
||||
esc_char, (esc_char == 'u' ? 4 : 8), uni_value);
|
||||
&& uni_value != 0x24 && uni_value != 0x40 && uni_value != 0x60)
|
||||
|| (uni_value >= 0xd800 && uni_value <= 0xdfff))
|
||||
error (EXIT_FAILURE, 0, _("invalid universal character name \\%c%0*x"),
|
||||
esc_char, (esc_char == 'u' ? 4 : 8), uni_value);
|
||||
|
||||
print_unicode_char (stdout, uni_value, 0);
|
||||
}
|
||||
@@ -290,10 +290,10 @@ print_esc (const char *escstart, bool octal_0)
|
||||
{
|
||||
putchar ('\\');
|
||||
if (*p)
|
||||
{
|
||||
putchar (*p);
|
||||
p++;
|
||||
}
|
||||
{
|
||||
putchar (*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return p - escstart - 1;
|
||||
}
|
||||
@@ -320,9 +320,9 @@ print_esc_string (const char *str)
|
||||
|
||||
static void
|
||||
print_direc (const char *start, size_t length, char conversion,
|
||||
bool have_field_width, int field_width,
|
||||
bool have_precision, int precision,
|
||||
char const *argument)
|
||||
bool have_field_width, int field_width,
|
||||
bool have_precision, int precision,
|
||||
char const *argument)
|
||||
{
|
||||
char *p; /* Null-terminated copy of % directive. */
|
||||
|
||||
@@ -337,20 +337,20 @@ print_direc (const char *start, size_t length, char conversion,
|
||||
switch (conversion)
|
||||
{
|
||||
case 'd': case 'i': case 'o': case 'u': case 'x': case 'X':
|
||||
length_modifier = PRIdMAX;
|
||||
length_modifier_len = sizeof PRIdMAX - 2;
|
||||
break;
|
||||
length_modifier = PRIdMAX;
|
||||
length_modifier_len = sizeof PRIdMAX - 2;
|
||||
break;
|
||||
|
||||
case 'a': case 'e': case 'f': case 'g':
|
||||
case 'A': case 'E': case 'F': case 'G':
|
||||
length_modifier = "L";
|
||||
length_modifier_len = 1;
|
||||
break;
|
||||
length_modifier = "L";
|
||||
length_modifier_len = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
length_modifier = start; /* Any valid pointer will do. */
|
||||
length_modifier_len = 0;
|
||||
break;
|
||||
length_modifier = start; /* Any valid pointer will do. */
|
||||
length_modifier_len = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
p = xmalloc (length + length_modifier_len + 2);
|
||||
@@ -365,21 +365,21 @@ print_direc (const char *start, size_t length, char conversion,
|
||||
case 'd':
|
||||
case 'i':
|
||||
{
|
||||
intmax_t arg = vstrtoimax (argument);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, arg);
|
||||
else
|
||||
xprintf (p, precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, arg);
|
||||
else
|
||||
xprintf (p, field_width, precision, arg);
|
||||
}
|
||||
intmax_t arg = vstrtoimax (argument);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, arg);
|
||||
else
|
||||
xprintf (p, precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, arg);
|
||||
else
|
||||
xprintf (p, field_width, precision, arg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -388,21 +388,21 @@ print_direc (const char *start, size_t length, char conversion,
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
uintmax_t arg = vstrtoumax (argument);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, arg);
|
||||
else
|
||||
xprintf (p, precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, arg);
|
||||
else
|
||||
xprintf (p, field_width, precision, arg);
|
||||
}
|
||||
uintmax_t arg = vstrtoumax (argument);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, arg);
|
||||
else
|
||||
xprintf (p, precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, arg);
|
||||
else
|
||||
xprintf (p, field_width, precision, arg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -415,46 +415,46 @@ print_direc (const char *start, size_t length, char conversion,
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
long double arg = vstrtold (argument);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, arg);
|
||||
else
|
||||
xprintf (p, precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, arg);
|
||||
else
|
||||
xprintf (p, field_width, precision, arg);
|
||||
}
|
||||
long double arg = vstrtold (argument);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, arg);
|
||||
else
|
||||
xprintf (p, precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, arg);
|
||||
else
|
||||
xprintf (p, field_width, precision, arg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (!have_field_width)
|
||||
xprintf (p, *argument);
|
||||
xprintf (p, *argument);
|
||||
else
|
||||
xprintf (p, field_width, *argument);
|
||||
xprintf (p, field_width, *argument);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, argument);
|
||||
else
|
||||
xprintf (p, precision, argument);
|
||||
}
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, argument);
|
||||
else
|
||||
xprintf (p, precision, argument);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, argument);
|
||||
else
|
||||
xprintf (p, field_width, precision, argument);
|
||||
}
|
||||
{
|
||||
if (!have_precision)
|
||||
xprintf (p, field_width, argument);
|
||||
else
|
||||
xprintf (p, field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -481,146 +481,146 @@ print_formatted (const char *format, int argc, char **argv)
|
||||
for (f = format; *f; ++f)
|
||||
{
|
||||
switch (*f)
|
||||
{
|
||||
case '%':
|
||||
direc_start = f++;
|
||||
direc_length = 1;
|
||||
have_field_width = have_precision = false;
|
||||
if (*f == '%')
|
||||
{
|
||||
putchar ('%');
|
||||
break;
|
||||
}
|
||||
if (*f == 'b')
|
||||
{
|
||||
/* FIXME: Field width and precision are not supported
|
||||
for %b, even though POSIX requires it. */
|
||||
if (argc > 0)
|
||||
{
|
||||
print_esc_string (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
case '%':
|
||||
direc_start = f++;
|
||||
direc_length = 1;
|
||||
have_field_width = have_precision = false;
|
||||
if (*f == '%')
|
||||
{
|
||||
putchar ('%');
|
||||
break;
|
||||
}
|
||||
if (*f == 'b')
|
||||
{
|
||||
/* FIXME: Field width and precision are not supported
|
||||
for %b, even though POSIX requires it. */
|
||||
if (argc > 0)
|
||||
{
|
||||
print_esc_string (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
memset (ok, 0, sizeof ok);
|
||||
ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] =
|
||||
ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] =
|
||||
ok['s'] = ok['u'] = ok['x'] = ok['X'] = 1;
|
||||
memset (ok, 0, sizeof ok);
|
||||
ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] =
|
||||
ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] =
|
||||
ok['s'] = ok['u'] = ok['x'] = ok['X'] = 1;
|
||||
|
||||
for (;; f++, direc_length++)
|
||||
switch (*f)
|
||||
{
|
||||
for (;; f++, direc_length++)
|
||||
switch (*f)
|
||||
{
|
||||
#if (__GLIBC__ == 2 && 2 <= __GLIBC_MINOR__) || 3 <= __GLIBC__
|
||||
case 'I':
|
||||
case 'I':
|
||||
#endif
|
||||
case '\'':
|
||||
ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] =
|
||||
ok['o'] = ok['s'] = ok['x'] = ok['X'] = 0;
|
||||
break;
|
||||
case '-': case '+': case ' ':
|
||||
break;
|
||||
case '#':
|
||||
ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = 0;
|
||||
break;
|
||||
case '0':
|
||||
ok['c'] = ok['s'] = 0;
|
||||
break;
|
||||
default:
|
||||
goto no_more_flag_characters;
|
||||
}
|
||||
no_more_flag_characters:;
|
||||
case '\'':
|
||||
ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] =
|
||||
ok['o'] = ok['s'] = ok['x'] = ok['X'] = 0;
|
||||
break;
|
||||
case '-': case '+': case ' ':
|
||||
break;
|
||||
case '#':
|
||||
ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = 0;
|
||||
break;
|
||||
case '0':
|
||||
ok['c'] = ok['s'] = 0;
|
||||
break;
|
||||
default:
|
||||
goto no_more_flag_characters;
|
||||
}
|
||||
no_more_flag_characters:;
|
||||
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
intmax_t width = vstrtoimax (*argv);
|
||||
if (INT_MIN <= width && width <= INT_MAX)
|
||||
field_width = width;
|
||||
else
|
||||
error (EXIT_FAILURE, 0, _("invalid field width: %s"),
|
||||
*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
field_width = 0;
|
||||
have_field_width = true;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '.')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
ok['c'] = 0;
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
intmax_t prec = vstrtoimax (*argv);
|
||||
if (prec < 0)
|
||||
{
|
||||
/* A negative precision is taken as if the
|
||||
precision were omitted, so -1 is safe
|
||||
here even if prec < INT_MIN. */
|
||||
precision = -1;
|
||||
}
|
||||
else if (INT_MAX < prec)
|
||||
error (EXIT_FAILURE, 0, _("invalid precision: %s"),
|
||||
*argv);
|
||||
else
|
||||
precision = prec;
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
precision = 0;
|
||||
have_precision = true;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
intmax_t width = vstrtoimax (*argv);
|
||||
if (INT_MIN <= width && width <= INT_MAX)
|
||||
field_width = width;
|
||||
else
|
||||
error (EXIT_FAILURE, 0, _("invalid field width: %s"),
|
||||
*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
field_width = 0;
|
||||
have_field_width = true;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '.')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
ok['c'] = 0;
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
intmax_t prec = vstrtoimax (*argv);
|
||||
if (prec < 0)
|
||||
{
|
||||
/* A negative precision is taken as if the
|
||||
precision were omitted, so -1 is safe
|
||||
here even if prec < INT_MIN. */
|
||||
precision = -1;
|
||||
}
|
||||
else if (INT_MAX < prec)
|
||||
error (EXIT_FAILURE, 0, _("invalid precision: %s"),
|
||||
*argv);
|
||||
else
|
||||
precision = prec;
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
precision = 0;
|
||||
have_precision = true;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
|
||||
while (*f == 'l' || *f == 'L' || *f == 'h'
|
||||
|| *f == 'j' || *f == 't' || *f == 'z')
|
||||
++f;
|
||||
while (*f == 'l' || *f == 'L' || *f == 'h'
|
||||
|| *f == 'j' || *f == 't' || *f == 'z')
|
||||
++f;
|
||||
|
||||
{
|
||||
unsigned char conversion = *f;
|
||||
if (! ok[conversion])
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%.*s: invalid conversion specification"),
|
||||
(int) (f + 1 - direc_start), direc_start);
|
||||
}
|
||||
{
|
||||
unsigned char conversion = *f;
|
||||
if (! ok[conversion])
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("%.*s: invalid conversion specification"),
|
||||
(int) (f + 1 - direc_start), direc_start);
|
||||
}
|
||||
|
||||
print_direc (direc_start, direc_length, *f,
|
||||
have_field_width, field_width,
|
||||
have_precision, precision,
|
||||
(argc <= 0 ? "" : (argc--, *argv++)));
|
||||
break;
|
||||
print_direc (direc_start, direc_length, *f,
|
||||
have_field_width, field_width,
|
||||
have_precision, precision,
|
||||
(argc <= 0 ? "" : (argc--, *argv++)));
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
f += print_esc (f, false);
|
||||
break;
|
||||
case '\\':
|
||||
f += print_esc (f, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
putchar (*f);
|
||||
}
|
||||
default:
|
||||
putchar (*f);
|
||||
}
|
||||
}
|
||||
|
||||
return save_argc - argc;
|
||||
@@ -649,14 +649,14 @@ main (int argc, char **argv)
|
||||
if (argc == 2)
|
||||
{
|
||||
if (STREQ (argv[1], "--help"))
|
||||
usage (EXIT_SUCCESS);
|
||||
usage (EXIT_SUCCESS);
|
||||
|
||||
if (STREQ (argv[1], "--version"))
|
||||
{
|
||||
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
|
||||
(char *) NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
{
|
||||
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
|
||||
(char *) NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/* The above handles --help and --version.
|
||||
@@ -687,8 +687,8 @@ main (int argc, char **argv)
|
||||
|
||||
if (argc > 0)
|
||||
error (0, 0,
|
||||
_("warning: ignoring excess arguments, starting with %s"),
|
||||
quote (argv[0]));
|
||||
_("warning: ignoring excess arguments, starting with %s"),
|
||||
quote (argv[0]));
|
||||
|
||||
exit (exit_status);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]...\n"), program_name);
|
||||
@@ -102,9 +102,9 @@ file_name_prepend (struct file_name *p, char const *s, size_t s_len)
|
||||
{
|
||||
size_t half = p->n_alloc + 1 + s_len;
|
||||
/* Use xnmalloc+free rather than xnrealloc, since with the latter
|
||||
we'd end up copying the data twice: once via realloc, then again
|
||||
to align it with the end of the new buffer. With xnmalloc, we
|
||||
copy it only once. */
|
||||
we'd end up copying the data twice: once via realloc, then again
|
||||
to align it with the end of the new buffer. With xnmalloc, we
|
||||
copy it only once. */
|
||||
char *q = xnmalloc (2, half);
|
||||
size_t n_used = p->n_alloc - n_free;
|
||||
p->start = q + 2 * half - n_used;
|
||||
@@ -149,7 +149,7 @@ nth_parent (size_t n)
|
||||
|
||||
static void
|
||||
find_dir_entry (struct stat *dot_sb, struct file_name *file_name,
|
||||
size_t parent_height)
|
||||
size_t parent_height)
|
||||
{
|
||||
DIR *dirp;
|
||||
int fd;
|
||||
@@ -160,16 +160,16 @@ find_dir_entry (struct stat *dot_sb, struct file_name *file_name,
|
||||
dirp = opendir ("..");
|
||||
if (dirp == NULL)
|
||||
error (EXIT_FAILURE, errno, _("cannot open directory %s"),
|
||||
quote (nth_parent (parent_height)));
|
||||
quote (nth_parent (parent_height)));
|
||||
|
||||
fd = dirfd (dirp);
|
||||
if ((0 <= fd ? fchdir (fd) : chdir ("..")) < 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to chdir to %s"),
|
||||
quote (nth_parent (parent_height)));
|
||||
quote (nth_parent (parent_height)));
|
||||
|
||||
if ((0 <= fd ? fstat (fd, &parent_sb) : stat (".", &parent_sb)) < 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to stat %s"),
|
||||
quote (nth_parent (parent_height)));
|
||||
quote (nth_parent (parent_height)));
|
||||
|
||||
/* If parent and child directory are on different devices, then we
|
||||
can't rely on d_ino for useful i-node numbers; use lstat instead. */
|
||||
@@ -184,57 +184,57 @@ find_dir_entry (struct stat *dot_sb, struct file_name *file_name,
|
||||
|
||||
errno = 0;
|
||||
if ((dp = readdir_ignoring_dot_and_dotdot (dirp)) == NULL)
|
||||
{
|
||||
if (errno)
|
||||
{
|
||||
/* Save/restore errno across closedir call. */
|
||||
int e = errno;
|
||||
closedir (dirp);
|
||||
errno = e;
|
||||
{
|
||||
if (errno)
|
||||
{
|
||||
/* Save/restore errno across closedir call. */
|
||||
int e = errno;
|
||||
closedir (dirp);
|
||||
errno = e;
|
||||
|
||||
/* Arrange to give a diagnostic after exiting this loop. */
|
||||
dirp = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* Arrange to give a diagnostic after exiting this loop. */
|
||||
dirp = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ino = D_INO (dp);
|
||||
|
||||
if (ino == NOT_AN_INODE_NUMBER || use_lstat)
|
||||
{
|
||||
if (lstat (dp->d_name, &ent_sb) < 0)
|
||||
{
|
||||
/* Skip any entry we can't stat. */
|
||||
continue;
|
||||
}
|
||||
ino = ent_sb.st_ino;
|
||||
}
|
||||
{
|
||||
if (lstat (dp->d_name, &ent_sb) < 0)
|
||||
{
|
||||
/* Skip any entry we can't stat. */
|
||||
continue;
|
||||
}
|
||||
ino = ent_sb.st_ino;
|
||||
}
|
||||
|
||||
if (ino != dot_sb->st_ino)
|
||||
continue;
|
||||
continue;
|
||||
|
||||
/* If we're not crossing a device boundary, then a simple i-node
|
||||
match is enough. */
|
||||
match is enough. */
|
||||
if ( ! use_lstat || ent_sb.st_dev == dot_sb->st_dev)
|
||||
{
|
||||
file_name_prepend (file_name, dp->d_name, _D_EXACT_NAMLEN (dp));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
{
|
||||
file_name_prepend (file_name, dp->d_name, _D_EXACT_NAMLEN (dp));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dirp == NULL || closedir (dirp) != 0)
|
||||
{
|
||||
/* Note that this diagnostic serves for both readdir
|
||||
and closedir failures. */
|
||||
and closedir failures. */
|
||||
error (EXIT_FAILURE, errno, _("reading directory %s"),
|
||||
quote (nth_parent (parent_height)));
|
||||
quote (nth_parent (parent_height)));
|
||||
}
|
||||
|
||||
if ( ! found)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("couldn't find directory entry in %s with matching i-node"),
|
||||
quote (nth_parent (parent_height)));
|
||||
_("couldn't find directory entry in %s with matching i-node"),
|
||||
quote (nth_parent (parent_height)));
|
||||
|
||||
*dot_sb = parent_sb;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ robust_getcwd (struct file_name *file_name)
|
||||
|
||||
if (root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
quote ("/"));
|
||||
|
||||
if (stat (".", &dot_sb) < 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to stat %s"), quote ("."));
|
||||
@@ -281,7 +281,7 @@ robust_getcwd (struct file_name *file_name)
|
||||
{
|
||||
/* If we've reached the root, we're done. */
|
||||
if (SAME_INODE (dot_sb, *root_dev_ino))
|
||||
break;
|
||||
break;
|
||||
|
||||
find_dir_entry (&dot_sb, file_name, height++);
|
||||
}
|
||||
@@ -309,8 +309,8 @@ logical_getcwd (void)
|
||||
while ((p = strstr (p, "/.")))
|
||||
{
|
||||
if (!p[2] || p[2] == '/'
|
||||
|| (p[2] == '.' && (!p[3] || p[3] == '/')))
|
||||
return NULL;
|
||||
|| (p[2] == '.' && (!p[3] || p[3] == '/')))
|
||||
return NULL;
|
||||
p++;
|
||||
}
|
||||
|
||||
@@ -340,23 +340,23 @@ main (int argc, char **argv)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "LP", longopts, NULL);
|
||||
if (c == -1)
|
||||
break;
|
||||
break;
|
||||
switch (c)
|
||||
{
|
||||
case 'L':
|
||||
logical = true;
|
||||
break;
|
||||
case 'P':
|
||||
logical = false;
|
||||
break;
|
||||
{
|
||||
case 'L':
|
||||
logical = true;
|
||||
break;
|
||||
case 'P':
|
||||
logical = false;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
@@ -366,10 +366,10 @@ main (int argc, char **argv)
|
||||
{
|
||||
wd = logical_getcwd ();
|
||||
if (wd)
|
||||
{
|
||||
puts (wd);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
{
|
||||
puts (wd);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
wd = xgetcwd ();
|
||||
|
||||
+29
-29
@@ -57,12 +57,12 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... FILE\n"), program_name);
|
||||
fputs (_("Print value of a symbolic link or canonical file name\n\n"),
|
||||
stdout);
|
||||
stdout);
|
||||
fputs (_("\
|
||||
-f, --canonicalize canonicalize by following every symlink in\n\
|
||||
every component of the given name recursively;\n\
|
||||
@@ -112,31 +112,31 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "efmnqsv", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'e':
|
||||
can_mode = CAN_EXISTING;
|
||||
break;
|
||||
case 'f':
|
||||
can_mode = CAN_ALL_BUT_LAST;
|
||||
break;
|
||||
case 'm':
|
||||
can_mode = CAN_MISSING;
|
||||
break;
|
||||
case 'n':
|
||||
no_newline = true;
|
||||
break;
|
||||
case 'q':
|
||||
case 's':
|
||||
verbose = false;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'e':
|
||||
can_mode = CAN_EXISTING;
|
||||
break;
|
||||
case 'f':
|
||||
can_mode = CAN_ALL_BUT_LAST;
|
||||
break;
|
||||
case 'm':
|
||||
can_mode = CAN_MISSING;
|
||||
break;
|
||||
case 'n':
|
||||
no_newline = true;
|
||||
break;
|
||||
case 'q':
|
||||
case 's':
|
||||
verbose = false;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind >= argc)
|
||||
@@ -154,8 +154,8 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
value = (can_mode != -1
|
||||
? canonicalize_filename_mode (fname, can_mode)
|
||||
: areadlink_with_size (fname, 63));
|
||||
? canonicalize_filename_mode (fname, can_mode)
|
||||
: areadlink_with_size (fname, 63));
|
||||
if (value)
|
||||
{
|
||||
printf ("%s%s", value, (no_newline ? "" : "\n"));
|
||||
|
||||
+456
-456
File diff suppressed because it is too large.
Load diff
+3
-3
@@ -83,12 +83,12 @@ enum RM_status
|
||||
do \
|
||||
{ \
|
||||
if ((New_value) == RM_ERROR \
|
||||
|| ((New_value) == RM_USER_DECLINED && (S) == RM_OK)) \
|
||||
(S) = (New_value); \
|
||||
|| ((New_value) == RM_USER_DECLINED && (S) == RM_OK)) \
|
||||
(S) = (New_value); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
enum RM_status rm (size_t n_files, char const *const *file,
|
||||
struct rm_options const *x);
|
||||
struct rm_options const *x);
|
||||
|
||||
#endif
|
||||
@@ -137,14 +137,14 @@ diagnose_leading_hyphen (int argc, char **argv)
|
||||
struct stat st;
|
||||
|
||||
if (arg[0] == '-' && arg[1] && lstat (arg, &st) == 0)
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("Try `%s ./%s' to remove the file %s.\n"),
|
||||
argv[0],
|
||||
quotearg_n_style (1, shell_quoting_style, arg),
|
||||
quote (arg));
|
||||
break;
|
||||
}
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("Try `%s ./%s' to remove the file %s.\n"),
|
||||
argv[0],
|
||||
quotearg_n_style (1, shell_quoting_style, arg),
|
||||
quote (arg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... FILE...\n"), program_name);
|
||||
@@ -196,7 +196,7 @@ use one of these commands:\n\
|
||||
\n\
|
||||
%s ./-foo\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
program_name, program_name);
|
||||
fputs (_("\
|
||||
\n\
|
||||
Note that if you use rm to remove a file, it is usually possible to recover\n\
|
||||
@@ -248,104 +248,104 @@ main (int argc, char **argv)
|
||||
while ((c = getopt_long (argc, argv, "dfirvIR", long_opts, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'd':
|
||||
/* Ignore this option, for backward compatibility with
|
||||
coreutils 5.92. FIXME: Some time after 2005, change this
|
||||
to report an error (or perhaps behave like FreeBSD does)
|
||||
instead of ignoring the option. */
|
||||
break;
|
||||
{
|
||||
case 'd':
|
||||
/* Ignore this option, for backward compatibility with
|
||||
coreutils 5.92. FIXME: Some time after 2005, change this
|
||||
to report an error (or perhaps behave like FreeBSD does)
|
||||
instead of ignoring the option. */
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
x.interactive = RMI_NEVER;
|
||||
x.ignore_missing_files = true;
|
||||
prompt_once = false;
|
||||
break;
|
||||
case 'f':
|
||||
x.interactive = RMI_NEVER;
|
||||
x.ignore_missing_files = true;
|
||||
prompt_once = false;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
x.interactive = RMI_ALWAYS;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = false;
|
||||
break;
|
||||
case 'i':
|
||||
x.interactive = RMI_ALWAYS;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = false;
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
x.interactive = RMI_NEVER;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = true;
|
||||
break;
|
||||
case 'I':
|
||||
x.interactive = RMI_NEVER;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = true;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
case 'R':
|
||||
x.recursive = true;
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
x.recursive = true;
|
||||
break;
|
||||
|
||||
case INTERACTIVE_OPTION:
|
||||
{
|
||||
int i;
|
||||
if (optarg)
|
||||
i = XARGMATCH ("--interactive", optarg, interactive_args,
|
||||
interactive_types);
|
||||
else
|
||||
i = interactive_always;
|
||||
switch (i)
|
||||
{
|
||||
case interactive_never:
|
||||
x.interactive = RMI_NEVER;
|
||||
prompt_once = false;
|
||||
break;
|
||||
case INTERACTIVE_OPTION:
|
||||
{
|
||||
int i;
|
||||
if (optarg)
|
||||
i = XARGMATCH ("--interactive", optarg, interactive_args,
|
||||
interactive_types);
|
||||
else
|
||||
i = interactive_always;
|
||||
switch (i)
|
||||
{
|
||||
case interactive_never:
|
||||
x.interactive = RMI_NEVER;
|
||||
prompt_once = false;
|
||||
break;
|
||||
|
||||
case interactive_once:
|
||||
x.interactive = RMI_SOMETIMES;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = true;
|
||||
break;
|
||||
case interactive_once:
|
||||
x.interactive = RMI_SOMETIMES;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = true;
|
||||
break;
|
||||
|
||||
case interactive_always:
|
||||
x.interactive = RMI_ALWAYS;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case interactive_always:
|
||||
x.interactive = RMI_ALWAYS;
|
||||
x.ignore_missing_files = false;
|
||||
prompt_once = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ONE_FILE_SYSTEM:
|
||||
x.one_file_system = true;
|
||||
break;
|
||||
case ONE_FILE_SYSTEM:
|
||||
x.one_file_system = true;
|
||||
break;
|
||||
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
case NO_PRESERVE_ROOT:
|
||||
preserve_root = false;
|
||||
break;
|
||||
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
case PRESERVE_ROOT:
|
||||
preserve_root = true;
|
||||
break;
|
||||
|
||||
case PRESUME_INPUT_TTY_OPTION:
|
||||
x.stdin_tty = true;
|
||||
break;
|
||||
case PRESUME_INPUT_TTY_OPTION:
|
||||
x.stdin_tty = true;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
diagnose_leading_hyphen (argc, argv);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
diagnose_leading_hyphen (argc, argv);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= optind)
|
||||
{
|
||||
if (x.ignore_missing_files)
|
||||
exit (EXIT_SUCCESS);
|
||||
exit (EXIT_SUCCESS);
|
||||
else
|
||||
{
|
||||
error (0, 0, _("missing operand"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("missing operand"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (x.recursive & preserve_root)
|
||||
@@ -353,8 +353,8 @@ main (int argc, char **argv)
|
||||
static struct dev_ino dev_ino_buf;
|
||||
x.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
|
||||
if (x.root_dev_ino == NULL)
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
|
||||
quote ("/"));
|
||||
}
|
||||
|
||||
size_t n_files = argc - optind;
|
||||
@@ -363,12 +363,12 @@ main (int argc, char **argv)
|
||||
if (prompt_once && (x.recursive || 3 < n_files))
|
||||
{
|
||||
fprintf (stderr,
|
||||
(x.recursive
|
||||
? _("%s: remove all arguments recursively? ")
|
||||
: _("%s: remove all arguments? ")),
|
||||
program_name);
|
||||
(x.recursive
|
||||
? _("%s: remove all arguments recursively? ")
|
||||
: _("%s: remove all arguments? ")),
|
||||
program_name);
|
||||
if (!yesno ())
|
||||
exit (EXIT_SUCCESS);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
enum RM_status status = rm (n_files, file, &x);
|
||||
assert (VALID_STATUS (status));
|
||||
|
||||
+51
-51
@@ -17,8 +17,8 @@
|
||||
|
||||
/* Options:
|
||||
-p, --parent Remove any parent dirs that are explicitly mentioned
|
||||
in an argument, if they become empty after the
|
||||
argument file is removed.
|
||||
in an argument, if they become empty after the
|
||||
argument file is removed.
|
||||
|
||||
David MacKenzie <djm@ai.mit.edu> */
|
||||
|
||||
@@ -101,9 +101,9 @@ static bool
|
||||
ignorable_failure (int error_number, char const *dir)
|
||||
{
|
||||
return (ignore_fail_on_non_empty
|
||||
&& (errno_rmdir_non_empty (error_number)
|
||||
|| (errno_may_be_empty (error_number)
|
||||
&& is_empty_dir (AT_FDCWD, dir))));
|
||||
&& (errno_rmdir_non_empty (error_number)
|
||||
|| (errno_may_be_empty (error_number)
|
||||
&& is_empty_dir (AT_FDCWD, dir))));
|
||||
}
|
||||
|
||||
/* Remove any empty parent directories of DIR.
|
||||
@@ -122,34 +122,34 @@ remove_parents (char *dir)
|
||||
{
|
||||
slash = strrchr (dir, '/');
|
||||
if (slash == NULL)
|
||||
break;
|
||||
break;
|
||||
/* Remove any characters after the slash, skipping any extra
|
||||
slashes in a row. */
|
||||
slashes in a row. */
|
||||
while (slash > dir && *slash == '/')
|
||||
--slash;
|
||||
--slash;
|
||||
slash[1] = 0;
|
||||
|
||||
/* Give a diagnostic for each attempted removal if --verbose. */
|
||||
if (verbose)
|
||||
prog_fprintf (stdout, _("removing directory, %s"), quote (dir));
|
||||
prog_fprintf (stdout, _("removing directory, %s"), quote (dir));
|
||||
|
||||
ok = (rmdir (dir) == 0);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
/* Stop quietly if --ignore-fail-on-non-empty. */
|
||||
if (ignorable_failure (errno, dir))
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Barring race conditions, DIR is expected to be a directory. */
|
||||
error (0, errno, _("failed to remove directory %s"),
|
||||
quote (dir));
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
/* Stop quietly if --ignore-fail-on-non-empty. */
|
||||
if (ignorable_failure (errno, dir))
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Barring race conditions, DIR is expected to be a directory. */
|
||||
error (0, errno, _("failed to remove directory %s"),
|
||||
quote (dir));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... DIRECTORY...\n"), program_name);
|
||||
@@ -201,21 +201,21 @@ main (int argc, char **argv)
|
||||
while ((optc = getopt_long (argc, argv, "pv", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
case 'p':
|
||||
remove_empty_parents = true;
|
||||
break;
|
||||
case IGNORE_FAIL_ON_NON_EMPTY_OPTION:
|
||||
ignore_fail_on_non_empty = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
case 'p':
|
||||
remove_empty_parents = true;
|
||||
break;
|
||||
case IGNORE_FAIL_ON_NON_EMPTY_OPTION:
|
||||
ignore_fail_on_non_empty = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
@@ -230,22 +230,22 @@ main (int argc, char **argv)
|
||||
|
||||
/* Give a diagnostic for each attempted removal if --verbose. */
|
||||
if (verbose)
|
||||
prog_fprintf (stdout, _("removing directory, %s"), quote (dir));
|
||||
prog_fprintf (stdout, _("removing directory, %s"), quote (dir));
|
||||
|
||||
if (rmdir (dir) != 0)
|
||||
{
|
||||
if (ignorable_failure (errno, dir))
|
||||
continue;
|
||||
{
|
||||
if (ignorable_failure (errno, dir))
|
||||
continue;
|
||||
|
||||
/* Here, the diagnostic is less precise, since we have no idea
|
||||
whether DIR is a directory. */
|
||||
error (0, errno, _("failed to remove %s"), quote (dir));
|
||||
ok = false;
|
||||
}
|
||||
/* Here, the diagnostic is less precise, since we have no idea
|
||||
whether DIR is a directory. */
|
||||
error (0, errno, _("failed to remove %s"), quote (dir));
|
||||
ok = false;
|
||||
}
|
||||
else if (remove_empty_parents)
|
||||
{
|
||||
ok &= remove_parents (dir);
|
||||
}
|
||||
{
|
||||
ok &= remove_parents (dir);
|
||||
}
|
||||
}
|
||||
|
||||
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
|
||||
+67
-67
@@ -78,7 +78,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -131,47 +131,47 @@ main (int argc, char **argv)
|
||||
{
|
||||
int option_index = 0;
|
||||
int c = getopt_long (argc, argv, "+r:t:u:l:c", long_options,
|
||||
&option_index);
|
||||
&option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
break;
|
||||
switch (c)
|
||||
{
|
||||
case 'r':
|
||||
if (role)
|
||||
error (EXIT_FAILURE, 0, _("multiple roles"));
|
||||
role = optarg;
|
||||
break;
|
||||
case 't':
|
||||
if (type)
|
||||
error (EXIT_FAILURE, 0, _("multiple types"));
|
||||
type = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
if (user)
|
||||
error (EXIT_FAILURE, 0, _("multiple users"));
|
||||
user = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
if (range)
|
||||
error (EXIT_FAILURE, 0, _("multiple levelranges"));
|
||||
range = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
compute_trans = true;
|
||||
break;
|
||||
{
|
||||
case 'r':
|
||||
if (role)
|
||||
error (EXIT_FAILURE, 0, _("multiple roles"));
|
||||
role = optarg;
|
||||
break;
|
||||
case 't':
|
||||
if (type)
|
||||
error (EXIT_FAILURE, 0, _("multiple types"));
|
||||
type = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
if (user)
|
||||
error (EXIT_FAILURE, 0, _("multiple users"));
|
||||
user = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
if (range)
|
||||
error (EXIT_FAILURE, 0, _("multiple levelranges"));
|
||||
range = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
compute_trans = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc - optind == 0)
|
||||
{
|
||||
if (getcon (&cur_context) < 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to get current context"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get current context"));
|
||||
fputs (cur_context, stdout);
|
||||
fputc ('\n', stdout);
|
||||
exit (EXIT_SUCCESS);
|
||||
@@ -180,10 +180,10 @@ main (int argc, char **argv)
|
||||
if (!(user || role || type || range || compute_trans))
|
||||
{
|
||||
if (optind >= argc)
|
||||
{
|
||||
error (0, 0, _("you must specify -c, -t, -u, -l, -r, or context"));
|
||||
usage (1);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("you must specify -c, -t, -u, -l, -r, or context"));
|
||||
usage (1);
|
||||
}
|
||||
context = argv[optind++];
|
||||
}
|
||||
|
||||
@@ -195,62 +195,62 @@ main (int argc, char **argv)
|
||||
|
||||
if (is_selinux_enabled () != 1)
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("runcon may be used only on a SELinux kernel"));
|
||||
_("runcon may be used only on a SELinux kernel"));
|
||||
|
||||
if (context)
|
||||
{
|
||||
con = context_new (context);
|
||||
if (!con)
|
||||
error (EXIT_FAILURE, errno, _("failed to create security context: %s"),
|
||||
quotearg_colon (context));
|
||||
error (EXIT_FAILURE, errno, _("failed to create security context: %s"),
|
||||
quotearg_colon (context));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getcon (&cur_context) < 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to get current context"));
|
||||
error (EXIT_FAILURE, errno, _("failed to get current context"));
|
||||
|
||||
/* We will generate context based on process transition */
|
||||
if (compute_trans)
|
||||
{
|
||||
/* Get context of file to be executed */
|
||||
if (getfilecon (argv[optind], &file_context) == -1)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to get security context of %s"),
|
||||
quote (argv[optind]));
|
||||
/* compute result of process transition */
|
||||
if (security_compute_create (cur_context, file_context,
|
||||
SECCLASS_PROCESS, &new_context) != 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to compute a new context"));
|
||||
/* free contexts */
|
||||
freecon (file_context);
|
||||
freecon (cur_context);
|
||||
{
|
||||
/* Get context of file to be executed */
|
||||
if (getfilecon (argv[optind], &file_context) == -1)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to get security context of %s"),
|
||||
quote (argv[optind]));
|
||||
/* compute result of process transition */
|
||||
if (security_compute_create (cur_context, file_context,
|
||||
SECCLASS_PROCESS, &new_context) != 0)
|
||||
error (EXIT_FAILURE, errno,
|
||||
_("failed to compute a new context"));
|
||||
/* free contexts */
|
||||
freecon (file_context);
|
||||
freecon (cur_context);
|
||||
|
||||
/* set cur_context equal to new_context */
|
||||
cur_context = new_context;
|
||||
}
|
||||
/* set cur_context equal to new_context */
|
||||
cur_context = new_context;
|
||||
}
|
||||
|
||||
con = context_new (cur_context);
|
||||
if (!con)
|
||||
error (EXIT_FAILURE, errno, _("failed to create security context: %s"),
|
||||
quotearg_colon (cur_context));
|
||||
error (EXIT_FAILURE, errno, _("failed to create security context: %s"),
|
||||
quotearg_colon (cur_context));
|
||||
if (user && context_user_set (con, user))
|
||||
error (EXIT_FAILURE, errno, _("failed to set new user %s"), user);
|
||||
error (EXIT_FAILURE, errno, _("failed to set new user %s"), user);
|
||||
if (type && context_type_set (con, type))
|
||||
error (EXIT_FAILURE, errno, _("failed to set new type %s"), type);
|
||||
error (EXIT_FAILURE, errno, _("failed to set new type %s"), type);
|
||||
if (range && context_range_set (con, range))
|
||||
error (EXIT_FAILURE, errno, _("failed to set new range %s"), range);
|
||||
error (EXIT_FAILURE, errno, _("failed to set new range %s"), range);
|
||||
if (role && context_role_set (con, role))
|
||||
error (EXIT_FAILURE, errno, _("failed to set new role %s"), role);
|
||||
error (EXIT_FAILURE, errno, _("failed to set new role %s"), role);
|
||||
}
|
||||
|
||||
if (security_check_context (context_str (con)) < 0)
|
||||
error (EXIT_FAILURE, errno, _("invalid context: %s"),
|
||||
quotearg_colon (context_str (con)));
|
||||
quotearg_colon (context_str (con)));
|
||||
|
||||
if (setexeccon (context_str (con)) != 0)
|
||||
error (EXIT_FAILURE, errno, _("unable to set security context %s"),
|
||||
quote (context_str (con)));
|
||||
quote (context_str (con)));
|
||||
if (cur_context != NULL)
|
||||
freecon (cur_context);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -150,25 +150,25 @@ scan_arg (const char *arg)
|
||||
{
|
||||
char const *decimal_point = strchr (arg, '.');
|
||||
if (! decimal_point)
|
||||
ret.precision = 0;
|
||||
ret.precision = 0;
|
||||
else
|
||||
{
|
||||
size_t fraction_len = strcspn (decimal_point + 1, "eE");
|
||||
if (fraction_len <= INT_MAX)
|
||||
ret.precision = fraction_len;
|
||||
ret.width += (fraction_len == 0 /* #. -> # */
|
||||
? -1
|
||||
: (decimal_point == arg /* .# -> 0.# */
|
||||
|| ! ISDIGIT (decimal_point[-1]))); /* -.# -> 0.# */
|
||||
}
|
||||
{
|
||||
size_t fraction_len = strcspn (decimal_point + 1, "eE");
|
||||
if (fraction_len <= INT_MAX)
|
||||
ret.precision = fraction_len;
|
||||
ret.width += (fraction_len == 0 /* #. -> # */
|
||||
? -1
|
||||
: (decimal_point == arg /* .# -> 0.# */
|
||||
|| ! ISDIGIT (decimal_point[-1]))); /* -.# -> 0.# */
|
||||
}
|
||||
char const *e = strchr (arg, 'e');
|
||||
if (! e)
|
||||
e = strchr (arg, 'E');
|
||||
e = strchr (arg, 'E');
|
||||
if (e)
|
||||
{
|
||||
long exponent = strtol (e + 1, NULL, 10);
|
||||
ret.precision += exponent < 0 ? -exponent : 0;
|
||||
}
|
||||
{
|
||||
long exponent = strtol (e + 1, NULL, 10);
|
||||
ret.precision += exponent < 0 ? -exponent : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -191,8 +191,8 @@ long_double_format (char const *fmt, struct layout *layout)
|
||||
for (i = 0; ! (fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
|
||||
{
|
||||
if (!fmt[i])
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("format %s has no %% directive"), quote (fmt));
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("format %s has no %% directive"), quote (fmt));
|
||||
prefix_len++;
|
||||
}
|
||||
|
||||
@@ -212,25 +212,25 @@ long_double_format (char const *fmt, struct layout *layout)
|
||||
error (EXIT_FAILURE, 0, _("format %s ends in %%"), quote (fmt));
|
||||
if (! strchr ("efgaEFGA", fmt[i]))
|
||||
error (EXIT_FAILURE, 0,
|
||||
_("format %s has unknown %%%c directive"), quote (fmt), fmt[i]);
|
||||
_("format %s has unknown %%%c directive"), quote (fmt), fmt[i]);
|
||||
|
||||
for (i++; ; i += (fmt[i] == '%') + 1)
|
||||
if (fmt[i] == '%' && fmt[i + 1] != '%')
|
||||
error (EXIT_FAILURE, 0, _("format %s has too many %% directives"),
|
||||
quote (fmt));
|
||||
quote (fmt));
|
||||
else if (fmt[i])
|
||||
suffix_len++;
|
||||
else
|
||||
{
|
||||
size_t format_size = i + 1;
|
||||
char *ldfmt = xmalloc (format_size + 1);
|
||||
memcpy (ldfmt, fmt, length_modifier_offset);
|
||||
ldfmt[length_modifier_offset] = 'L';
|
||||
strcpy (ldfmt + length_modifier_offset + 1,
|
||||
fmt + length_modifier_offset + has_L);
|
||||
layout->prefix_len = prefix_len;
|
||||
layout->suffix_len = suffix_len;
|
||||
return ldfmt;
|
||||
size_t format_size = i + 1;
|
||||
char *ldfmt = xmalloc (format_size + 1);
|
||||
memcpy (ldfmt, fmt, length_modifier_offset);
|
||||
ldfmt[length_modifier_offset] = 'L';
|
||||
strcpy (ldfmt + length_modifier_offset + 1,
|
||||
fmt + length_modifier_offset + has_L);
|
||||
layout->prefix_len = prefix_len;
|
||||
layout->suffix_len = suffix_len;
|
||||
return ldfmt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ long_double_format (char const *fmt, struct layout *layout)
|
||||
|
||||
static void
|
||||
print_numbers (char const *fmt, struct layout layout,
|
||||
long double first, long double step, long double last)
|
||||
long double first, long double step, long double last)
|
||||
{
|
||||
bool out_of_range = (step < 0 ? first < last : last < first);
|
||||
|
||||
@@ -249,51 +249,51 @@ print_numbers (char const *fmt, struct layout layout,
|
||||
long double i;
|
||||
|
||||
for (i = 1; ; i++)
|
||||
{
|
||||
long double x0 = x;
|
||||
printf (fmt, x);
|
||||
if (out_of_range)
|
||||
break;
|
||||
x = first + i * step;
|
||||
out_of_range = (step < 0 ? x < last : last < x);
|
||||
{
|
||||
long double x0 = x;
|
||||
printf (fmt, x);
|
||||
if (out_of_range)
|
||||
break;
|
||||
x = first + i * step;
|
||||
out_of_range = (step < 0 ? x < last : last < x);
|
||||
|
||||
if (out_of_range)
|
||||
{
|
||||
/* If the number just past LAST prints as a value equal
|
||||
to LAST, and prints differently from the previous
|
||||
number, then print the number. This avoids problems
|
||||
with rounding. For example, with the x86 it causes
|
||||
"seq 0 0.000001 0.000003" to print 0.000003 instead
|
||||
of stopping at 0.000002. */
|
||||
if (out_of_range)
|
||||
{
|
||||
/* If the number just past LAST prints as a value equal
|
||||
to LAST, and prints differently from the previous
|
||||
number, then print the number. This avoids problems
|
||||
with rounding. For example, with the x86 it causes
|
||||
"seq 0 0.000001 0.000003" to print 0.000003 instead
|
||||
of stopping at 0.000002. */
|
||||
|
||||
bool print_extra_number = false;
|
||||
long double x_val;
|
||||
char *x_str;
|
||||
int x_strlen;
|
||||
setlocale (LC_NUMERIC, "C");
|
||||
x_strlen = asprintf (&x_str, fmt, x);
|
||||
setlocale (LC_NUMERIC, "");
|
||||
if (x_strlen < 0)
|
||||
xalloc_die ();
|
||||
x_str[x_strlen - layout.suffix_len] = '\0';
|
||||
bool print_extra_number = false;
|
||||
long double x_val;
|
||||
char *x_str;
|
||||
int x_strlen;
|
||||
setlocale (LC_NUMERIC, "C");
|
||||
x_strlen = asprintf (&x_str, fmt, x);
|
||||
setlocale (LC_NUMERIC, "");
|
||||
if (x_strlen < 0)
|
||||
xalloc_die ();
|
||||
x_str[x_strlen - layout.suffix_len] = '\0';
|
||||
|
||||
if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
|
||||
&& x_val == last)
|
||||
{
|
||||
char *x0_str = NULL;
|
||||
if (asprintf (&x0_str, fmt, x0) < 0)
|
||||
xalloc_die ();
|
||||
print_extra_number = !STREQ (x0_str, x_str);
|
||||
free (x0_str);
|
||||
}
|
||||
if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
|
||||
&& x_val == last)
|
||||
{
|
||||
char *x0_str = NULL;
|
||||
if (asprintf (&x0_str, fmt, x0) < 0)
|
||||
xalloc_die ();
|
||||
print_extra_number = !STREQ (x0_str, x_str);
|
||||
free (x0_str);
|
||||
}
|
||||
|
||||
free (x_str);
|
||||
if (! print_extra_number)
|
||||
break;
|
||||
}
|
||||
free (x_str);
|
||||
if (! print_extra_number)
|
||||
break;
|
||||
}
|
||||
|
||||
fputs (separator, stdout);
|
||||
}
|
||||
fputs (separator, stdout);
|
||||
}
|
||||
|
||||
fputs (terminator, stdout);
|
||||
}
|
||||
@@ -310,28 +310,28 @@ get_default_format (operand first, operand step, operand last)
|
||||
if (prec != INT_MAX && last.precision != INT_MAX)
|
||||
{
|
||||
if (equal_width)
|
||||
{
|
||||
/* increase first_width by any increased precision in step */
|
||||
size_t first_width = first.width + (prec - first.precision);
|
||||
/* adjust last_width to use precision from first/step */
|
||||
size_t last_width = last.width + (prec - last.precision);
|
||||
if (last.precision && prec == 0)
|
||||
last_width--; /* don't include space for '.' */
|
||||
if (last.precision == 0 && prec)
|
||||
last_width++; /* include space for '.' */
|
||||
size_t width = MAX (first_width, last_width);
|
||||
if (width <= INT_MAX)
|
||||
{
|
||||
int w = width;
|
||||
sprintf (format_buf, "%%0%d.%dLf", w, prec);
|
||||
return format_buf;
|
||||
}
|
||||
}
|
||||
{
|
||||
/* increase first_width by any increased precision in step */
|
||||
size_t first_width = first.width + (prec - first.precision);
|
||||
/* adjust last_width to use precision from first/step */
|
||||
size_t last_width = last.width + (prec - last.precision);
|
||||
if (last.precision && prec == 0)
|
||||
last_width--; /* don't include space for '.' */
|
||||
if (last.precision == 0 && prec)
|
||||
last_width++; /* include space for '.' */
|
||||
size_t width = MAX (first_width, last_width);
|
||||
if (width <= INT_MAX)
|
||||
{
|
||||
int w = width;
|
||||
sprintf (format_buf, "%%0%d.%dLf", w, prec);
|
||||
return format_buf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (format_buf, "%%.%dLf", prec);
|
||||
return format_buf;
|
||||
}
|
||||
{
|
||||
sprintf (format_buf, "%%.%dLf", prec);
|
||||
return format_buf;
|
||||
}
|
||||
}
|
||||
|
||||
return "%Lg";
|
||||
@@ -366,37 +366,37 @@ main (int argc, char **argv)
|
||||
while (optind < argc)
|
||||
{
|
||||
if (argv[optind][0] == '-'
|
||||
&& ((optc = argv[optind][1]) == '.' || ISDIGIT (optc)))
|
||||
{
|
||||
/* means negative number */
|
||||
break;
|
||||
}
|
||||
&& ((optc = argv[optind][1]) == '.' || ISDIGIT (optc)))
|
||||
{
|
||||
/* means negative number */
|
||||
break;
|
||||
}
|
||||
|
||||
optc = getopt_long (argc, argv, "+f:s:w", long_options, NULL);
|
||||
if (optc == -1)
|
||||
break;
|
||||
break;
|
||||
|
||||
switch (optc)
|
||||
{
|
||||
case 'f':
|
||||
format_str = optarg;
|
||||
break;
|
||||
{
|
||||
case 'f':
|
||||
format_str = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
separator = optarg;
|
||||
break;
|
||||
case 's':
|
||||
separator = optarg;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
equal_width = true;
|
||||
break;
|
||||
case 'w':
|
||||
equal_width = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc - optind < 1)
|
||||
@@ -422,10 +422,10 @@ main (int argc, char **argv)
|
||||
last = scan_arg (argv[optind++]);
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
step = last;
|
||||
last = scan_arg (argv[optind++]);
|
||||
}
|
||||
{
|
||||
step = last;
|
||||
last = scan_arg (argv[optind++]);
|
||||
}
|
||||
}
|
||||
|
||||
if (format_str != NULL && equal_width)
|
||||
|
||||
+317
-317
@@ -152,7 +152,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... FILE...\n"), program_name);
|
||||
@@ -282,9 +282,9 @@ static bool
|
||||
ignorable_sync_errno (int errno_val)
|
||||
{
|
||||
return (errno_val == EINVAL
|
||||
|| errno_val == EBADF
|
||||
/* HP-UX does this */
|
||||
|| errno_val == EISDIR);
|
||||
|| errno_val == EBADF
|
||||
/* HP-UX does this */
|
||||
|| errno_val == EISDIR);
|
||||
}
|
||||
|
||||
/* Request that all data for FD be transferred to the corresponding
|
||||
@@ -333,13 +333,13 @@ direct_mode (int fd, bool enable)
|
||||
{
|
||||
int fd_flags = fcntl (fd, F_GETFL);
|
||||
if (0 < fd_flags)
|
||||
{
|
||||
int new_flags = (enable
|
||||
? (fd_flags | O_DIRECT)
|
||||
: (fd_flags & ~O_DIRECT));
|
||||
if (new_flags != fd_flags)
|
||||
fcntl (fd, F_SETFL, new_flags);
|
||||
}
|
||||
{
|
||||
int new_flags = (enable
|
||||
? (fd_flags | O_DIRECT)
|
||||
: (fd_flags & ~O_DIRECT));
|
||||
if (new_flags != fd_flags)
|
||||
fcntl (fd, F_SETFL, new_flags);
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_DIRECTIO && defined DIRECTIO_ON && defined DIRECTIO_OFF
|
||||
@@ -361,7 +361,7 @@ direct_mode (int fd, bool enable)
|
||||
*/
|
||||
static int
|
||||
dopass (int fd, char const *qname, off_t *sizep, int type,
|
||||
struct randread_source *s, unsigned long int k, unsigned long int n)
|
||||
struct randread_source *s, unsigned long int k, unsigned long int n)
|
||||
{
|
||||
off_t size = *sizep;
|
||||
off_t offset; /* Current file posiiton */
|
||||
@@ -422,144 +422,144 @@ dopass (int fd, char const *qname, off_t *sizep, int type,
|
||||
/* How much to write this time? */
|
||||
lim = sizeof r;
|
||||
if (0 <= size && size - offset < sizeof_r)
|
||||
{
|
||||
if (size < offset)
|
||||
break;
|
||||
lim = size - offset;
|
||||
if (!lim)
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (size < offset)
|
||||
break;
|
||||
lim = size - offset;
|
||||
if (!lim)
|
||||
break;
|
||||
}
|
||||
if (type < 0)
|
||||
randread (s, &r, lim);
|
||||
randread (s, &r, lim);
|
||||
/* Loop to retry partial writes. */
|
||||
for (soff = 0; soff < lim; soff += ssize, first_write = false)
|
||||
{
|
||||
ssize = write (fd, r.c + soff, lim - soff);
|
||||
if (ssize <= 0)
|
||||
{
|
||||
if (size < 0 && (ssize == 0 || errno == ENOSPC))
|
||||
{
|
||||
/* Ah, we have found the end of the file */
|
||||
*sizep = size = offset + soff;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
int errnum = errno;
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
{
|
||||
ssize = write (fd, r.c + soff, lim - soff);
|
||||
if (ssize <= 0)
|
||||
{
|
||||
if (size < 0 && (ssize == 0 || errno == ENOSPC))
|
||||
{
|
||||
/* Ah, we have found the end of the file */
|
||||
*sizep = size = offset + soff;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
int errnum = errno;
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
|
||||
/* If the first write of the first pass for a given file
|
||||
has just failed with EINVAL, turn off direct mode I/O
|
||||
and try again. This works around a bug in Linux kernel
|
||||
2.4 whereby opening with O_DIRECT would succeed for some
|
||||
file system types (e.g., ext3), but any attempt to
|
||||
access a file through the resulting descriptor would
|
||||
fail with EINVAL. */
|
||||
if (k == 1 && first_write && errno == EINVAL)
|
||||
{
|
||||
direct_mode (fd, false);
|
||||
ssize = 0;
|
||||
continue;
|
||||
}
|
||||
error (0, errnum, _("%s: error writing at offset %s"),
|
||||
qname, umaxtostr (offset + soff, buf));
|
||||
/* If the first write of the first pass for a given file
|
||||
has just failed with EINVAL, turn off direct mode I/O
|
||||
and try again. This works around a bug in Linux kernel
|
||||
2.4 whereby opening with O_DIRECT would succeed for some
|
||||
file system types (e.g., ext3), but any attempt to
|
||||
access a file through the resulting descriptor would
|
||||
fail with EINVAL. */
|
||||
if (k == 1 && first_write && errno == EINVAL)
|
||||
{
|
||||
direct_mode (fd, false);
|
||||
ssize = 0;
|
||||
continue;
|
||||
}
|
||||
error (0, errnum, _("%s: error writing at offset %s"),
|
||||
qname, umaxtostr (offset + soff, buf));
|
||||
|
||||
/* 'shred' is often used on bad media, before throwing it
|
||||
out. Thus, it shouldn't give up on bad blocks. This
|
||||
code works because lim is always a multiple of
|
||||
SECTOR_SIZE, except at the end. */
|
||||
verify (sizeof r % SECTOR_SIZE == 0);
|
||||
if (errnum == EIO && 0 <= size && (soff | SECTOR_MASK) < lim)
|
||||
{
|
||||
size_t soff1 = (soff | SECTOR_MASK) + 1;
|
||||
if (lseek (fd, offset + soff1, SEEK_SET) != -1)
|
||||
{
|
||||
/* Arrange to skip this block. */
|
||||
ssize = soff1 - soff;
|
||||
write_error = true;
|
||||
continue;
|
||||
}
|
||||
error (0, errno, _("%s: lseek failed"), qname);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* 'shred' is often used on bad media, before throwing it
|
||||
out. Thus, it shouldn't give up on bad blocks. This
|
||||
code works because lim is always a multiple of
|
||||
SECTOR_SIZE, except at the end. */
|
||||
verify (sizeof r % SECTOR_SIZE == 0);
|
||||
if (errnum == EIO && 0 <= size && (soff | SECTOR_MASK) < lim)
|
||||
{
|
||||
size_t soff1 = (soff | SECTOR_MASK) + 1;
|
||||
if (lseek (fd, offset + soff1, SEEK_SET) != -1)
|
||||
{
|
||||
/* Arrange to skip this block. */
|
||||
ssize = soff1 - soff;
|
||||
write_error = true;
|
||||
continue;
|
||||
}
|
||||
error (0, errno, _("%s: lseek failed"), qname);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Okay, we have written "soff" bytes. */
|
||||
|
||||
if (offset > OFF_T_MAX - (off_t) soff)
|
||||
{
|
||||
error (0, 0, _("%s: file too large"), qname);
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
error (0, 0, _("%s: file too large"), qname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset += soff;
|
||||
|
||||
/* Time to print progress? */
|
||||
if (n
|
||||
&& ((offset == size && *previous_human_offset)
|
||||
|| thresh <= (now = time (NULL))))
|
||||
{
|
||||
char offset_buf[LONGEST_HUMAN_READABLE + 1];
|
||||
char size_buf[LONGEST_HUMAN_READABLE + 1];
|
||||
int human_progress_opts = (human_autoscale | human_SI
|
||||
| human_base_1024 | human_B);
|
||||
char const *human_offset
|
||||
= human_readable (offset, offset_buf,
|
||||
human_floor | human_progress_opts, 1, 1);
|
||||
&& ((offset == size && *previous_human_offset)
|
||||
|| thresh <= (now = time (NULL))))
|
||||
{
|
||||
char offset_buf[LONGEST_HUMAN_READABLE + 1];
|
||||
char size_buf[LONGEST_HUMAN_READABLE + 1];
|
||||
int human_progress_opts = (human_autoscale | human_SI
|
||||
| human_base_1024 | human_B);
|
||||
char const *human_offset
|
||||
= human_readable (offset, offset_buf,
|
||||
human_floor | human_progress_opts, 1, 1);
|
||||
|
||||
if (offset == size
|
||||
|| !STREQ (previous_human_offset, human_offset))
|
||||
{
|
||||
if (size < 0)
|
||||
error (0, 0, _("%s: pass %lu/%lu (%s)...%s"),
|
||||
qname, k, n, pass_string, human_offset);
|
||||
else
|
||||
{
|
||||
uintmax_t off = offset;
|
||||
int percent = (size == 0
|
||||
? 100
|
||||
: (off <= TYPE_MAXIMUM (uintmax_t) / 100
|
||||
? off * 100 / size
|
||||
: off / (size / 100)));
|
||||
char const *human_size
|
||||
= human_readable (size, size_buf,
|
||||
human_ceiling | human_progress_opts,
|
||||
1, 1);
|
||||
if (offset == size)
|
||||
human_offset = human_size;
|
||||
error (0, 0, _("%s: pass %lu/%lu (%s)...%s/%s %d%%"),
|
||||
qname, k, n, pass_string, human_offset, human_size,
|
||||
percent);
|
||||
}
|
||||
if (offset == size
|
||||
|| !STREQ (previous_human_offset, human_offset))
|
||||
{
|
||||
if (size < 0)
|
||||
error (0, 0, _("%s: pass %lu/%lu (%s)...%s"),
|
||||
qname, k, n, pass_string, human_offset);
|
||||
else
|
||||
{
|
||||
uintmax_t off = offset;
|
||||
int percent = (size == 0
|
||||
? 100
|
||||
: (off <= TYPE_MAXIMUM (uintmax_t) / 100
|
||||
? off * 100 / size
|
||||
: off / (size / 100)));
|
||||
char const *human_size
|
||||
= human_readable (size, size_buf,
|
||||
human_ceiling | human_progress_opts,
|
||||
1, 1);
|
||||
if (offset == size)
|
||||
human_offset = human_size;
|
||||
error (0, 0, _("%s: pass %lu/%lu (%s)...%s/%s %d%%"),
|
||||
qname, k, n, pass_string, human_offset, human_size,
|
||||
percent);
|
||||
}
|
||||
|
||||
strcpy (previous_offset_buf, human_offset);
|
||||
previous_human_offset = previous_offset_buf;
|
||||
thresh = now + VERBOSE_UPDATE;
|
||||
strcpy (previous_offset_buf, human_offset);
|
||||
previous_human_offset = previous_offset_buf;
|
||||
thresh = now + VERBOSE_UPDATE;
|
||||
|
||||
/*
|
||||
* Force periodic syncs to keep displayed progress accurate
|
||||
* FIXME: Should these be present even if -v is not enabled,
|
||||
* to keep the buffer cache from filling with dirty pages?
|
||||
* It's a common problem with programs that do lots of writes,
|
||||
* like mkfs.
|
||||
*/
|
||||
if (dosync (fd, qname) != 0)
|
||||
{
|
||||
if (errno != EIO)
|
||||
return -1;
|
||||
write_error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Force periodic syncs to keep displayed progress accurate
|
||||
* FIXME: Should these be present even if -v is not enabled,
|
||||
* to keep the buffer cache from filling with dirty pages?
|
||||
* It's a common problem with programs that do lots of writes,
|
||||
* like mkfs.
|
||||
*/
|
||||
if (dosync (fd, qname) != 0)
|
||||
{
|
||||
if (errno != EIO)
|
||||
return -1;
|
||||
write_error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Force what we just wrote to hit the media. */
|
||||
if (dosync (fd, qname) != 0)
|
||||
{
|
||||
if (errno != EIO)
|
||||
return -1;
|
||||
return -1;
|
||||
write_error = true;
|
||||
}
|
||||
|
||||
@@ -631,7 +631,7 @@ static int const
|
||||
12, 0x111, 0x222, 0x333, 0x444, 0x666, 0x777,
|
||||
0x888, 0x999, 0xBBB, 0xCCC, 0xDDD, 0xEEE, /* 4-bit */
|
||||
-1, /* 1 random pass */
|
||||
/* The following patterns have the frst bit per block flipped */
|
||||
/* The following patterns have the frst bit per block flipped */
|
||||
8, 0x1000, 0x1249, 0x1492, 0x16DB, 0x1924, 0x1B6D, 0x1DB6, 0x1FFF,
|
||||
14, 0x1111, 0x1222, 0x1333, 0x1444, 0x1555, 0x1666, 0x1777,
|
||||
0x1888, 0x1999, 0x1AAA, 0x1BBB, 0x1CCC, 0x1DDD, 0x1EEE,
|
||||
@@ -668,47 +668,47 @@ genpattern (int *dest, size_t num, struct randint_source *s)
|
||||
{
|
||||
k = *p++; /* Block descriptor word */
|
||||
if (!k)
|
||||
{ /* Loop back to the beginning */
|
||||
p = patterns;
|
||||
}
|
||||
{ /* Loop back to the beginning */
|
||||
p = patterns;
|
||||
}
|
||||
else if (k < 0)
|
||||
{ /* -k random passes */
|
||||
k = -k;
|
||||
if ((size_t) k >= n)
|
||||
{
|
||||
randpasses += n;
|
||||
n = 0;
|
||||
break;
|
||||
}
|
||||
randpasses += k;
|
||||
n -= k;
|
||||
}
|
||||
{ /* -k random passes */
|
||||
k = -k;
|
||||
if ((size_t) k >= n)
|
||||
{
|
||||
randpasses += n;
|
||||
n = 0;
|
||||
break;
|
||||
}
|
||||
randpasses += k;
|
||||
n -= k;
|
||||
}
|
||||
else if ((size_t) k <= n)
|
||||
{ /* Full block of patterns */
|
||||
memcpy (d, p, k * sizeof (int));
|
||||
p += k;
|
||||
d += k;
|
||||
n -= k;
|
||||
}
|
||||
{ /* Full block of patterns */
|
||||
memcpy (d, p, k * sizeof (int));
|
||||
p += k;
|
||||
d += k;
|
||||
n -= k;
|
||||
}
|
||||
else if (n < 2 || 3 * n < (size_t) k)
|
||||
{ /* Finish with random */
|
||||
randpasses += n;
|
||||
break;
|
||||
}
|
||||
{ /* Finish with random */
|
||||
randpasses += n;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{ /* Pad out with k of the n available */
|
||||
do
|
||||
{
|
||||
if (n == (size_t) k || randint_choose (s, k) < n)
|
||||
{
|
||||
*d++ = *p;
|
||||
n--;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (n);
|
||||
break;
|
||||
}
|
||||
{ /* Pad out with k of the n available */
|
||||
do
|
||||
{
|
||||
if (n == (size_t) k || randint_choose (s, k) < n)
|
||||
{
|
||||
*d++ = *p;
|
||||
n--;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
top = num - randpasses; /* Top of initialized data */
|
||||
/* assert (d == dest+top); */
|
||||
@@ -738,18 +738,18 @@ genpattern (int *dest, size_t num, struct randint_source *s)
|
||||
for (n = 0; n < num; n++)
|
||||
{
|
||||
if (accum <= randpasses)
|
||||
{
|
||||
accum += num - 1;
|
||||
dest[top++] = dest[n];
|
||||
dest[n] = -1;
|
||||
}
|
||||
{
|
||||
accum += num - 1;
|
||||
dest[top++] = dest[n];
|
||||
dest[n] = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
swap = n + randint_choose (s, top - n);
|
||||
k = dest[n];
|
||||
dest[n] = dest[swap];
|
||||
dest[swap] = k;
|
||||
}
|
||||
{
|
||||
swap = n + randint_choose (s, top - n);
|
||||
k = dest[n];
|
||||
dest[n] = dest[swap];
|
||||
dest[swap] = k;
|
||||
}
|
||||
accum -= randpasses;
|
||||
}
|
||||
/* assert (top == num); */
|
||||
@@ -761,7 +761,7 @@ genpattern (int *dest, size_t num, struct randint_source *s)
|
||||
*/
|
||||
static bool
|
||||
do_wipefd (int fd, char const *qname, struct randint_source *s,
|
||||
struct Options const *flags)
|
||||
struct Options const *flags)
|
||||
{
|
||||
size_t i;
|
||||
struct stat st;
|
||||
@@ -801,36 +801,36 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
|
||||
if (size == -1)
|
||||
{
|
||||
/* Accept a length of zero only if it's a regular file.
|
||||
For any other type of file, try to get the size another way. */
|
||||
For any other type of file, try to get the size another way. */
|
||||
if (S_ISREG (st.st_mode))
|
||||
{
|
||||
size = st.st_size;
|
||||
if (size < 0)
|
||||
{
|
||||
error (0, 0, _("%s: file has negative size"), qname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
{
|
||||
size = st.st_size;
|
||||
if (size < 0)
|
||||
{
|
||||
error (0, 0, _("%s: file has negative size"), qname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = lseek (fd, 0, SEEK_END);
|
||||
if (size <= 0)
|
||||
{
|
||||
/* We are unable to determine the length, up front.
|
||||
Let dopass do that as part of its first iteration. */
|
||||
size = -1;
|
||||
}
|
||||
}
|
||||
{
|
||||
size = lseek (fd, 0, SEEK_END);
|
||||
if (size <= 0)
|
||||
{
|
||||
/* We are unable to determine the length, up front.
|
||||
Let dopass do that as part of its first iteration. */
|
||||
size = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allow `rounding up' only for regular files. */
|
||||
if (0 <= size && !(flags->exact) && S_ISREG (st.st_mode))
|
||||
{
|
||||
size += ST_BLKSIZE (st) - 1 - (size - 1) % ST_BLKSIZE (st);
|
||||
{
|
||||
size += ST_BLKSIZE (st) - 1 - (size - 1) % ST_BLKSIZE (st);
|
||||
|
||||
/* If in rounding up, we've just overflowed, use the maximum. */
|
||||
if (size < 0)
|
||||
size = TYPE_MAXIMUM (off_t);
|
||||
}
|
||||
/* If in rounding up, we've just overflowed, use the maximum. */
|
||||
if (size < 0)
|
||||
size = TYPE_MAXIMUM (off_t);
|
||||
}
|
||||
}
|
||||
|
||||
/* Schedule the passes in random order. */
|
||||
@@ -843,15 +843,15 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
|
||||
{
|
||||
int err = dopass (fd, qname, &size, passarray[i], rs, i + 1, n);
|
||||
if (err)
|
||||
{
|
||||
if (err < 0)
|
||||
{
|
||||
memset (passarray, 0, flags->n_iterations * sizeof (int));
|
||||
free (passarray);
|
||||
return false;
|
||||
}
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
if (err < 0)
|
||||
{
|
||||
memset (passarray, 0, flags->n_iterations * sizeof (int));
|
||||
free (passarray);
|
||||
return false;
|
||||
}
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
memset (passarray, 0, flags->n_iterations * sizeof (int));
|
||||
@@ -861,11 +861,11 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
|
||||
{
|
||||
int err = dopass (fd, qname, &size, 0, rs, flags->n_iterations + 1, n);
|
||||
if (err)
|
||||
{
|
||||
if (err < 0)
|
||||
return false;
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
if (err < 0)
|
||||
return false;
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Okay, now deallocate the data. The effect of ftruncate on
|
||||
@@ -884,7 +884,7 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
|
||||
/* A wrapper with a little more checking for fds on the command line */
|
||||
static bool
|
||||
wipefd (int fd, char const *qname, struct randint_source *s,
|
||||
struct Options const *flags)
|
||||
struct Options const *flags)
|
||||
{
|
||||
int fd_flags = fcntl (fd, F_GETFL);
|
||||
|
||||
@@ -921,10 +921,10 @@ incname (char *name, size_t len)
|
||||
|
||||
/* If this character has a successor, use it. */
|
||||
if (p[1])
|
||||
{
|
||||
name[len] = p[1];
|
||||
return true;
|
||||
}
|
||||
{
|
||||
name[len] = p[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Otherwise, set this digit to 0 and increment the prefix. */
|
||||
name[len] = nameset[0];
|
||||
@@ -980,40 +980,40 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags)
|
||||
memset (base, nameset[0], len);
|
||||
base[len] = 0;
|
||||
do
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat (newname, &st) < 0)
|
||||
{
|
||||
if (rename (oldname, newname) == 0)
|
||||
{
|
||||
if (0 <= dir_fd && dosync (dir_fd, qdir) != 0)
|
||||
ok = false;
|
||||
if (flags->verbose)
|
||||
{
|
||||
/*
|
||||
* People seem to understand this better than talking
|
||||
* about renaming oldname. newname doesn't need
|
||||
* quoting because we picked it. oldname needs to
|
||||
* be quoted only the first time.
|
||||
*/
|
||||
char const *old = (first ? qoldname : oldname);
|
||||
error (0, 0, _("%s: renamed to %s"), old, newname);
|
||||
first = false;
|
||||
}
|
||||
memcpy (oldname + (base - newname), base, len + 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The rename failed: give up on this length. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* newname exists, so increment BASE so we use another */
|
||||
}
|
||||
}
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat (newname, &st) < 0)
|
||||
{
|
||||
if (rename (oldname, newname) == 0)
|
||||
{
|
||||
if (0 <= dir_fd && dosync (dir_fd, qdir) != 0)
|
||||
ok = false;
|
||||
if (flags->verbose)
|
||||
{
|
||||
/*
|
||||
* People seem to understand this better than talking
|
||||
* about renaming oldname. newname doesn't need
|
||||
* quoting because we picked it. oldname needs to
|
||||
* be quoted only the first time.
|
||||
*/
|
||||
char const *old = (first ? qoldname : oldname);
|
||||
error (0, 0, _("%s: renamed to %s"), old, newname);
|
||||
first = false;
|
||||
}
|
||||
memcpy (oldname + (base - newname), base, len + 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The rename failed: give up on this length. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* newname exists, so increment BASE so we use another */
|
||||
}
|
||||
}
|
||||
while (incname (base, len));
|
||||
len--;
|
||||
}
|
||||
@@ -1027,12 +1027,12 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags)
|
||||
if (0 <= dir_fd)
|
||||
{
|
||||
if (dosync (dir_fd, qdir) != 0)
|
||||
ok = false;
|
||||
ok = false;
|
||||
if (close (dir_fd) != 0)
|
||||
{
|
||||
error (0, errno, _("%s: failed to close"), qdir);
|
||||
ok = false;
|
||||
}
|
||||
{
|
||||
error (0, errno, _("%s: failed to close"), qdir);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
free (newname);
|
||||
free (dir);
|
||||
@@ -1054,7 +1054,7 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags)
|
||||
*/
|
||||
static bool
|
||||
wipefile (char *name, char const *qname,
|
||||
struct randint_source *s, struct Options const *flags)
|
||||
struct randint_source *s, struct Options const *flags)
|
||||
{
|
||||
bool ok;
|
||||
int fd;
|
||||
@@ -1120,66 +1120,66 @@ main (int argc, char **argv)
|
||||
while ((c = getopt_long (argc, argv, "fn:s:uvxz", long_opts, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'f':
|
||||
flags.force = true;
|
||||
break;
|
||||
{
|
||||
case 'f':
|
||||
flags.force = true;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
{
|
||||
uintmax_t tmp;
|
||||
if (xstrtoumax (optarg, NULL, 10, &tmp, NULL) != LONGINT_OK
|
||||
|| MIN (UINT32_MAX, SIZE_MAX / sizeof (int)) < tmp)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid number of passes"),
|
||||
quotearg_colon (optarg));
|
||||
}
|
||||
flags.n_iterations = tmp;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
{
|
||||
uintmax_t tmp;
|
||||
if (xstrtoumax (optarg, NULL, 10, &tmp, NULL) != LONGINT_OK
|
||||
|| MIN (UINT32_MAX, SIZE_MAX / sizeof (int)) < tmp)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid number of passes"),
|
||||
quotearg_colon (optarg));
|
||||
}
|
||||
flags.n_iterations = tmp;
|
||||
}
|
||||
break;
|
||||
|
||||
case RANDOM_SOURCE_OPTION:
|
||||
if (random_source && !STREQ (random_source, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple random sources specified"));
|
||||
random_source = optarg;
|
||||
break;
|
||||
case RANDOM_SOURCE_OPTION:
|
||||
if (random_source && !STREQ (random_source, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple random sources specified"));
|
||||
random_source = optarg;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
flags.remove_file = true;
|
||||
break;
|
||||
case 'u':
|
||||
flags.remove_file = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
{
|
||||
uintmax_t tmp;
|
||||
if (xstrtoumax (optarg, NULL, 0, &tmp, "cbBkKMGTPEZY0")
|
||||
!= LONGINT_OK)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid file size"),
|
||||
quotearg_colon (optarg));
|
||||
}
|
||||
flags.size = tmp;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
uintmax_t tmp;
|
||||
if (xstrtoumax (optarg, NULL, 0, &tmp, "cbBkKMGTPEZY0")
|
||||
!= LONGINT_OK)
|
||||
{
|
||||
error (EXIT_FAILURE, 0, _("%s: invalid file size"),
|
||||
quotearg_colon (optarg));
|
||||
}
|
||||
flags.size = tmp;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
flags.verbose = true;
|
||||
break;
|
||||
case 'v':
|
||||
flags.verbose = true;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
flags.exact = true;
|
||||
break;
|
||||
case 'x':
|
||||
flags.exact = true;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
flags.zero_fill = true;
|
||||
break;
|
||||
case 'z':
|
||||
flags.zero_fill = true;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
file = argv + optind;
|
||||
@@ -1200,14 +1200,14 @@ main (int argc, char **argv)
|
||||
{
|
||||
char *qname = xstrdup (quotearg_colon (file[i]));
|
||||
if (STREQ (file[i], "-"))
|
||||
{
|
||||
ok &= wipefd (STDOUT_FILENO, qname, randint_source, &flags);
|
||||
}
|
||||
{
|
||||
ok &= wipefd (STDOUT_FILENO, qname, randint_source, &flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Plain filename - Note that this overwrites *argv! */
|
||||
ok &= wipefile (file[i], qname, randint_source, &flags);
|
||||
}
|
||||
{
|
||||
/* Plain filename - Note that this overwrites *argv! */
|
||||
ok &= wipefile (file[i], qname, randint_source, &flags);
|
||||
}
|
||||
free (qname);
|
||||
}
|
||||
|
||||
|
||||
+94
-94
@@ -41,7 +41,7 @@ usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
@@ -49,7 +49,7 @@ Usage: %s [OPTION]... [FILE]\n\
|
||||
or: %s -e [OPTION]... [ARG]...\n\
|
||||
or: %s -i LO-HI [OPTION]...\n\
|
||||
"),
|
||||
program_name, program_name, program_name);
|
||||
program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
Write a random permutation of the input lines to standard output.\n\
|
||||
\n\
|
||||
@@ -163,27 +163,27 @@ read_input (FILE *in, char eolbyte, char ***pline)
|
||||
off_t file_size = instat.st_size;
|
||||
off_t current_offset = ftello (in);
|
||||
if (0 <= current_offset)
|
||||
{
|
||||
off_t remaining_size =
|
||||
(current_offset < file_size ? file_size - current_offset : 0);
|
||||
if (SIZE_MAX - 2 < remaining_size)
|
||||
xalloc_die ();
|
||||
next_alloc = remaining_size + 2;
|
||||
}
|
||||
{
|
||||
off_t remaining_size =
|
||||
(current_offset < file_size ? file_size - current_offset : 0);
|
||||
if (SIZE_MAX - 2 < remaining_size)
|
||||
xalloc_die ();
|
||||
next_alloc = remaining_size + 2;
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (alloc <= used + 1)
|
||||
{
|
||||
if (alloc == SIZE_MAX)
|
||||
xalloc_die ();
|
||||
alloc = next_alloc;
|
||||
next_alloc = alloc * 2;
|
||||
if (next_alloc < alloc)
|
||||
next_alloc = SIZE_MAX;
|
||||
buf = xrealloc (buf, alloc);
|
||||
}
|
||||
{
|
||||
if (alloc == SIZE_MAX)
|
||||
xalloc_die ();
|
||||
alloc = next_alloc;
|
||||
next_alloc = alloc * 2;
|
||||
if (next_alloc < alloc)
|
||||
next_alloc = SIZE_MAX;
|
||||
buf = xrealloc (buf, alloc);
|
||||
}
|
||||
|
||||
bytes_to_read = alloc - used - 1;
|
||||
nread = fread (buf + used, sizeof (char), bytes_to_read, in);
|
||||
@@ -214,24 +214,24 @@ read_input (FILE *in, char eolbyte, char ***pline)
|
||||
|
||||
static int
|
||||
write_permuted_output (size_t n_lines, char * const *line, size_t lo_input,
|
||||
size_t const *permutation, char eolbyte)
|
||||
size_t const *permutation, char eolbyte)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (line)
|
||||
for (i = 0; i < n_lines; i++)
|
||||
{
|
||||
char * const *p = line + permutation[i];
|
||||
size_t len = p[1] - p[0];
|
||||
if (fwrite (p[0], sizeof *p[0], len, stdout) != len)
|
||||
return -1;
|
||||
char * const *p = line + permutation[i];
|
||||
size_t len = p[1] - p[0];
|
||||
if (fwrite (p[0], sizeof *p[0], len, stdout) != len)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
for (i = 0; i < n_lines; i++)
|
||||
{
|
||||
unsigned long int n = lo_input + permutation[i];
|
||||
if (printf ("%lu%c", n, eolbyte) < 0)
|
||||
return -1;
|
||||
unsigned long int n = lo_input + permutation[i];
|
||||
if (printf ("%lu%c", n, eolbyte) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -269,75 +269,75 @@ main (int argc, char **argv)
|
||||
switch (optc)
|
||||
{
|
||||
case 'e':
|
||||
echo = true;
|
||||
break;
|
||||
echo = true;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
{
|
||||
unsigned long int argval = 0;
|
||||
char *p = strchr (optarg, '-');
|
||||
char const *hi_optarg = optarg;
|
||||
bool invalid = !p;
|
||||
{
|
||||
unsigned long int argval = 0;
|
||||
char *p = strchr (optarg, '-');
|
||||
char const *hi_optarg = optarg;
|
||||
bool invalid = !p;
|
||||
|
||||
if (input_numbers_option_used (lo_input, hi_input))
|
||||
error (EXIT_FAILURE, 0, _("multiple -i options specified"));
|
||||
if (input_numbers_option_used (lo_input, hi_input))
|
||||
error (EXIT_FAILURE, 0, _("multiple -i options specified"));
|
||||
|
||||
if (p)
|
||||
{
|
||||
*p = '\0';
|
||||
invalid = ((xstrtoul (optarg, NULL, 10, &argval, NULL)
|
||||
!= LONGINT_OK)
|
||||
|| SIZE_MAX < argval);
|
||||
*p = '-';
|
||||
lo_input = argval;
|
||||
hi_optarg = p + 1;
|
||||
}
|
||||
if (p)
|
||||
{
|
||||
*p = '\0';
|
||||
invalid = ((xstrtoul (optarg, NULL, 10, &argval, NULL)
|
||||
!= LONGINT_OK)
|
||||
|| SIZE_MAX < argval);
|
||||
*p = '-';
|
||||
lo_input = argval;
|
||||
hi_optarg = p + 1;
|
||||
}
|
||||
|
||||
invalid |= ((xstrtoul (hi_optarg, NULL, 10, &argval, NULL)
|
||||
!= LONGINT_OK)
|
||||
|| SIZE_MAX < argval);
|
||||
hi_input = argval;
|
||||
n_lines = hi_input - lo_input + 1;
|
||||
invalid |= ((lo_input <= hi_input) == (n_lines == 0));
|
||||
if (invalid)
|
||||
error (EXIT_FAILURE, 0, _("invalid input range %s"),
|
||||
quote (optarg));
|
||||
}
|
||||
break;
|
||||
invalid |= ((xstrtoul (hi_optarg, NULL, 10, &argval, NULL)
|
||||
!= LONGINT_OK)
|
||||
|| SIZE_MAX < argval);
|
||||
hi_input = argval;
|
||||
n_lines = hi_input - lo_input + 1;
|
||||
invalid |= ((lo_input <= hi_input) == (n_lines == 0));
|
||||
if (invalid)
|
||||
error (EXIT_FAILURE, 0, _("invalid input range %s"),
|
||||
quote (optarg));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
{
|
||||
unsigned long int argval;
|
||||
strtol_error e = xstrtoul (optarg, NULL, 10, &argval, NULL);
|
||||
{
|
||||
unsigned long int argval;
|
||||
strtol_error e = xstrtoul (optarg, NULL, 10, &argval, NULL);
|
||||
|
||||
if (e == LONGINT_OK)
|
||||
head_lines = MIN (head_lines, argval);
|
||||
else if (e != LONGINT_OVERFLOW)
|
||||
error (EXIT_FAILURE, 0, _("invalid line count %s"),
|
||||
quote (optarg));
|
||||
}
|
||||
break;
|
||||
if (e == LONGINT_OK)
|
||||
head_lines = MIN (head_lines, argval);
|
||||
else if (e != LONGINT_OVERFLOW)
|
||||
error (EXIT_FAILURE, 0, _("invalid line count %s"),
|
||||
quote (optarg));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
if (outfile && !STREQ (outfile, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple output files specified"));
|
||||
outfile = optarg;
|
||||
break;
|
||||
if (outfile && !STREQ (outfile, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple output files specified"));
|
||||
outfile = optarg;
|
||||
break;
|
||||
|
||||
case RANDOM_SOURCE_OPTION:
|
||||
if (random_source && !STREQ (random_source, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple random sources specified"));
|
||||
random_source = optarg;
|
||||
break;
|
||||
if (random_source && !STREQ (random_source, optarg))
|
||||
error (EXIT_FAILURE, 0, _("multiple random sources specified"));
|
||||
random_source = optarg;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
eolbyte = '\0';
|
||||
break;
|
||||
eolbyte = '\0';
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
n_operands = argc - optind;
|
||||
@@ -346,7 +346,7 @@ main (int argc, char **argv)
|
||||
if (echo)
|
||||
{
|
||||
if (input_numbers_option_used (lo_input, hi_input))
|
||||
error (EXIT_FAILURE, 0, _("cannot combine -e and -i options"));
|
||||
error (EXIT_FAILURE, 0, _("cannot combine -e and -i options"));
|
||||
input_from_argv (operand, n_operands, eolbyte);
|
||||
n_lines = n_operands;
|
||||
line = operand;
|
||||
@@ -354,29 +354,29 @@ main (int argc, char **argv)
|
||||
else if (input_numbers_option_used (lo_input, hi_input))
|
||||
{
|
||||
if (n_operands)
|
||||
{
|
||||
error (0, 0, _("extra operand %s\n"), quote (operand[0]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
error (0, 0, _("extra operand %s\n"), quote (operand[0]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
n_lines = hi_input - lo_input + 1;
|
||||
line = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (n_operands)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (! (STREQ (operand[0], "-") || freopen (operand[0], "r", stdin)))
|
||||
error (EXIT_FAILURE, errno, "%s", operand[0]);
|
||||
break;
|
||||
case 1:
|
||||
if (! (STREQ (operand[0], "-") || freopen (operand[0], "r", stdin)))
|
||||
error (EXIT_FAILURE, errno, "%s", operand[0]);
|
||||
break;
|
||||
|
||||
default:
|
||||
error (0, 0, _("extra operand %s"), quote (operand[1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
default:
|
||||
error (0, 0, _("extra operand %s"), quote (operand[1]));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
n_lines = read_input (stdin, eolbyte, &input_lines);
|
||||
line = input_lines;
|
||||
@@ -385,7 +385,7 @@ main (int argc, char **argv)
|
||||
head_lines = MIN (head_lines, n_lines);
|
||||
|
||||
randint_source = randint_all_new (random_source,
|
||||
randperm_bound (head_lines, n_lines));
|
||||
randperm_bound (head_lines, n_lines));
|
||||
if (! randint_source)
|
||||
error (EXIT_FAILURE, errno, "%s", quotearg_colon (random_source));
|
||||
|
||||
|
||||
Loaded 100 of 176 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user