summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-01-04 22:45:28 +0000
committerJim Meyering <jim@meyering.net>1998-01-04 22:45:28 +0000
commit5d4f8ebdfda9a4aadaeb30aebd34542e55bc13e1 (patch)
treeebcd4ea3aeb95093c8658d1442ee10612a29f438
parentb246280c27644ec0f08909d33e652cabb6b16981 (diff)
downloadcoreutils-5d4f8ebdfda9a4aadaeb30aebd34542e55bc13e1.tar.xz
(main, usage): Check for write error to stdout before exiting.
Include "closeout.h".
-rw-r--r--src/cp.c7
-rw-r--r--src/dd.c5
-rw-r--r--src/df.c6
-rw-r--r--src/dircolors.c7
-rw-r--r--src/du.c6
-rw-r--r--src/install.c7
-rw-r--r--src/ln.c7
-rw-r--r--src/ls.c9
-rw-r--r--src/mkdir.c5
-rw-r--r--src/mkfifo.c5
-rw-r--r--src/mknod.c5
-rw-r--r--src/mv.c7
-rw-r--r--src/rm.c7
-rw-r--r--src/rmdir.c5
-rw-r--r--src/sync.c4
-rw-r--r--src/touch.c5
16 files changed, 76 insertions, 21 deletions
diff --git a/src/cp.c b/src/cp.c
index d09a2f7cd..a2814c2a5 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -1,5 +1,5 @@
/* cp.c -- file copying (main routines)
- Copyright (C) 89, 90, 91, 95, 1996, 1997 Free Software Foundation.
+ Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,6 +33,7 @@
#include "backupfile.h"
#include "argmatch.h"
#include "path-concat.h"
+#include "closeout.h"
#include "cp-hash.h"
#include "copy.h"
#include "error.h"
@@ -176,6 +177,7 @@ options are given and SOURCE and DEST are the same name for an existing,\n\
regular file.\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -728,6 +730,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("cp (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -760,5 +763,7 @@ main (int argc, char **argv)
exit_status |= do_copy (argc, argv, &x);
+ if (x.verbose)
+ close_stdout ();
exit (exit_status);
}
diff --git a/src/dd.c b/src/dd.c
index f71502e62..3c1ff283c 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1,5 +1,5 @@
/* dd -- convert a file while copying it.
- Copyright (C) 85, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 85, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
#include "human.h"
#include "system.h"
+#include "closeout.h"
#include "error.h"
#ifndef SIGINFO
@@ -351,6 +352,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("dd (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -1137,6 +1139,7 @@ by w for x2, by b for x512, by k for x1024. Each KEYWORD may be:\n\
sync pad every input block with NULs to ibs-size\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
diff --git a/src/df.c b/src/df.c
index 7db3e763c..bcef2a252 100644
--- a/src/df.c
+++ b/src/df.c
@@ -1,5 +1,5 @@
/* df - summarize free disk space
- Copyright (C) 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,6 +32,7 @@
#include "fsusage.h"
#include "system.h"
#include "save-cwd.h"
+#include "closeout.h"
#include "error.h"
#include "human.h"
@@ -518,6 +519,7 @@ or all filesystems by default.\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -625,6 +627,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("df (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -716,6 +719,7 @@ with the portable output format"));
show_entry (argv[i], &stats[i - optind]);
}
+ close_stdout ();
exit (exit_status);
}
diff --git a/src/dircolors.c b/src/dircolors.c
index f024396a2..b16d7e27a 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -1,6 +1,6 @@
/* dircolors - output commands to set the LS_COLOR environment variable
Copyright (C) 1994, 1995, 1997 H. Peter Anvin
- Copyright (C) 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "system.h"
#include "getline.h"
#include "long-options.h"
+#include "closeout.h"
#include "error.h"
#include "obstack.h"
#include "dircolors.h"
@@ -114,6 +115,7 @@ file types and extensions. Otherwise, a precompiled database is used.\n\
For details on the format of these files, run `dircolors --print-database'.\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
@@ -516,8 +518,7 @@ dircolors' internal database"));
}
}
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
+ close_stdout ();
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
diff --git a/src/du.c b/src/du.c
index eee05318a..165d0dfd8 100644
--- a/src/du.c
+++ b/src/du.c
@@ -1,5 +1,5 @@
/* du -- summarize disk usage
- Copyright (C) 88, 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 88, 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -54,6 +54,7 @@
#include "exclude.h"
#include "system.h"
#include "save-cwd.h"
+#include "closeout.h"
#include "error.h"
#include "human.h"
#include "xstrtol.h"
@@ -238,6 +239,7 @@ Summarize disk usage of each FILE, recursively for directories.\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -372,6 +374,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("du (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -405,6 +408,7 @@ main (int argc, char **argv)
du_files (optind == argc ? cwd_only : argv + optind);
+ close_stdout ();
exit (exit_status);
}
diff --git a/src/install.c b/src/install.c
index 470da79a7..7cbd2f6db 100644
--- a/src/install.c
+++ b/src/install.c
@@ -1,5 +1,5 @@
/* install - copy files and set attributes
- Copyright (C) 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -70,6 +70,7 @@
#include "backupfile.h"
#include "modechange.h"
#include "makepath.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
@@ -257,6 +258,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("install (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -318,6 +320,8 @@ main (int argc, char **argv)
}
}
+ if (verbose)
+ close_stdout ();
exit (errors);
}
@@ -672,6 +676,7 @@ version control may be set with VERSION_CONTROL, values are:\n\
never, simple always make simple backups\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
diff --git a/src/ln.c b/src/ln.c
index 6078f48d0..70cb328ca 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -1,5 +1,5 @@
/* `ln' program to create links between files.
- Copyright (C) 86, 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 86, 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
#include "system.h"
#include "backupfile.h"
+#include "closeout.h"
#include "error.h"
int link (); /* Some systems don't declare this anywhere. */
@@ -353,6 +354,7 @@ version control may be set with VERSION_CONTROL, values are:\n\
never, simple always make simple backups\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -429,6 +431,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("ln (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -499,5 +502,7 @@ main (int argc, char **argv)
errors += do_link (argv[optind], to);
}
+ if (verbose)
+ close_stdout ();
exit (errors != 0);
}
diff --git a/src/ls.c b/src/ls.c
index 4f28157a9..561d52a16 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1,5 +1,5 @@
/* `dir', `vdir' and `ls' directory listing programs for GNU.
- Copyright (C) 85, 88, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 85, 88, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -65,6 +65,7 @@
#include "obstack.h"
#include "ls.h"
+#include "closeout.h"
#include "error.h"
#include "human.h"
#include "argmatch.h"
@@ -698,6 +699,7 @@ main (int argc, char **argv)
(ls_mode == LS_LS ? "ls"
: (ls_mode == LS_MULTI_COL ? "dir" : "vdir")),
GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (EXIT_SUCCESS);
}
@@ -782,9 +784,6 @@ main (int argc, char **argv)
dired_dump_obstack ("//SUBDIRED//", quoting_style, &subdired_obstack);
}
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
-
/* Restore default color before exiting */
if (print_with_color)
{
@@ -792,6 +791,7 @@ main (int argc, char **argv)
put_indicator (&color_indicator[C_RIGHT]);
}
+ close_stdout ();
exit (exit_status);
}
@@ -2990,6 +2990,7 @@ optional WHEN argument is equivalent to using --color=always. With\n\
to a terminal (tty).\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
diff --git a/src/mkdir.c b/src/mkdir.c
index a880b0096..89886e158 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -1,5 +1,5 @@
/* mkdir -- make directories
- Copyright (C) 90, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 90, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
#include "system.h"
#include "modechange.h"
#include "makepath.h"
+#include "closeout.h"
#include "error.h"
/* The name this program was run with. */
@@ -68,6 +69,7 @@ Create the DIRECTORY(ies), if they do not already exist.\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -112,6 +114,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("mkdir (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
diff --git a/src/mkfifo.c b/src/mkfifo.c
index 387fab993..d70dc15d7 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -1,5 +1,5 @@
/* mkfifo -- make fifo's (named pipes)
- Copyright (C) 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
#include "system.h"
#include "modechange.h"
+#include "closeout.h"
#include "error.h"
/* The name this program was run with. */
@@ -66,6 +67,7 @@ Create named pipes (FIFOs) with the given NAMEs.\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -107,6 +109,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("mkfifo (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
diff --git a/src/mknod.c b/src/mknod.c
index d2292f7f5..1233a15e6 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -1,5 +1,5 @@
/* mknod -- make special files
- Copyright (C) 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -34,6 +34,7 @@
#include "system.h"
#include "modechange.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
@@ -77,6 +78,7 @@ MAJOR MINOR are forbidden for TYPE p, mandatory otherwise. TYPE may be:\n\
p create a FIFO\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -116,6 +118,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("mknod (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
diff --git a/src/mv.c b/src/mv.c
index 9b08bf50f..c431a688c 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -1,5 +1,5 @@
/* mv -- move or rename files
- Copyright (C) 86, 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 86, 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@
#include "system.h"
#include "path-concat.h"
#include "backupfile.h"
+#include "closeout.h"
#include "error.h"
#ifdef HAVE_LCHOWN
@@ -454,6 +455,7 @@ version control may be set with VERSION_CONTROL, values are:\n\
never, simple always make simple backups\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -517,6 +519,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("mv (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -545,5 +548,7 @@ main (int argc, char **argv)
for (; optind < argc - 1; ++optind)
errors |= movefile (argv[optind], argv[argc - 1], dest_is_dir);
+ if (verbose)
+ close_stdout ();
exit (errors);
}
diff --git a/src/rm.c b/src/rm.c
index dbf1d42af..b4ac4d280 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -1,5 +1,5 @@
/* `rm' file deletion utility for GNU.
- Copyright (C) 88, 90, 91, 94, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 88, 90, 91, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -51,6 +51,7 @@
#include "save-cwd.h"
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "obstack.h"
#include "hash.h"
@@ -307,6 +308,7 @@ Remove (unlink) the FILE(s).\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -992,6 +994,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("rm (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
@@ -1040,5 +1043,7 @@ main (int argc, char **argv)
hash_free (active_dir_map);
#endif
+ if (verbose)
+ close_stdout ();
exit (fail);
}
diff --git a/src/rmdir.c b/src/rmdir.c
index 9b2ae90e4..7853aa080 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -1,5 +1,5 @@
/* rmdir -- remove directories
- Copyright (C) 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
void strip_trailing_slashes ();
@@ -126,6 +127,7 @@ Remove the DIRECTORY(ies), if they are empty.\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -166,6 +168,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("rmdir (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
diff --git a/src/sync.c b/src/sync.c
index dc0e9edd6..41fcd69d9 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -1,5 +1,5 @@
/* sync - update the super block
- Copyright (C) 94, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
#include "system.h"
#include "long-options.h"
+#include "closeout.h"
#include "error.h"
/* The name this program was run with. */
@@ -44,6 +45,7 @@ Force changed blocks to disk, update the super block.\n\
--version output version information and exit\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
diff --git a/src/touch.c b/src/touch.c
index 202bf5ce3..881f1d0d4 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -1,5 +1,5 @@
/* touch -- change modification and access times of files
- Copyright (C) 87, 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 87, 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "argmatch.h"
@@ -260,6 +261,7 @@ Update the access and modification times of each FILE to the current time.\n\
STAMP may be used without -t if none of -drt, nor --, are used.\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
@@ -340,6 +342,7 @@ main (int argc, char **argv)
if (show_version)
{
printf ("touch (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}