#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
/* The official name of this program (e.g., no `g' prefix). */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
operating_mode = undefined_mode;
/* By default, all non-delimited lines are printed. */
error (0, errno, "-");
exit_status = 1;
}
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
/* expand - convert tabs to spaces
- Copyright (C) 89, 91, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 89, 91, 1995-2000 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
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
/* The official name of this program (e.g., no `g' prefix). */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
while ((c = getopt_long (argc, argv, "it:,0123456789", longopts, NULL)) != -1)
{
switch (c)
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
/* GNU fmt -- simple text formatter.
- Copyright (C) 1994-1999 Free Software Foundation, Inc.
+ Copyright (C) 1994-2000 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
#define word unused_word_type
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
crown = tagged = split = uniform = FALSE;
max_width = WIDTH;
prefix = "";
}
}
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
-
exit (EXIT_SUCCESS);
}
/* fold -- wrap each input line to fit in specified width.
- Copyright (C) 91, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 91, 1995-2000 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
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
break_spaces = count_bytes = have_read_stdin = 0;
/* Turn any numeric options into -w options. */
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (errs == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
#include "safe-read.h"
filename = _("standard input");
if (print_headers)
write_header (filename);
+ /* FIXME: use STDIN_FILENO, not `0' */
return head (filename, 0, n_units, count_lines);
}
else
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
have_read_stdin = 0;
print_headers = 0;
if (have_read_stdin && close (0) < 0)
error (EXIT_FAILURE, errno, "-");
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
#include <getopt.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "hard-locale.h"
#include "linebuffer.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
#ifdef ENABLE_NLS
hard_LC_COLLATE = hard_locale (LC_COLLATE);
#endif
error (EXIT_FAILURE, errno, "%s", names[1]);
if ((fp1 == stdin || fp2 == stdin) && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (EXIT_SUCCESS);
}
/* Compute MD5 checksum of files or strings according to the definition
of MD5 in RFC 1321 from April 1992.
- Copyright (C) 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 1995-2000 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
#include "md5.h"
#include "getline.h"
#include "system.h"
+#include "closeout.h"
#include "error.h"
/* The official name of this program (e.g., no `g' prefix). */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
switch (opt)
{
}
}
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
-
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
/* nl -- number lines of files
- Copyright (C) 89, 92, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 89, 92, 1995-2000 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
#include <getopt.h>
#include "system.h"
+#include "closeout.h"
#include <regex.h>
check_section (void)
{
size_t len = line_buf.length - 1;
-
+
if (len < 2 || memcmp (line_buf.buffer, section_del, 2))
return Text;
if (len == header_del_len
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
have_read_stdin = 0;
while ((c = getopt_long (argc, argv, "h:b:f:v:i:pl:s:w:n:d:", longopts,
error (0, errno, "-");
exit_status = 1;
}
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
/* od -- dump files in octal and other formats
- Copyright (C) 92, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 92, 1995-2000 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
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
err = 0;
for (i = 0; i <= MAX_INTEGRAL_TYPE_SIZE; i++)
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
-
exit (err == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
/* The official name of this program (e.g., no `g' prefix). */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
have_read_stdin = 0;
serial_merge = 0;
delims = default_delims;
exit_status = paste_serial (argc - optind, &argv[optind]);
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
#include <sys/types.h>
#include <time.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "xstrtol.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
n_files = 0;
file_names = (argc > 1
? (char **) xmalloc ((argc - 1) * sizeof (char *))
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
if (failed_opens > 0)
exit (EXIT_FAILURE);
exit (EXIT_SUCCESS);
/* Permuted index for GNU, with keywords in their context.
- Copyright (C) 1990, 1991, 1993, 1998-1999 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1991, 1993, 1998-2000 Free Software Foundation, Inc.
François Pinard <pinard@iro.umontreal.ca>, 1988.
This program is free software; you can redistribute it and/or modify
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "argmatch.h"
#include "bumpalloc.h"
#include "diacrit.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
#if HAVE_SETCHRCLASS
setchrclass (NULL);
#endif
if (optind < argc)
{
+ /* FIXME: don't fclose here? */
fclose (stdout);
if (fopen (argv[optind], "w") == NULL)
error (EXIT_FAILURE, errno, "%s", argv[optind]);
/* split.c -- split a file into pieces.
- Copyright (C) 88, 91, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 88, 91, 1995-2000 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
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "safe-read.h"
#include "xstrtol.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
/* Parse command line options. */
infile = "-";
/* sum -- checksum and count the blocks in a file
- Copyright (C) 86, 89, 91, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 86, 89, 91, 1995-2000 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
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "safe-read.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
have_read_stdin = 0;
while ((optc = getopt_long (argc, argv, "rs", longopts, NULL)) != -1)
/* tac - concatenate and print files in reverse
- Copyright (C) 1988-1991, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 1988-1991, 1995-2000 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
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include <regex.h>
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
errors = 0;
separator = "\n";
sentinel_length = 1;
if (have_read_stdin && close (0) < 0)
error (EXIT_FAILURE, errno, "-");
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
#include <getopt.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "safe-read.h"
#include "xstrtol.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
while ((c = getopt_long (argc, argv, "cdst", long_options, NULL)) != -1)
{
switch (c)
}
}
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
-
if (close (0) != 0)
error (EXIT_FAILURE, errno, _("standard input"));
#include <getopt.h>
#include "system.h"
+#include "closeout.h"
#include "long-options.h"
#include "error.h"
#include "readtokens.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
exit_status = 0;
parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
else
tsort ("-");
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
-
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
have_read_stdin = 0;
exit_status = 0;
convert_entire_line = 0;
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (fclose (stdout) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
/* uniq -- remove duplicate lines from a sorted file
- Copyright (C) 86, 91, 1995-1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 86, 91, 1995-1998, 1999, 2000 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
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "linebuffer.h"
#include "error.h"
#include "xstrtol.h"
if (ferror (istream) || fclose (istream) == EOF)
error (EXIT_FAILURE, errno, _("error reading %s"), infile);
- if (ferror (ostream) || fclose (ostream) == EOF)
+ /* Close ostream only if it's not stdout -- the latter is closed
+ via the atexit-invoked close_stdout. */
+ if (ostream != stdout && (ferror (ostream) || fclose (ostream) == EOF))
error (EXIT_FAILURE, errno, _("error writing %s"), outfile);
free (lb1.buffer);
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
skip_chars = 0;
skip_fields = 0;
check_chars = 0;
/* wc - print the number of bytes, words, and lines in files
- Copyright (C) 85, 91, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 85, 91, 1995-2000 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
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "human.h"
#include "safe-read.h"
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
+
exit_status = 0;
posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
print_lines = print_words = print_chars = print_linelength = 0;