Paul Eggert [Sat, 27 Jun 2020 16:44:11 +0000 (09:44 -0700)]
getloadavg: don’t depend on fopen-gnu
This is for Emacs, which does not need fopen-gnu for anything else,
and which would need it only on a NetBSD platform where getloadavg
does not work (does that even happen?).
* lib/getloadavg.c (getloadavg) [__NetBSD__]: Use open, not fopen.
* modules/getloadavg (Depends-on): Remove fopen-gnu.
Bruno Haible [Sat, 27 Jun 2020 09:08:51 +0000 (11:08 +0200)]
fopen-gnu: Simplify code.
* lib/fopen.c: Include <stdbool.h>.
(rpl_fopen): Use a single variable open_flags instead of
open_flags_standard and open_flags_gnu. Make open_flags_gnu a bool.
* modules/fopen (Depends-on): Add stdbool.
These modules provide the same functionality as the modules
dtoastr and ldtoastr except for the formatting taking place in the
C locale.
* MODULES.html.sh: Add c-dtoastr and c-ldtoastr.
* lib/c-dtoastr.c, lib/c-ldtoastr.c: New files.
* lib/ftoastr.c: Prefix exported functions when the macro C_LOCALE is
defined. Use c_snprintf and c_strtod/c_strtold instead of
snprintf and strtod/strtold whhen the macro C_LOCALE is defined.
* lib/ftoastr.h: Add prototypes for c_dtoastr and c_ldtoastr.
* modules/c-dtoastr, modules/c-dtoastr-tests, modules/c-ldtoastr,
modules/c-ldtoastr-tests: New files.
* tests/test-c-dtoastr.c, tests/test-c-dtoastr.sh,
tests-c-ldtoastr.c tests-c-ldtoastr.sh: New files.
Dmitry V. Levin [Wed, 3 Jun 2020 08:00:00 +0000 (08:00 +0000)]
git-version-gen: update scriptversion
scriptversion in git-version-gen should be kept up-to-date because
this script is used by projects that update it from gnulib
when its scriptversion changes.
Paul Eggert [Tue, 2 Jun 2020 00:57:27 +0000 (17:57 -0700)]
getloadavg: fix double-increment bug
* lib/getloadavg.c (getloadavg): Fix double-increment typo on
Linux without glibc, Android, Cygwin. This fixes a bug I
introduced in 2011-02-08T20:23:29Z!eggert@cs.ucla.edu.
Problem and fix reported by Semen Verchenko in:
https://lists.gnu.org/r/bug-gnulib/2020-06/msg00007.html
Paul Eggert [Mon, 1 Jun 2020 22:58:29 +0000 (15:58 -0700)]
tempname: use getrandom, not getentropy
This removes a dependency, as getentropy depends on getrandom.
* lib/tempname.c: Include sys/random.h instead of unistd.h.
(RANDOM_BITS) [!_LIBC]: Use getrandom, not getentropy.
* modules/tempname (Depends-on): Depend on getrandom, not getentropy.
Paul Eggert [Mon, 1 Jun 2020 06:29:21 +0000 (23:29 -0700)]
getrandom-tests: do not assume GRND_RANDOM yields short read
* tests/test-getrandom.c (main): Omit assertion that
getrandom (b, sizeof b, GRND_RANDOM | GRND_NONBLOCK) < sizeof b
when b’s size is 100000. This assertion fails with Linux kernel
5.6.13, as that kernel ignores the GRND_RANDOM flag.
The separate blocking pool is going away in the Linux kernel, and
they’ve added a flag GRND_INSECURE instead; see:
https://lore.kernel.org/linux-api/705c5a091b63cc5da70c99304bb97e0109be0a26.1577088521.git.luto@kernel.org/
The assertion was iffy anyway; what’s to prevent a kernel from
lazily filling a large buffer with random bytes?
Paul Eggert [Mon, 1 Jun 2020 03:15:25 +0000 (20:15 -0700)]
tempname: merge from glibc and coreutils
Also, merge in Gnulib’s more-recent methods of making it easier
to share between Gnulib and glibc, and fix a few randomness
glitches.
* lib/tempname.c: Include libc-config.h, not config.h, if !_LIBC.
(__set_errno): Remove; libc-config.h does that for us.
Do not include <sys/time.h>.
(__secure_getenv) [_LIBC]: New macro.
(__try_tempname, __getpid, __gettimeofday) [!_LIBC]: Remove macros.
(RANDOM_BITS): Rewrite.
(RANDOM_VALUE_MAX, BASE_62_DIGITS, BASE_62_POWER): New macros.
(random_value): New typedef.
(try_file, try_dir, try_nocreate): Move up.
(gen_tempname_len, try_tempname_len): New functions.
(gen_tempname_len): Use a constant array rather than a switch.
(try_tempname_len): Don’t assume string length fits in int.
Generalize use of RANDOM_BITS. If _LIBC, don’t assume RANDOM_BITS
has enough entropy (it’s a bit short).
(__gen_tempname): Rewrite in terms of gen_tempname_len.
(__try_tempname): Rewrite in terms of try_tempname_len.
* lib/tempname.h (gen_tempname_len, try_tempname_len): New decls.
* modules/tempname (Depends-on): Remove gettimeofday, sys_time.
Add getentropy, libc-config.
Bruno Haible [Sun, 31 May 2020 18:12:04 +0000 (20:12 +0200)]
getentropy: Work around a macOS and Solaris problem.
* lib/unistd.in.h: Include <sys/random.h>, when needed for the
'getentropy' module.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
UNISTD_H_HAVE_SYS_RANDOM_H.
* m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Set
UNISTD_H_HAVE_SYS_RANDOM_H.
* modules/unistd (Makefile.am): Substitute UNISTD_H_HAVE_SYS_RANDOM_H.
* doc/glibc-functions/getentropy.texi: Document the macOS and Solaris
problem. List more platforms.
Paul Eggert [Sun, 31 May 2020 17:14:41 +0000 (10:14 -0700)]
fnmatch: merge from glibc
Also, merge in Gnulib’s more-recent methods of making it easier
to share between Gnulib and glibc.
* lib/fnmatch.c: Reorder includes to match glibc better.
Include libc-config.h instead of config.h.
Include alloca.h only if _LIBC || HAVE_ALLOCA.
Do not include "../locale/elem-hash.h" if _LIBC.
Define macros for btowc, etc. if _LIBC. All uses simplified.
Define FALLTHROUGH if _LIBC, instead of including attribute.h.
Include intprops.h, since glibc has it now.
(SIZE_MAX): Remove; use (size_t) -1 instead.
Omit the "Comment out all this code" ifdef, since Gnulib
has never really needed it.
(STREQ): Remove; no longer used.
(__libc_use_alloca, alloca, alloca_account): Define as
needed if !_LIBC.
(ISWCTYPE): Remove; all uses replaced by iswctype.
(HANDLE_MULTIBYTE): Remove. All uses removed by assuming true.
(internal_function): Remove. All uses removed.
(STRUCT): New macro.
(WIDE_CHAR_VERSION): Define to 0 instead of leaving undefined.
(WMEMCMP): New macro.
(FINDIDX): Define if _LIBC, and include <locale/weight.h>
and <locale/weightwc.h>.
(fnmatch): Prefer __glibc_likely and __glibc_unlikely to
__builtin_expect. Check for integer overflow more
systematically. Account for alloca storage better when
recursive. Use strnlen instead of strlen for efficiency.
* lib/fnmatch_loop.c: Include stdint.h if _LIBC, for int32_t etc.
(struct STRUCT): New type.
(FCT, EXT): New ENDS and ALLOCA_USED args.
All callers changed.
(FCT): Prefer __glibc_unlikely to __builtin_expect.
Simplify by assuming WIDE_CHAR_SUPPORT.
Copy _LIBC code from glibc without worrying Gnulib compatibility.
Cast cold to UCHAR to avoid signedness warning.
(END): Check for invalid pattern.
(EXT): Improve alloca/malloc checking (taken from glibc),
and improve it some more by using intprops.h and checking
for integer overflow and using bool for booleans.
* lib/libc-config.h (compat_symbol): New macro.
(versioned_symbol): Make it ‘extern int dummy’ so that it’s
acceptable to non-GCC when a trailing semicolon is added.
* modules/fnmatch (Depends-on): Add alloca-opt, intprops,
libc-config, strnlen. Remove alloca.
Bruno Haible [Sun, 31 May 2020 16:47:12 +0000 (18:47 +0200)]
getrandom: Doc and test tweaks.
* lib/getrandom.c (getrandom): Mention that it never returns 0, and that
it sets errno when failing.
* tests/test-getrandom.c (main): Disable the high-quality check on those
platforms on which it fails.
* doc/glibc-functions/getrandom.texi: Add Minix, AIX, HP-UX, IRIX,
Cygwin to the list of platforms that don't have the function. Add a note
about the quality of the result.
* doc/glibc-headers/sys_random.texi: Don't mention the 'getrandom'
declaration; this is fixed by module 'getrandom'.
Bruno Haible [Sun, 31 May 2020 16:23:04 +0000 (18:23 +0200)]
getrandom: Add support for native Windows.
* lib/getrandom.c: Include <errno.h>, <windows.h>, <bcrypt.h>,
<wincrypt.h>.
(CRYPT_VERIFY_CONTEXT): New macro.
(LoadLibrary, CryptAcquireContext): Redirect to the variant with suffix
'A'.
(GetProcAddress): New macro.
(BCryptGenRandomFuncType): New type.
(BCryptGenRandomFunc, initialized): New variables.
(initialize): New function.
(getrandom): On native Windows, use <bcrypt.h> API when available, and
<wincrypt.h> API as fallback.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Set LIB_GETRANDOM.
* modules/getrandom (Link): New section.
* modules/getentropy (Link): Likewise.
* modules/getrandom-tests (Makefile.am): Link test-getrandom against
$(LIB_GETRANDOM).
* modules/getentropy-tests (Makefile.am): Link test-getentropy against
$(LIB_GETRANDOM).
* modules/sys_random-c++-tests (Makefile.am): Link test-sys_random-c++
against $(LIB_GETRANDOM).
* doc/glibc-functions/getrandom.texi: Mention the native Windows
support.
Bruno Haible [Sat, 30 May 2020 23:02:21 +0000 (01:02 +0200)]
sys_random: Work around macOS bug.
* m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Include <sys/types.h> and
<stdlib.h> before <sys/random.h>.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Likewise.
* lib/sys_random.in.h: On macOS, include <sys/types.h> and <stdlib.h>
first.
* doc/glibc-headers/sys_random.texi: Mention the macOS problem.
Bruno Haible [Sat, 30 May 2020 15:33:46 +0000 (17:33 +0200)]
getrandom: Override incompatible system function on Solaris 11.
* lib/sys_random.in.h (getrandom): Override if REPLACE_GETRANDOM is 1.
* lib/getrandom.c (getrandom): When the system has getrandom, just
invoke it.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Set REPLACE_GETRANDOM if the
system's getrandom function's prototype is not the expected one.
* m4/sys_random_h.m4 (gl_SYS_RANDOM_H_DEFAULTS): Initialize
REPLACE_GETRANDOM.
* modules/sys_random (Makefile.am): Substitute REPLACE_GETRANDOM.
* modules/getrandom (modules/getrandom): Consider REPLACE_GETRANDOM.
* tests/test-getrandom.c (main): Allow error EINVAL as an alternative to
EAGAIN.
* doc/glibc-functions/getrandom.texi: Mention the new module and the
Solaris problem.
Bruno Haible [Sat, 30 May 2020 14:18:36 +0000 (16:18 +0200)]
sys_random: New module.
* lib/sys_random.in.h: Use the common idioms for overridable header
files.
* m4/sys_random_h.m4: New file.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Require gl_SYS_RANDOM_H_DEFAULTS.
* modules/sys_random: New file.
* modules/getrandom (Files): Remove lib/sys_random.in.h.
(Depends-on): Add sys_random.
(configure.ac): Use gl_SYS_RANDOM_MODULE_INDICATOR, not
gl_UNISTD_MODULE_INDICATOR.
(Makefile.am): Don't generate sys/random.h here.
* doc/glibc-headers/sys_random.texi: New file.
* doc/gnulib.texi: Include it.
Bruno Haible [Sat, 30 May 2020 12:13:22 +0000 (14:13 +0200)]
crypto/gc-random: Fix link error on MSVC.
* m4/gc-random.m4 (gl_GC_RANDOM): Set LIB_GC_RAMDOM.
* modules/crypto/gc-random (Link): New section.
* modules/crypto/gc-tests (Makefile.am): Link test-gc against
$(LIB_GC_RAMDOM).
Bruno Haible [Sat, 30 May 2020 09:04:02 +0000 (11:04 +0200)]
Don't assume that UNICODE is not defined.
Many Windows API functions are defined differently (redirecting to a
function with suffix 'W') if the application defines the macro UNICODE
than by default (redirecting to a function with suffix 'A').
Bruno Haible [Sat, 30 May 2020 01:17:19 +0000 (03:17 +0200)]
gnulib-tool: Fix link errors with a particular set of modules on mingw.
* gnulib-tool (func_emit_tests_Makefile_am): Add ../lib/libgnu.a to
LDADD a second time, after the second occurrence of libtests.a.
* pygnulib/GLEmiter.py (tests_Makefile_am): Likewise.
Bruno Haible [Fri, 29 May 2020 20:28:00 +0000 (22:28 +0200)]
Avoid dynamic lookup of Windows API functions when possible.
* lib/getaddrinfo.c (GetProcAddress, getaddrinfo_func,
freeaddrinfo_func, getnameinfo_func, getaddrinfo_ptr, freeaddrinfo_ptr,
getnameinfo_ptr): Don't define in a build for Windows XP or higher.
(use_win32_p): Define differently.
* lib/link.c (GetProcAddress, CreateHardLinkFuncType,
CreateHardLinkFunc, initialized, initialize): Don't define in a build
for Windows XP or higher.
Daiki Ueno [Fri, 29 May 2020 03:45:40 +0000 (05:45 +0200)]
read-file: disable buffering if RF_SENSITIVE is set
* lib/read-file.c (read_file): Call setvbuf if RF_SENSITIVE.
Suggested by Glenn Strauss.
(fread_file): Suggest calling setvbuf before calling this
function. Suggested by Bruno Haible.
Bruno Haible [Fri, 29 May 2020 00:03:12 +0000 (02:03 +0200)]
Avoid dynamic loading of Windows API functions when possible.
Reported by Steve Lhomme <robux4@ycbcr.xyz> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00182.html>.
* lib/gettimeofday.c (GetProcAddress,
GetSystemTimePreciseAsFileTimeFuncType,
GetSystemTimePreciseAsFileTimeFunc, initialized, initialize): Don't
define in a build for Windows 8 or higher.
* lib/isatty.c (GetProcAddress, GetNamedPipeClientProcessIdFuncType,
GetNamedPipeClientProcessIdFunc, QueryFullProcessImageNameFuncType,
QueryFullProcessImageNameFunc, initialized, initialize): Don't define
in a build for Windows Vista or higher.
* lib/stat-w32.c (GetProcAddress, GetFileInformationByHandleExFuncType,
GetFileInformationByHandleExFunc, GetFinalPathNameByHandleFuncType,
GetFinalPathNameByHandleFunc, initialized, initialize): Likewise.
Bruno Haible [Wed, 27 May 2020 18:35:39 +0000 (20:35 +0200)]
relocatable-prog: Make more robust in multithreaded applications.
* lib/progreloc.c (O_CLOEXEC): Define fallback to 0 when use from module
relocatable-prog-wrapper.
(find_executable): Pass an O_CLOEXEC flag to open().
* modules/relocatable-prog (Depends-on): Add 'open'.
Daiki Ueno [Thu, 28 May 2020 09:40:49 +0000 (11:40 +0200)]
fopen-gnu: make 'b' flag can be used with 'e' on Windows
* lib/fopen.c (rpl_fopen): Pass O_BINARY to open, if a 'b' flag is
specified on Windows.
* tests/test-fopen-gnu.c (DATA): New define.
(main): Add test for reading binary files with an 'e' flag.
Bruno Haible [Thu, 28 May 2020 00:31:53 +0000 (02:31 +0200)]
Don't assume that UNICODE is not defined.
Some Windows types, such as TCHAR, LPTSTR, LPCTSTR, are defined
differently if the application defines the macro UNICODE.
Reported by Steve Lhomme <robux4@ycbcr.xyz> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00184.html>.
* lib/link.c (CreateHardLinkFuncType): Use LPCSTR, not LPCTSTR.
* lib/localename.c (enum_locales_fn): Use LPSTR, not LPTSTR.
* lib/stat-w32.c (GetFinalPathNameByHandleFuncType): Likewise.
Bruno Haible [Thu, 28 May 2020 00:06:51 +0000 (02:06 +0200)]
Improve pattern for defining _WIN32_WINNT.
Newer versions of the Windows API may not only add, but also remove API
functions. Therefore, when the user is e.g. building for Windows 10, we
should not set _WIN32_WINNT to e.g. Windows 8, as this may enable the
use of APIs that were present in Windows 8 but removed in Windows 10.
Suggested by Steve Lhomme <robux4@ycbcr.xyz> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00318.html>.
* lib/ftruncate.c (_WIN32_WINNT): Don't set to a smaller value.
* lib/sethostname.c (_WIN32_WINNT): Likewise.
* lib/stat-w32.c (_WIN32_WINNT): Likewise.