]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main, usage): Check for write error to stdout before exiting.
authorJim Meyering <jim@meyering.net>
Sun, 4 Jan 1998 22:45:28 +0000 (22:45 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 4 Jan 1998 22:45:28 +0000 (22:45 +0000)
Include "closeout.h".

16 files changed:
src/cp.c
src/dd.c
src/df.c
src/dircolors.c
src/du.c
src/install.c
src/ln.c
src/ls.c
src/mkdir.c
src/mkfifo.c
src/mknod.c
src/mv.c
src/rm.c
src/rmdir.c
src/sync.c
src/touch.c

index d09a2f7cd9fb84818180c56420e245276390fbf2..a2814c2a5700aecd5fd94a270167000e4f01627d 100644 (file)
--- 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);
 }
index f71502e6207c1224bf25cd0af490c1d343d7678b..3c1ff283c7293c08e4b947988fa5f985f6f488e7 100644 (file)
--- 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);
 }
index 7db3e763c31f51d1171ad6c37fca074b15fd9610..bcef2a252f238e28706e17ddd76bf3db502b3e04 100644 (file)
--- 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);
 }
 
index f024396a2af3fa72139d61e5b1b916fbfe8be505..b16d7e27ab85a95b2f7cc006128a5a8d5d2939ca 100644 (file)
@@ -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"));
index eee05318aa4cf2221d8e808db2cdce707312c4a3..165d0dfd82ab3af344d8e5cbc35072345a1e02db 100644 (file)
--- 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);
 }
 
index 470da79a7d2313d689b6976dd2088e5c55c65bf8..7cbd2f6dbfe304f4e92117eb3b70885b550c7796 100644 (file)
@@ -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);
 }
index 6078f48d0efa3dbc1c1af20199af24802994a542..70cb328caf72bd0a6b07ef75164459a61132dd13 100644 (file)
--- 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);
 }
index 4f28157a9921aafe683c94ef31e5ddd0228d8f25..561d52a16ab8f9b507995cdf822971ae3db99db8 100644 (file)
--- 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);
 }
index a880b0096239f4419e24dae2be673b209c32c92d..89886e15815c9ade7407dd072d19ceed730882c8 100644 (file)
@@ -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);
     }
 
index 387fab99376846f2242a46383dfdba725c49dc64..d70dc15d75dcc2a6f5436978b4375a99bc13bddf 100644 (file)
@@ -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);
     }
 
index d2292f7f544683d6c24ff7566aa21daaaebdae7b..1233a15e64a317d2215ac6014e4d362a9de164ff 100644 (file)
@@ -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);
     }
 
index 9b08bf50fb67777e279db52213a4e413250b97f7..c431a688c865607d87221159466ecb4b7bae5d3c 100644 (file)
--- 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);
 }
index dbf1d42af4e21f3430ba476002ade35f6123cde5..b4ac4d28029e4287f4d9234513019c1d37bf879e 100644 (file)
--- 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);
 }
index 9b2ae90e449660a6ec670c3b3198de6ea51984c1..7853aa08010faf79be55c3a826493a8b30e756b5 100644 (file)
@@ -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);
     }
 
index dc0e9edd6d42349c2dcc2b1601a61a98d3321990..41fcd69d9556cc08b89cd364fe3946122d9cacd9 100644 (file)
@@ -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);
 }
index 202bf5ce3274a7051a7459e9147549ec9a13adfe..881f1d0d4490ffb3977731cc21a617b1ec29ea8c 100644 (file)
@@ -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);
     }