Bruno Haible [Sun, 13 May 2018 21:23:47 +0000 (23:23 +0200)]
imaxdiv: Fix compilation error on Android.
* m4/imaxdiv.m4 (gl_FUNC_IMAXDIV): Set HAVE_IMAXDIV_T to 0 if imaxdiv_t
is not defined.
* lib/inttypes.in.h (imaxdiv_t): Define if HAVE_IMAXDIV_T, not
HAVE_DECL_IMAXDIV, is 0.
* m4/inttypes.m4 (gl_INTTYPES_H_DEFAULTS): Initialize HAVE_IMAXDIV_T.
* modules/inttypes-incomplete (Makefile.am): Substitute HAVE_IMAXDIV_T.
Bruno Haible [Sun, 13 May 2018 20:20:13 +0000 (22:20 +0200)]
Support selective inclusion mechanism of recent mingw.org header files.
Reported by Eli Zaretskii <eliz@gnu.org>.
* lib/sys_types.in.h: On mingw, when __need_off_t, __need___off64_t,
__need_ssize_t, or __need_time_t is defined, just include the system's
<sys/types.h>.
* lib/locale.in.h: On mingw, when __need_locale_t is defined, just
include the system's <locale.h>.
Paul Eggert [Thu, 10 May 2018 01:07:29 +0000 (18:07 -0700)]
af_alg: recover better from crypto failures
* lib/af_alg.c (afalg_stream): Recover from crypto failures if the
input stream is seekable, by repositioning the stream back to
where it was, possibly by just calling sendfile with an offset
arg. This lets us return -EAFNOSUPPORT instead of -EIO in some
cases, which lets our callers try again with user-mode code.
* modules/crypto/af_alg (Depends-on): Depend on fseeko and ftello
instead of on fflush and lseek.
Paul Eggert [Wed, 9 May 2018 19:04:37 +0000 (12:04 -0700)]
af_alg: distiguish I/O errors better
* lib/af_alg.c (afalg_buffer, afalg_stream): Return -EAFNOSUPPORT,
not -EIO, if it’s OK for the caller to try again with user-mode code.
(afalg_stream) [!_WIN32 || __CYGWIN__]: Return -EIO (not possibly
some other error number) if fflush fails, as the caller should not
try again that case.
Paul Eggert [Wed, 9 May 2018 18:34:28 +0000 (11:34 -0700)]
af_alg: don’t leak file descriptors into children
* lib/af_alg.c (alg_socket): Use SOCK_CLOEXEC when creating sockets.
This code should be compiled only on recent GNU/Linux platforms
so we shouldn’t have to also depend on the accept4 module.
Paul Eggert [Mon, 7 May 2018 07:25:57 +0000 (00:25 -0700)]
af_alg: Pacify --enable-gcc-warnings
Problem reported by Assaf Gordon in:
https://lists.gnu.org/r/bug-gnulib/2018-05/msg00041.html
* lib/af_alg.c (afalg_buffer): Move local decls to pacify
gcc -Wjump-misses-init.
* lib/sha512.c (shaxxx_stream): Now static.
Paul Eggert [Sun, 6 May 2018 02:39:37 +0000 (19:39 -0700)]
crypto/{md5,sha1,sha256,sha512}: simplify
* lib/md5.c (md5_stream):
* lib/sha1.c (sha1_stream):
* lib/sha256.c (shaxxx_stream):
Simplify, partly by assuming C99.
* lib/sha256.c (shaxxx_stream):
New function, which implements both sha256 and sha224.
Simplify, partly by assuming C99.
(sha256_stream, sha224_stream):
Use it to avoid code duplication, removing a FIXME.
* lib/sha512.c (shaxxx_stream, sha512_stream, sha384_stream):
Likewise.
Bruno Haible [Sat, 5 May 2018 18:27:33 +0000 (20:27 +0200)]
af_alg: New module.
* lib/af_alg.h: Test HAVE_* macro through '#if', not '#ifdef'.
* lib/af_alg.c: Include "af_alg.h" before the other header files.
* lib/md5.c: Include "af_alg.h" unconditionally.
(md5_stream): Invoke afalg_stream unconditionally.
* lib/sha1.c: Include "af_alg.h" unconditionally.
(sha1_stream): Invoke afalg_stream unconditionally.
* lib/sha256.c: Include "af_alg.h" unconditionally.
(sha256_stream, sha224_stream): Invoke afalg_stream unconditionally.
* lib/sha512.c: Include "af_alg.h" unconditionally.
(sha512_stream, sha384_stream): Invoke afalg_stream unconditionally.
* m4/af_alg.m4: Renamed from m4/linux-if-alg.m4.
(gl_AF_ALG): Renamed from gl_LINUX_IF_ALG_H.
* modules/crypto/af_alg: New file.
* modules/crypto/md5 (Files): Remove files that are now in the
'crypto/af_alg' module.
(Depends-on): Add crypto/af_alg.
(configure.ac): Remove gl_LINUX_IF_ALG_H invocation.
(Makefile.am): Don't mention af_alg.c here.
* modules/crypto/sha1 (Files): Remove files that are now in the
'crypto/af_alg' module.
(Depends-on): Add crypto/af_alg.
(configure.ac): Remove gl_LINUX_IF_ALG_H invocation.
(Makefile.am): Don't mention af_alg.c here.
* modules/crypto/sha256 (Files): Remove files that are now in the
'crypto/af_alg' module.
(Depends-on): Add crypto/af_alg.
(configure.ac): Remove gl_LINUX_IF_ALG_H invocation.
(Makefile.am): Don't mention af_alg.c here.
* modules/crypto/sha512 (Files): Remove files that are now in the
'crypto/af_alg' module.
(Depends-on): Add crypto/af_alg.
(configure.ac): Remove gl_LINUX_IF_ALG_H invocation.
(Makefile.am): Don't mention af_alg.c here.
Paul Eggert [Sat, 5 May 2018 18:08:08 +0000 (11:08 -0700)]
af_alg: minor style improvements
* lib/af_alg.c (afalg_stream): Prefer C99 style
decl-after-statement, since we’re already assuming C99. Clarify
by strengthening the bind test and omit unnecessary assignment.
Paul Eggert [Sat, 5 May 2018 17:27:38 +0000 (10:27 -0700)]
sys-limits.h: new file for crypto and safe I/O
* lib/af_alg.c: Include sys-limits.h.
(MAX_RW_COUNT): Remove. Use replaced by SYS_BUFSIZE_MAX.
(afalg_stream): Also reject negative sizes for sendfile; they
should not happen and the code is a bit cleaner and faster this way.
* lib/safe-read.c: Include sys-limits.h.
(BUGGY_READ_MAXIMUM): Remove. All uses replaced by SYS_BUFSIZE_MAX.
* lib/sys-limits.h: New file, with values and commentary derived
from the old safe-read.c and from GNU Emacs sysdep.c.
* modules/crypto/md5, modules/crypto/sha1, modules/crypto/sha256:
* modules/crypto/sha512, modules/safe-read, modules/safe-write:
Add lib/sys-limits.h to Files section.
Linux supports accessing kernel crypto API via AF_ALG since
version 2.6.38. Coreutils uses libcrypto when available and fallbacks to
generic C implementation of various hashing functions.
Add a generic afalg_stream() function which uses AF_ALG to calculate the
hash of a stream and use sendfile() when possible (regular file with size
less or equal than 0x7ffff000 (2,147,479,552) bytes, AKA MAX_RW_COUNT).
Use afalg_stream() only in sha1sum for now, but other hashes are possible.
The speed gain really depends on the CPU type, on systems which doesn't use
libcrypto ranges from ~10% to 320%.
This is a test on a Intel(R) Xeon(R) CPU E3-1265L V2 and Debian stretch:
Bruno Haible [Wed, 2 May 2018 21:36:18 +0000 (23:36 +0200)]
localename: Fix test failures on mingw.
* lib/localename.c (gl_locale_name_thread): Remove code specific to
native Windows.
(gl_locale_name_posix): Move code specific to native Windows here.
* tests/test-localename.c (test_locale_name, test_locale_name_posix):
Accept result without charset suffix, as it appears on mingw.
Paul Smith [Sat, 28 Apr 2018 23:37:50 +0000 (16:37 -0700)]
bootstrap: Avoid gnulib operations if not needed
* build-aux/bootstrap: Remove unused variable gnulib_mk.
Set $gnulib_extra_files early so it can be overridden in .conf.
Remove redundant --import flag from $gnulib_tool_options.
Set $use_gnulib to false if no gnulib modules or files are needed.
If $use_gnulib is false, don't do anything related to gnulib.
A lot of this is just whitespace (indentation) changes.
localcharset: short-circuit the search for an alias on a Mac
* lib/localcharset.c (get_charset_aliases): Add a tautological
UTF-8 entry to speed up the search for this case.
Most machines default to a UTF-8 locale nowadays, so begin the
list of aliases with a dummy UTF-8 entry so it will be found
immediately and a time-consuming search through the rest of
the list is avoided.
Paul Eggert [Wed, 11 Apr 2018 19:50:35 +0000 (12:50 -0700)]
fts: fix bug in find across filesystems
This fixes a bug I introduced last summer.
Problem reported by Kamil Dudka in:
https://lists.gnu.org/r/bug-gnulib/2018-04/msg00033.html
* lib/fts.c (filesystem_type, dirent_inode_sort_may_be_useful)
(leaf_optimization):
New arg for file descriptor. All callers changed.
(fts_build): Check for whether inodes should be sorted
before closing the directory.
Paul Eggert [Thu, 5 Apr 2018 15:48:01 +0000 (08:48 -0700)]
fts: treat CIFS like NFS
Problem reported by Kamil Dudka in:
https://lists.gnu.org/r/bug-gnulib/2018-04/msg00015.html
* lib/fts.c (S_MAGIC_CIFS): New macro.
(dirent_inode_sort_may_be_useful, leaf_optimization):
Treat CIFS like NFS.
Paul Eggert [Wed, 28 Mar 2018 19:45:45 +0000 (12:45 -0700)]
time_rz: fix workaround for Mac OS X 10.6 infloop
Problems reported by Charles A. Roelli (Bug#27736#117).
* m4/time_rz.m4 (gl_TIME_RZ): Use a slightly different timestamp.
Also, discard output, which clutters the 'configure' log.
Paul Eggert [Tue, 27 Mar 2018 02:23:33 +0000 (19:23 -0700)]
time_rz: work around Mac OS X 10.6 infloop
* doc/posix-functions/localtime.texi:
* doc/posix-functions/localtime_r.texi: Mention the bug.
* lib/time_rz.c (localtime_rz): Work around the bug. It’d be
better to fix localtime and localtime_r instead, but that would be
more work and is not needed to fix the Emacs problem.
* m4/time_rz.m4 (gl_TIME_RZ): Detect the bug.
Jim Meyering [Sat, 24 Mar 2018 16:48:47 +0000 (09:48 -0700)]
test-version-etc.sh: don't use diff directly: use init.sh's compare
We'd rather not sacrifice readable "diff -u" output even for
"diff -c" output (not supported by busybox) or for even less
readable ed-style "diff" output. So use init.sh's compare function
* tests/test-version-etc.sh: Source init.sh and add "." to path.
Remove "./" from invocation of test-version-etc, so we use path.
And s/diff/compare/.
* modules/version-etc-tests (Depends-on): Add test-framework-sh,
to get init.sh.
Prompted by Eric Blake's comments in
https://lists.gnu.org/r/sed-devel/2018-03/msg00015.html
Jim Meyering [Fri, 23 Mar 2018 23:46:13 +0000 (16:46 -0700)]
test-version-etc.sh: port to diff without -c
* tests/test-version-etc.sh: Don't use diff's -c option.
This caused spurious test failure on Alpine Linux, which
uses busybox's diff. Reported by Assaf Gordon in
https://lists.gnu.org/r/sed-devel/2018-03/msg00013.html
Bruno Haible [Fri, 16 Mar 2018 15:25:02 +0000 (16:25 +0100)]
glob: Don't compile replacements on recent glibc systems.
* lib/glob.in.h: Use the usual idiom for the double-inclusion guard. If
REPLACE_GLOB is 0, include the system's <glob.h> and use
_GL_CXXALIAS_SYS.
* m4/glob.m4 (gl_GLOB): Set REPLACE_GLOB instead of GLOB_H. Accept
_GNU_GLOB_INTERFACE_VERSION 2 as well. Delete the file conf$$-globtest
inside the AC_RUN_IFELSE block. Remove GL_GENERATE_GLOB_H conditional.
* modules/glob (Dependencies): Test REPLACE_GLOB instead of GLOB_H.
Remove snippet/warn-on-use.
(configure.ac): Test REPLACE_GLOB instead of GLOB_H.
(Makefile.am): Create glob.h always. Update list of substitutions in
glob.h. Don't depend on $(WARN_ON_USE_H).