/* cat -- concatenate files and print on the standard output.
- Copyright (C) 88, 90, 91, 1995-2008 Free Software Foundation, Inc.
+ Copyright (C) 88, 90, 91, 1995-2009 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
proper_name_utf8 ("Torbjorn Granlund", "Torbj\303\266rn Granlund"), \
proper_name ("Richard M. Stallman")
-/* Undefine, to avoid warning about redefinition on some systems. */
-#undef max
-#define max(h,i) ((h) > (i) ? (h) : (i))
-
/* Name of input file. May be "-". */
static char const *infile;
/* Preserves the `cat' function's local `newlines' between invocations. */
static int newlines2 = 0;
+static inline size_t
+compute_buffer_size (struct stat st)
+{
+ return MIN (8 * ST_BLKSIZE (st), 32 * 1024);
+}
+
void
usage (int status)
{
if (fstat (STDOUT_FILENO, &stat_buf) < 0)
error (EXIT_FAILURE, errno, _("standard output"));
- outsize = ST_BLKSIZE (stat_buf);
+ outsize = compute_buffer_size (stat_buf);
/* Input file can be output file for non-regular files.
fstat on pipes returns S_IFSOCK on some systems, S_IFIFO
on others, so the checking should not be done for those types,
ok = false;
goto contin;
}
- insize = ST_BLKSIZE (stat_buf);
+ insize = compute_buffer_size (stat_buf);
/* Compare the device and i-node numbers of this input file with
the corresponding values of the (output file associated with)
if (! (number | show_ends | show_nonprinting
| show_tabs | squeeze_blank))
{
- insize = max (insize, outsize);
+ insize = MAX (insize, outsize);
inbuf = xmalloc (insize + page_size - 1);
ok &= simple_cat (ptr_align (inbuf, page_size), insize);