* src/cmp.c (main):
* src/diff.c (compare_files): Omit third arg 0 to ‘open’.
This was never necessary, and I suspect was put in only to pacify
no-longer-relevant compilers.
* src/diff.c (compare_files):
* src/ifdef.c (format_group, print_ifdef_lines):
* src/io.c (find_and_hash_each_line):
Don’t put assignments into ‘if (...)’, of ‘switch (...)’,
as per GNU coding standards.
* src/cmp.c (bytes): Use INTMAX_MAX, not -1, for “infinity”.
This simplifies the code and is not a value that can be exhausted
these days.
(main, cmp): Treat very large -n values as “infinity”.
* tests/cmp: Test this.
* src/cmp.c (main): Avoid a 'stat' call in the common case when
standard output is not a character special device. This is valid
because /dev/null is a character special device.
* src/cmp.c (cmp): When calculating the offset width,
Don’t attempt to squeeze a file position into an int
as that might trap or yield the wrong answer.
Also, treat “negative” file sizes as zero; this can
happen if the initial file offset is past EOF.
* src/cmp.c (ignore_initial): Now an array of intmax_t not off_t.
This allows cmp -i N to work better on platforms where intmax_t
is wider than off_t, N fits in the former and not the latter,
and the input is not a regular file. All uses changed.
(cmp): Instead of seeking to file end when -i N is huge,
simply pretend that we read zero bytes. This avoids some
kernel lseek bugs.
* src/cmp.c (file_position): Set position to EOF by calling lseek
with an offset of 0 and SEEK_END, rather than a SEEK_CURR-relative
offset of the maximum off_t value. The latter would evoke failure on
fedora 38/glibc-2.37/linux 6.2.15-300.fc38.x86_64:
lseek(3, 9223372036854775807, SEEK_CUR) = -1 EINVAL
The failing test was this (which must now exit 0, but did not):
echo a>a;echo b>b; src/cmp -i 99999999999999999999 a b
* NEWS: Document this.
* src/cmp.c (specify_ignore_initial):
If the value exceeds TYPE_MAXIMUM (off_t), set the correspnding
ignore_initial value to -1 instead of reporting an error.
(main, cmp, file_position): All uses changed. Hence a huge value
will always do the right thing with regular files, which cannot
contain more than TYPE_MAXIMUM (off_t) bytes. There still may be
EOVERFLOW failures reported for non-regular files, though, as
these can be larger.
* tests/cmp: Test cmp -i N when N cannot fit into 64 bits.
* NEWS: Mention this.
* src/cmp.c (main, cmp): Do not trust st_size == 0, as it may
be a /proc file.
* tests/brief-vs-stat-zero-kernel-lies: Also test cmp -s.
c_isdigit is a function supplied by Gnulib, which should
be a bit better than our own macro.
* bootstrap.conf (gnulib_modules): Add c-ctype.
* src/system.h (ISDIGIT): Remove. All calls replaced by c_isdigit.
Include <c-ctype.h>, for c_isdigit.
* src/system.h (floor_log2): Declare with "SYSTEM_INLINE int"
on the same line as the function name, to accommodate the
tight-scope syntax-check rule.
* cfg.mk (_gl_TS_extern): Add SYSTEM_INLINE to the regexp.
Prefer C11-style char32_t to wchar_t, as char32_t works better on
platforms where wchar_t is only 16 bits.
* .gitignore: Add lib/uchar.h.
* bootstrap.conf (gnulib_modules): Add c32width, mbrtoc32.
Remove mbrtowc. Sort.
* src/side.c: Include uchar.h instead of wchar.h.
(print_half_line): Use c32width and mbrtowc instead of
wcwidth and mbrtowc.
* configure.ac (GNULIB_EXCLUDE_SINGLE_THREAD)
(GNULIB_MBRTOWC_SINGLE_THREAD, GNULIB_REGEX_SINGLE_THREAD)
(GNULIB_WCHAR_SINGLE_LOCALE):
Define, to improve performance a bit in Gnulib.
Diffutils is single-threaded and sets locales first.
This refactors and reindents option-parsing so that the code looks
similar in all three main programs.
* src/cmp.c, src/diff3.c, src/sdiff.c (shortopts): New constant.
(main): Use it.
* src/diff.c (main): Put local inside loop.
* src/Makefile.am (noinst_HEADERS): Remove die.h.
* src/die.h: Remove. All uses of ‘die’ replaced with ‘error’,
and all includes of die.h removed.
This reverts commit 2016-10-16T15:43:14Z!meyering@fb.com,
which is no longer needed now that the Gnulib ‘error’
module arranges for static checking to work with ‘error’.
* src/diff.h (struct file_data.changed): Now bool instead of char.
This shrinks the size of the code generated on GCC x86-64 by 1.6%.
Formerly this was char because bool’s size is greater than 1
on some platforms, but those platforms are no longer of so
much importance that it’s worth pessimizing on common platforms.
All uses changed.
* configure.ac: Pass new args to AC_INIT.
(gl_GCC_VERSION_IFELSE): New macro, taken from coreutils.
Modernize GCC warnings to agree more with coreutils.
* bootstrap.conf (buildreq): Require Automake 1.14 instead of 1.12.2,
since AM_PROG_CC_C_O is obsolete as of 1.14.
* configure.ac: Don’t use obsolescent AM_PROG_CC_C_O.
* src/context.c (find_hunk):
Check for overflow when computing non-ignorable threshold.
* src/diff.c (main): Limit ‘context’ to LIN_MAX since it is a lin.
* src/system.h (CONTEXT_MAX): Remove.
The ‘register’ keyword is no longer needed for optimization.
With GCC 13.1 x86-64 compiled with -O2, omitting ‘register’ did not
change the generated code.