/* sum -- checksum and count the blocks in a file
- Copyright (C) 86, 89, 91, 1995-2002, 2004, 2005,
- 2008-2009 Free Software Foundation, Inc.
+ Copyright (C) 1986-2013 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 "error.h"
+#include "fadvise.h"
#include "human.h"
#include "safe-read.h"
#include "xfreopen.h"
-/* The official name of this program (e.g., no `g' prefix). */
+/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "sum"
#define AUTHORS \
usage (int status)
{
if (status != EXIT_SUCCESS)
- fprintf (stderr, _("Try `%s --help' for more information.\n"),
- program_name);
+ emit_try_help ();
else
{
printf (_("\
\n\
With no FILE, or when FILE is -, read standard input.\n\
"), stdout);
- emit_bug_reporting_address ();
+ emit_ancillary_info ();
}
exit (status);
}
}
}
+ fadvise (fp, FADVISE_SEQUENTIAL);
+
while ((ch = getc (fp)) != EOF)
{
total_bytes++;
atexit (close_stdout);
+ /* Line buffer stdout to ensure lines are written atomically and immediately
+ so that processes running in parallel do not intersperse their output. */
+ setvbuf (stdout, NULL, _IOLBF, 0);
+
have_read_stdin = false;
while ((optc = getopt_long (argc, argv, "rs", longopts, NULL)) != -1)