1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-14 07:46:28 +02:00

(main, usage): Check for write error to stdout before exiting.

Include "closeout.h".
This commit is contained in:
Jim Meyering
1998-01-04 22:45:28 +00:00
parent b246280c27
commit 5d4f8ebdfd
16 changed files with 76 additions and 21 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View 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"));

View File

@@ -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);
}

View 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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View 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);
}

View 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);
}

View 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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View 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);
}

View 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);
}

View 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);
}