]> Savannah Git Hosting - gnulib.git/log
gnulib.git
8 years agostrings-c++-tests: New module.
Bruno Haible [Fri, 5 May 2017 20:40:19 +0000 (22:40 +0200)]
strings-c++-tests: New module.

* tests/test-strings-c++.cc: New file.
(ffs): Declare, missing since 2011-07-12.
* modules/strings-c++-tests: New file.

8 years agostring-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 20:36:48 +0000 (22:36 +0200)]
string-c++-tests: Update.

* tests/test-string-c++.cc (ffsl): Declare, missing since 2011-07-15.
(ffsll): Declare, missing since 2011-07-15.

8 years agostdlib-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 20:29:18 +0000 (22:29 +0200)]
stdlib-c++-tests: Update.

* tests/test-stdlib-c++.cc (posix_openpt): Declare, missing since
2011-10-18.
(ptsname_r): Declare, missing since 2011-11-07.
(qsort_r): Declare, missing since 2014-08-29.
(random, srandom, initstate, setstate): Declare, missing since
2012-01-14.
(secure_getenv): Declare, missing since 2013-02-05.

8 years agostdio-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 20:13:37 +0000 (22:13 +0200)]
stdio-c++-tests: Update.

* tests/test-stdio-c++.cc (pclose): Declare, missing since 2011-09-18.

8 years agosignal-h-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 20:08:05 +0000 (22:08 +0200)]
signal-h-c++-tests: Update.

* tests/test-signal-h-c++.cc (raise): Remove redundant declaration.

8 years agomath-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 20:03:49 +0000 (22:03 +0200)]
math-c++-tests: Update.

* tests/test-math-c++.cc (fmaf): Declare, missing since 2011-10-17.
(fma): Declare, missing since 2011-10-17.
(fmal): Declare, missing since 2011-10-17.

8 years agolocale-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 19:57:14 +0000 (21:57 +0200)]
locale-c++-tests: Update.

* tests/test-locale-c++.cc (localeconv): Declare, missing since
2012-03-25.

8 years agointtypes-c++-tests: New module.
Bruno Haible [Fri, 5 May 2017 19:50:57 +0000 (21:50 +0200)]
inttypes-c++-tests: New module.

* tests/test-inttypes-c++.cc: New file.
(strtoimax): Declare, missing since 2012-01-05.
(strtoumax): Declare, missing since 2012-01-05.
* modules/inttypes-c++-tests: New file.

8 years agodirent-c++-tests: Update.
Bruno Haible [Fri, 5 May 2017 19:38:07 +0000 (21:38 +0200)]
dirent-c++-tests: Update.

* tests/test-dirent-c++.cc (readdir): Declare, missing since 2011-09-13.
(rewinddir): Declare, missing since 2011-09-13.
(dirfd): Declare, missing since 2010-03-08.

8 years agoargp: Fix mistake in 2017-04-23 commit.
Bruno Haible [Thu, 4 May 2017 22:09:48 +0000 (00:09 +0200)]
argp: Fix mistake in 2017-04-23 commit.

* lib/argp-help.c (__argp_failure): If GNULIB_STRERROR_R_POSIX is set,
assume that strerror_r returns 'int', not 'char *'.

8 years agoargp: Fix typo.
Reuben Thomas [Thu, 4 May 2017 15:51:43 +0000 (17:51 +0200)]
argp: Fix typo.

* lib/argp-help.c (argp_doc): Fix spelling mistake in comment.

8 years agoutimens: port to Emacs + MS-Windows
Paul Eggert [Tue, 2 May 2017 07:40:41 +0000 (00:40 -0700)]
utimens: port to Emacs + MS-Windows

Skip the new MS-Windows-specific code if Emacs.
* lib/utimens.c [EMACS_CONFIGUATION]:
Avoid new MS-Windows-specific code.
(USE_SETFILETIME): New macro.
(fdutimens): Use it.

8 years agotzset: update doc for TZ problems on MS-Windows
Paul Eggert [Tue, 2 May 2017 01:00:56 +0000 (18:00 -0700)]
tzset: update doc for TZ problems on MS-Windows

* doc/posix-functions/ctime.texi,  doc/posix-functions/daylight.texi:
* doc/posix-functions/localtime.texi, doc/posix-functions/mktime.texi:
* doc/posix-functions/strftime.texi, doc/posix-functions/timezone.texi:
* doc/posix-functions/tzname.texi, doc/posix-functions/tzset.texi:
* doc/posix-functions/wcsftime.texi:
Mention some issues with TZ under MS-Windows.

8 years agocopy-file: Fix build error on mingw.
Bruno Haible [Mon, 1 May 2017 16:14:35 +0000 (18:14 +0200)]
copy-file: Fix build error on mingw.

* modules/copy-file (Depends-on): Add 'close'.

8 years agoFix recent ChangeLog entry.
Bruno Haible [Mon, 1 May 2017 15:40:15 +0000 (17:40 +0200)]
Fix recent ChangeLog entry.

8 years agotzset: Work around TZ problem on native Windows.
Bruno Haible [Mon, 1 May 2017 15:27:53 +0000 (17:27 +0200)]
tzset: Work around TZ problem on native Windows.

* m4/tzset.m4 (gl_FUNC_TZSET): Require AC_CANONICAL_HOST. On native
Windows, set REPLACE_TZSET to 1.
* lib/tzset.c (tzset): On native Windows, fix TZ if necessary, and
invoke '_tzset' instead of 'tzset'.
* doc/posix-functions/tzset.texi: Mention the native Windows workaround.

* modules/time_rz (Depends-on): Add tzset.
* lib/time_rz.c (tzset): Remove fallback definition.
* m4/time_rz.m4 (gl_TIME_RZ): Don't test for tzset.

8 years agomktime: Fix dependencies.
Bruno Haible [Mon, 1 May 2017 14:37:15 +0000 (16:37 +0200)]
mktime: Fix dependencies.

* modules/mktime (Depends-on): Add 'time'.

8 years agoNew module 'localtime-buffer', split off from module 'gettimeofday'.
Bruno Haible [Mon, 1 May 2017 14:10:46 +0000 (16:10 +0200)]
New module 'localtime-buffer', split off from module 'gettimeofday'.

* lib/localtime-buffer.h: New file.
* lib/localtime-buffer.c: New file, extracted from lib/gettimeofday.c.
* lib/time.in.h (tzset): New declaration.
(localtime, gmtime): Don't test GNULIB_GETTIMEOFDAY.
* lib/tzset.c: New file, extracted from lib/gettimeofday.c.
* lib/gettimeofday.c: Include localtime-buffer.h. Remove code that was
moved to lib/localtime-buffer.c or lib/tzset.c.
* m4/localtime-buffer.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_TZSET,
HAVE_TZSET, REPLACE_TZSET.
* m4/tzset.m4 (gl_FUNC_TZSET): Move code from m4/gettimeofday.m4 to
here, with modifications. Set HAVE_TZSET, REPLACE_TZSET. Invoke
gl_LOCALTIME_BUFFER_NEEDED.
(gl_FUNC_TZSET_CLOBBER): Don't require gl_HEADER_SYS_TIME_H; not needed
since 2007-01-18.
* m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY): Remove code that deals with
tzset.
(gl_FUNC_GETTIMEOFDAY_CLOBBER): Require gl_LOCALTIME_BUFFER_DEFAULTS.
Invoke gl_LOCALTIME_BUFFER_NEEDED instead of
gl_GETTIMEOFDAY_REPLACE_LOCALTIME.
(gl_GETTIMEOFDAY_REPLACE_LOCALTIME): Remove macro.
* modules/localtime-buffer: New file.
* modules/time (Depends-on): Remove 'gettimeofday'.
(Makefile.am): Substitute GNULIB_TZSET, HAVE_TZSET,
REPLACE_TZSET. Don't substitute GNULIB_GETTIMEOFDAY.
* modules/tzset (Description): Enable hyperlink to POSIX spec.
(Files): Add lib/tzset.c.
(Depends-on): Remove gettimeofday. Add localtime-buffer, time.
(configure.ac): Arrange to conditionally compile lib/tzset.c. Invoke
gl_TIME_MODULE_INDICATOR.
* modules/gettimeofday (Depends-on): Add localtime-buffer.

8 years agocopy-file: Preserve sub-second time stamps.
Bruno Haible [Mon, 1 May 2017 11:27:57 +0000 (13:27 +0200)]
copy-file: Preserve sub-second time stamps.

* lib/copy-file.c: Include stat-time.h, utimens.h instead of <utime.h>.
(qcopy_file_preserving): Use 'struct timespec' and utimens() to
transport the time stamps from the original file to the destination
file.
* m4/copy-file.m4 (gl_COPY_FILE): Don't test for utime, utimes.
* modules/copy-file (Depends-on): Add stat-time, utimns instead of
utime-h.

8 years agowctype: Fix problems if <wchar.h> gets included after <wctype.h>.
Bruno Haible [Mon, 1 May 2017 10:58:28 +0000 (12:58 +0200)]
wctype: Fix problems if <wchar.h> gets included after <wctype.h>.

* lib/wctype.in.h: Include not only <ctype.h> but also <wchar.h>. Do so
also on MSVC.
Reported by Eli Zaretskii <eliz@gnu.org>.

8 years agowchar: Fix compilation error with the original mingw.org mingw.
Bruno Haible [Mon, 1 May 2017 10:36:02 +0000 (12:36 +0200)]
wchar: Fix compilation error with the original mingw.org mingw.

* lib/wchar.in.h (rpl_wint_t): If <crtdefs.h> does not exist, include
<stddef.h> instead.
* m4/wint_t.m4 (gl_TYPE_WINT_T_PREREQ): New macro, extracted from
gl_WCTYPE_H.
* m4/wctype_h.m4 (gl_WCTYPE_H): Don't set HAVE_CRTDEFS_H here; require
gl_TYPE_WINT_T_PREREQ instead.
* m4/wchar_h.m4 (gl_WCHAR_H): Require gl_TYPE_WINT_T_PREREQ.
* modules/wchar (Makefile.am): Substitute HAVE_CRTDEFS_H.
Reported by Eli Zaretskii <eliz@gnu.org>.

8 years agoutimecmp: Add support for native Windows.
Bruno Haible [Mon, 1 May 2017 09:52:56 +0000 (11:52 +0200)]
utimecmp: Add support for native Windows.

* lib/utimecmp.c (SYSCALL_RESOLUTION): Set to 100 on native Windows.

8 years agoutimens: Add support for native Windows.
Bruno Haible [Mon, 1 May 2017 09:50:08 +0000 (11:50 +0200)]
utimens: Add support for native Windows.

* lib/utimens.c: Include <windows.h>, msvc-nothrow.h.
(fdutimens): Provide a native Windows implementation, like utime.c with
added tv_nsec support.
* modules/utimens (Depends-on): Add msvc-nothrow, utime.
Suggested by Tim Rühsen <tim.ruehsen@gmx.de>.

8 years agowcsftime: New module.
Bruno Haible [Sun, 30 Apr 2017 15:56:49 +0000 (17:56 +0200)]
wcsftime: New module.

* lib/wchar.in.h (wcsftime): New declaration.
* lib/wcsftime.c: New file.
* m4/wcsftime.m4: New file.
* m4/wchar_h.m4 (gl_WCHAR_H): Test for wcsftime declaration.
(gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_WCSFTIME,
HAVE_WCSFTIME, REPLACE_WCSFTIME.
* modules/wchar (Makefile.am): Substitute GNULIB_WCSFTIME,
HAVE_WCSFTIME, REPLACE_WCSFTIME.
* modules/wcsftime: New file.
* doc/posix-functions/wcsftime.texi: Mention the new module.

8 years agostrftime-fixes: New module.
Bruno Haible [Sun, 30 Apr 2017 15:14:35 +0000 (17:14 +0200)]
strftime-fixes: New module.

* lib/time.in.h (strftime): New declaration.
* lib/strftime-fixes.c: New file.
* m4/strftime.m4 (gl_FUNC_GNU_STRFTIME): Inline gl_FUNC_STRFTIME macro.
(gl_FUNC_STRFTIME): Remove macro.
* m4/strftime-fixes.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_STRFTIME,
REPLACE_STRFTIME.
* modules/time (Makefile.am): Substitute GNULIB_STRFTIME,
REPLACE_STRFTIME.
* modules/strftime-fixes: New file.
* doc/posix-functions/strftime.texi: Mention the new module.

8 years agomktime: Work around TZ problem on native Windows.
Bruno Haible [Sun, 30 Apr 2017 14:34:54 +0000 (16:34 +0200)]
mktime: Work around TZ problem on native Windows.

* lib/mktime.c: Add #ifs to make the algorithmic workaround independent
from the native Windows workaround.
* m4/mktime.m4 (gl_FUNC_MKTIME_WORKS): New macro, extracted from
gl_FUNC_MKTIME. If guessing, set gl_cv_func_working_mktime to
'guessing no'.
(gl_FUNC_MKTIME): Require it. Require AC_CANONICAL_HOST.
Set REPLACE_MKTIME to 1 on native Windows. Define NEED_MKTIME_WORKING,
NEED_MKTIME_WINDOWS.
(gl_FUNC_MKTIME_INTERNAL): Require gl_FUNC_MKTIME_WORKS, not
gl_FUNC_MKTIME. Set WANT_MKTIME_INTERNAL, not REPLACE_MKTIME. Define
NEED_MKTIME_INTERNAL.
* m4/timegm.m4 (gl_FUNC_TIMEGM): Require gl_FUNC_MKTIME_WORKS, not
gl_FUNC_MKTIME. Cope with 'guessing yes' value.
* modules/mktime-internal (configure.ac): Test WANT_MKTIME_INTERNAL,
not REPLACE_MKTIME.
* doc/posix-functions/mktime.texi: Mention the native Windows
workaround.

8 years agolocaltime: New module.
Bruno Haible [Sun, 30 Apr 2017 11:32:40 +0000 (13:32 +0200)]
localtime: New module.

* lib/time.in.h (localtime): Declare also if requested by module
'localtime'.
* lib/localtime.c: New file.
* m4/localtime.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_LOCALTIME.
* modules/time (Makefile.am): Substitute GNULIB_LOCALTIME.
* modules/localtime: New file.
* doc/posix-functions/localtime.texi: Mention the new module.

8 years agoctime: New module.
Bruno Haible [Sun, 30 Apr 2017 11:19:24 +0000 (13:19 +0200)]
ctime: New module.

* lib/time.in.h (ctime): New declaration.
* lib/ctime.c: New file.
* m4/ctime.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_CTIME,
REPLACE_CTIME.
* modules/time (Makefile.am): Substitute GNULIB_CTIME, REPLACE_CTIME.
* modules/ctime: New file.
* doc/posix-functions/ctime.texi: Mention the new module.

8 years agogettimeofday: Provide higher resolution on native Windows.
Bruno Haible [Sun, 30 Apr 2017 10:15:08 +0000 (12:15 +0200)]
gettimeofday: Provide higher resolution on native Windows.

* lib/gettimeofday.c: Don't include <sys/timeb.h>.
(GetSystemTimePreciseAsFileTimeFuncType): New variable.
(initialize): Initialize it.
(gettimeofday) [WINDOWS_NATIVE]: Use it, and convert from FILETIME to
'struct timeval'. Don't use _ftime().
* m4/gettimeofday.m4 (gl_PREREQ_GETTIMEOFDAY): Don't test for
<sys/timeb.h> and _ftime.

8 years agoDocument the problem with the Cygwin environment variable TZ.
Bruno Haible [Sun, 30 Apr 2017 09:38:25 +0000 (11:38 +0200)]
Document the problem with the Cygwin environment variable TZ.

* doc/posix-functions/tzset.texi: Add note about TZ.
* doc/posix-functions/ctime.texi: Likewise.
* doc/posix-functions/localtime.texi: Likewise.
* doc/posix-functions/mktime.texi: Likewise.
* doc/posix-functions/strftime.texi: Likewise.
* doc/posix-functions/wcsftime.texi: Likewise.
* doc/pastposix-functions/ftime.texi: Likewise.

8 years agoutime-tests: New module.
Bruno Haible [Sun, 30 Apr 2017 09:13:56 +0000 (11:13 +0200)]
utime-tests: New module.

* tests/test-utime.c: New file, based on tests/test-utimens.h.
* tests/test-utimens-common.h: Include <sys/stat.h>.
* modules/utime-tests: New file.

8 years agoutime: New module.
Bruno Haible [Sun, 30 Apr 2017 01:08:46 +0000 (03:08 +0200)]
utime: New module.

* lib/utime.in.h: Add comment for snippets.
(utime): New declaration.
* lib/utime.c: New file.
* m4/utime.m4: New file.
* m4/utime_h.m4 (gl_UTIME_H): Test for utime declaration.
(gl_UTIME_H_DEFAULTS): Initialize GNULIB_UTIME, HAVE_UTIME,
REPLACE_UTIME.
* modules/utime-h (Depends-on): Add snippets.
(Makefile.am): Substitute GNULIB_UTIME, HAVE_UTIME, REPLACE_UTIME.
Insert snippets.
* modules/utime: New file.
* doc/posix-functions/utime.texi: Mention the new module.

8 years agoutime-h: Modernize handling of 'struct utimbuf'.
Bruno Haible [Sat, 29 Apr 2017 23:26:05 +0000 (01:26 +0200)]
utime-h: Modernize handling of 'struct utimbuf'.

* lib/utime.in.h: Include next <utime.h> if it exists.
(utimbuf): Define to _utimbuf on native Windows.
* m4/utime-h.m4 (gl_UTIME_H): Check for prerequisites of include_next.
Set UTIME_H on native Windows.
(gl_UTIME_MODULE_INDICATOR, gl_HEADER_UTIME_H_DEFAULTS): New macros.
* modules/utime-h (Depends-on): Add include_next.
(Makefile.am): Substitute also HAVE_UTIME_H, INCLUDE_NEXT,
PRAGMA_SYSTEM_HEADER, PRAGMA_COLUMNS, NEXT_UTIME_H.

* lib/utimens.c (utimbuf): Remove fallback definition.
* m4/utimens.m4 (gl_UTIMENS): Don't require
gl_CHECK_TYPE_STRUCT_UTIMBUF.
* m4/utimbuf.m4: Remove file.
* modules/utimens (Files): Remove m4/utimbuf.m4.

8 years agoMake use of module 'utime-h'.
Bruno Haible [Sat, 29 Apr 2017 22:03:50 +0000 (00:03 +0200)]
Make use of module 'utime-h'.

* modules/copy-file (Depends-on): Add utime-h.
* lib/copy-file.c: Assume that <utime.h> exists.
* m4/copy-file.m4 (gl_COPY_FILE): Don't test for <utime.h>.

* modules/utimens (Depends-on): Add utime-h.
* lib/utimens.c: Assume that <utime.h> exists.

8 years agoutime-h: New module.
Bruno Haible [Sun, 30 Apr 2017 08:21:22 +0000 (10:21 +0200)]
utime-h: New module.

* m4/utime_h.m4: New file.
* lib/utime.in.h: New file.
* modules/utime-h: New file.
* doc/posix-headers/utime.texi: Mention the new module.

* tests/test-utime-h.c: New file.
* modules/utime-h-tests: New file.

8 years agoFix a few typos.
Bruno Haible [Sun, 30 Apr 2017 08:15:55 +0000 (10:15 +0200)]
Fix a few typos.

* m4/fstat.m4 (gl_FUNC_FSTAT): Require AC_CANONICAL_HOST.
* m4/stat.m4 (gl_FUNC_STAT): Fix comment.
* doc/posix-functions/fstat.texi: Fix a plural typo.
* doc/posix-functions/stat.texi: Likewise.
* m4/include_next.m4: Update comments.

8 years agoerror: Fix mistake in 2017-04-23 commit.
Bruno Haible [Sat, 29 Apr 2017 21:01:39 +0000 (23:01 +0200)]
error: Fix mistake in 2017-04-23 commit.

* lib/error.c (print_errno_message): If GNULIB_STRERROR_R_POSIX is set,
assume that strerror_r returns 'int', not 'char *'.

8 years agostat: Fix time_t values and other problems on native Windows platforms.
Bruno Haible [Sat, 29 Apr 2017 13:05:15 +0000 (15:05 +0200)]
stat: Fix time_t values and other problems on native Windows platforms.

* doc/posix-functions/stat.texi: Mention the problem with the Microsoft
implementations of stat().
* lib/stat.c: Include filename.h instead of dosname.h. Include
malloca.h, stat-w32.h.
(is_unc_root): New function.
(rpl_stat): New implementation for native Windows. Remove
REPLACE_FUNC_STAT_DIR code.
* m4/stat.m4 (gl_FUNC_STAT): On native Windows, set REPLACE_STAT always.
Don't define REPLACE_FUNC_STAT_DIR.
(gl_PREREQ_STAT): Require gl_HEADER_SYS_STAT_H.
* modules/stat (Files): Add lib/stat-w32.h, lib/stat-w32.c.
(Depends-on): Remove dosname. Add filename, malloca.
(configure.ac): Also compile lib/stat-w32.c.

8 years agofstat: Fix time_t values on native Windows platforms.
Bruno Haible [Sat, 29 Apr 2017 12:55:22 +0000 (14:55 +0200)]
fstat: Fix time_t values on native Windows platforms.

* doc/posix-functions/fstat.texi: Mention the problem with st_*time.
* lib/stat-w32.h: New file.
* lib/stat-w32.c: New file.
* lib/fstat.c: Don't include msvc-inval.h. Include msvc-nothrow.h,
stat-w32.h instead.
(fstat_nothrow): Remove function.
(rpl_fstat): Implement by means of _gl_fstat_by_handle.
* m4/fstat.m4 (gl_FUNC_FSTAT): On native Windows, set REPLACE_FSTAT
always.
(gl_PREREQ_FSTAT): Require gl_HEADER_SYS_STAT_H.
* modules/fstat (Files): Add lib/stat-w32.h, lib/stat-w32.c.
(Depends-on): Remove msvc-inval. Add pathmax, msvc-nothrow.
(configure.ac): Also compile lib/stat-w32.c.

8 years agogetopt: port to Solaris 10 with circa-1997 glibc getopt.h
Paul Eggert [Sat, 29 Apr 2017 18:09:39 +0000 (11:09 -0700)]
getopt: port to Solaris 10 with circa-1997 glibc getopt.h

Problem reported by Assaf Gordon and Gavin Smith in:
http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00157.html
* lib/getopt-pfx-ext.h (_getopt_internal) [__GETOPT_PREFIX]:
#define this, too.

8 years agostrerror_r-posix: Fixes for MSVC 14.
Bruno Haible [Sat, 29 Apr 2017 11:23:28 +0000 (13:23 +0200)]
strerror_r-posix: Fixes for MSVC 14.

* lib/strerror_r.c: Include <stdarg.h>.
(strerror_r): Provide error messages for errno values 100...140.
* doc/posix-functions/strerror_r.texi: Mention the MSVC 14 problem.

8 years agonoreturn: New module.
Bruno Haible [Wed, 26 Apr 2017 21:25:11 +0000 (23:25 +0200)]
noreturn: New module.

* lib/noreturn.h: New file.
* modules/noreturn: New file.
* tests/test-noreturn.c: New file.
* modules/noreturn-tests: New file.
* tests/test-noreturn-c++.cc: New file.
* modules/noreturn-c++-tests: New file.

8 years agowctype-h: Fix compilation error with the original mingw.org mingw.
Bruno Haible [Thu, 27 Apr 2017 16:59:24 +0000 (18:59 +0200)]
wctype-h: Fix compilation error with the original mingw.org mingw.

* m4/wctype_h.m4 (gl_WCTYPE_H): Test for <crtdefs.h>. Set
HAVE_CRTDEFS_H.
* modules/wctype-h (Makefile.am): Substitute HAVE_CRTDEFS_H.
* lib/wctype.in.h (rpl_wint_t): If <crtdefs.h> does not exist, include
<stddef.h> instead.
Reported and proposed by Eli Zaretskii <eliz@gnu.org>.

8 years agonap.h: Fix compilation on non windows platforms
Pádraig Brady [Thu, 27 Apr 2017 04:46:55 +0000 (21:46 -0700)]
nap.h: Fix compilation on non windows platforms

* tests/nap.h: Move misplaced endif.

8 years agotime_rz: fix heap buffer overflow vulnerability
Pádraig Brady [Mon, 24 Apr 2017 08:43:36 +0000 (01:43 -0700)]
time_rz: fix heap buffer overflow vulnerability

This issue has been assigned CVE-2017-7476 and was
detected with American Fuzzy Lop 2.41b run on the
coreutils date(1) program with ASAN enabled.

  ERROR: AddressSanitizer: heap-buffer-overflow on address 0x...
  WRITE of size 8 at 0x60d00000cff8 thread T0
  #1 0x443020 in extend_abbrs lib/time_rz.c:88
  #2 0x443356 in save_abbr lib/time_rz.c:155
  #3 0x44393f in localtime_rz lib/time_rz.c:290
  #4 0x41e4fe in parse_datetime2 lib/parse-datetime.y:1798

A minimized reproducer is the following 120 byte TZ value,
which goes beyond the value of ABBR_SIZE_MIN (119) on x86_64.
Extend the aa...b portion to overwrite more of the heap.

  date -d $(printf 'TZ="aaa%020daaaaaab%089d"')

localtime_rz and mktime_z were affected since commit 4bc76593.
parse_datetime was affected since commit 4e6e16b3f.

* lib/time_rz.c (save_abbr): Rearrange the calculation determining
whether there is enough buffer space available.  The rearrangement
ensures we're only dealing with positive numbers, thus avoiding
the problematic promotion of signed to unsigned causing an invalid
comparison when zone_copy is more than ABBR_SIZE_MIN bytes beyond
the start of the buffer.
* tests/test-parse-datetime.c (main): Add a test case written by
Paul Eggert, which overwrites enough of the heap so that
standard glibc will fail with "free(): invalid pointer"
without the patch applied.
Reported and analyzed at https://bugzilla.redhat.com/1444774

8 years agoxalloc: add missing integer overflow check
Paul Eggert [Wed, 26 Apr 2017 18:38:30 +0000 (11:38 -0700)]
xalloc: add missing integer overflow check

* lib/xalloc.h (x2nrealloc): Also check for multiplication
overflow when P is null.

8 years agoparse-datetime: make it standalone
Paul Eggert [Tue, 25 Apr 2017 18:58:30 +0000 (11:58 -0700)]
parse-datetime: make it standalone

* lib/parse-datetime.y: Include <stdarg.h>, for va_start etc.
(_GL_ATTRIBUTE_FORMAT): New macro.
These are needed to get './gnulib-tool --test parse-datetime' to work.

8 years agonap.h: Port to native Windows.
Bruno Haible [Sun, 23 Apr 2017 17:19:35 +0000 (19:19 +0200)]
nap.h: Port to native Windows.

* tests/nap.h (nap_get_stat): Renamed from get_stat. Remove argument fd;
use nap_fd instead. On native Windows, close and reopen nap_fd.
(nap_works): Don't compare the ctimes, because on native Windows, these
are the creation times.
(nap): Update.

8 years agonap.h: Fix logic.
Bruno Haible [Sun, 23 Apr 2017 17:09:32 +0000 (19:09 +0200)]
nap.h: Fix logic.

* tests/nap.h (nap): Avoid signed integer overflow in loop.

8 years agoFix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.
Bruno Haible [Sun, 23 Apr 2017 17:02:08 +0000 (19:02 +0200)]
Fix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.

* modules/strerror_r-posix (configure.ac): Invoke gl_MODULE_INDICATOR.
* lib/error.c: Test GNULIB_STRERROR_R_POSIX before testing
HAVE_DECL_STRERROR_R, HAVE_STRERROR_R, or STRERROR_R_CHAR_P.
* lib/argp-help.c (__argp_failure): Likewise.

8 years agostrerror_r-posix: Revert commits from 2016-10-16,2016-11-04,2016-11-14.
Bruno Haible [Sun, 23 Apr 2017 16:27:44 +0000 (18:27 +0200)]
strerror_r-posix: Revert commits from 2016-10-16,2016-11-04,2016-11-14.

* m4/strerror_r.m4: Revert changes since 2016-10-16.
* lib/strerror_r.c: Likewise.

8 years agoTarget a C99 subset, not a C89 subset
Paul Eggert [Mon, 24 Apr 2017 03:54:35 +0000 (20:54 -0700)]
Target a C99 subset, not a C89 subset

For many years Gnulib has targeted C89 and has resisted using C99
features, as some Gnulib-using programs still wanted to target
C89.  As this no longer seems to be the case, relax the porting
requirements to allow some C99 features.  This is merely a change
to the documentation, to give other Gnulib developers a chance to
weigh in on the topic.
* doc/extern-inline.texi (extern inline):
* doc/gnulib-readme.texi (Portability guidelines):
* doc/gnulib-tool.texi (Initial import):
* doc/gnulib.texi (Header files):
Modernize to talk about C99 and C11 instead of C89 and C99.
* doc/gnulib-readme.texi (Portability guidelines):
Now a section, not merely a subsection, so that it
can be split up.  Modernize a bit.
(C language versions, C99 features assumed)
(C99 features avoided):
New sections.

8 years agodoc: New section "Modules that modify the way other modules work".
Bruno Haible [Sun, 23 Apr 2017 16:06:19 +0000 (18:06 +0200)]
doc: New section "Modules that modify the way other modules work".

* doc/gnulib.texi (Modules that modify the way other modules work): New
section.

8 years agostat-time: Update comments.
Bruno Haible [Sun, 23 Apr 2017 11:18:16 +0000 (13:18 +0200)]
stat-time: Update comments.

* lib/stat-time.h: Fix reference regarding st_ctime on Windows.
* tests/test-utimens-common.h: Add reference regarding st_ctime on
Windows.

8 years agoglob: Fix more memory leaks.
Bruno Haible [Sat, 1 Apr 2017 13:15:18 +0000 (15:15 +0200)]
glob: Fix more memory leaks.

* lib/glob.c (glob): Free allocated memory before returning.
Reported by Coverity via Tim Rühsen.

8 years agopoll: improve fast check for out-of-range NFD
Paul Eggert [Sun, 23 Apr 2017 01:48:39 +0000 (18:48 -0700)]
poll: improve fast check for out-of-range NFD

* lib/poll.c: Do not include intprops.h.
(poll): Compare NFD to INT_MAX, not to TYPE_MAXIMUM (nfds_t) / 2.
* modules/poll (Depends-on): Remove intprops.

8 years agoftoastr: cite a newer paper
Paul Eggert [Sun, 23 Apr 2017 01:34:07 +0000 (18:34 -0700)]
ftoastr: cite a newer paper

* lib/ftoastr.c (FTOASTR): In comment, cite Andrysco et al. 2016
instead of Loitsch 2010.

8 years agopoll: Enable argument check also in the Windows implementation.
Bruno Haible [Sun, 23 Apr 2017 01:25:10 +0000 (03:25 +0200)]
poll: Enable argument check also in the Windows implementation.

* lib/poll.c (poll) [WINDOWS_NATIVE]: Check value of nfd correctly.
Reported by Paul Eggert.

8 years agogetlogin_r: Work around bug in Mac OS X 10.12.
Bruno Haible [Sun, 23 Apr 2017 00:45:19 +0000 (02:45 +0200)]
getlogin_r: Work around bug in Mac OS X 10.12.

* m4/getlogin_r.m4 (gl_FUNC_GETLOGIN_R): Test also against the Mac OS X
bug.
* lib/getlogin_r.c (getlogin_r): When getlogin_r returns a string of the
given size minus 1, call getlogin_r a second time, on a larger buffer.
* modules/getlogin_r (Depends-on): Add malloca.
* doc/posix-functions/getlogin_r.texi: Mention the Mac OS X bug.

8 years agoparse-datetime: fix %z and prefer signed int
Paul Eggert [Sat, 22 Apr 2017 22:13:24 +0000 (15:13 -0700)]
parse-datetime: fix %z and prefer signed int

%z problem reported by Pádraig Brady in:
http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00103.html
While fixing it, I decided to prefer signed ints to size_t, as
they are less error-prone (e.g., ubsan catches overflow).
* lib/parse-datetime.y (textint, parser_control, lookup_word, yylex)
(parse_datetime2): Prefer ptrdiff_t to size_t for sizes and object
counts, since signed integers make for better debugging.
(date): Don’t assume %z works in printf formats.
(debug_strfdatetime, debug_strfdate, debug_strftime): Use int for
sizes of buffers known to be small, e.g., because we’re using snprintf.
(parse_datetime2): Simplify call to debug_mktime_not_ok.

8 years ago*printf: Work around rounding bug on Mac OS X.
Bruno Haible [Sat, 22 Apr 2017 14:27:45 +0000 (16:27 +0200)]
*printf: Work around rounding bug on Mac OS X.

* m4/printf.m4 (gl_PRINTF_DIRECTIVE_A): Test for Mac OS X 10.12 bug.
* doc/posix-functions/*printf.texi: Mention the rounding bugs of
Mac OS X and FreeBSD.
* doc/glibc-functions/*printf.texi: Likewise.

8 years agovasnprintf tests: Avoid warnings.
Bruno Haible [Sat, 22 Apr 2017 12:51:37 +0000 (14:51 +0200)]
vasnprintf tests: Avoid warnings.

* tests/test-vasnprintf-posix3.c (test_function, my_asnprintf,
test_vasnprintf, test_asnprintf): Don't define if there's nothing to
test.

8 years agosys_file tests: Avoid warning.
Bruno Haible [Sat, 22 Apr 2017 12:43:23 +0000 (14:43 +0200)]
sys_file tests: Avoid warning.

* tests/test-sys_file.c (main): Add a default clause to the switch
statement.

8 years agosethostname: Update doc.
Bruno Haible [Sat, 22 Apr 2017 12:39:09 +0000 (14:39 +0200)]
sethostname: Update doc.

* doc/glibc-functions/sethostname.texi: Mention differing prototype on
Mac OS X.

8 years agoquotearg tests: Avoid warnings.
Bruno Haible [Sat, 22 Apr 2017 12:24:36 +0000 (14:24 +0200)]
quotearg tests: Avoid warnings.

* tests/test-quotearg.c: Don't include test-quotearg.h if ENABLE_NLS is
false.

8 years agopoll: Enable argument check.
Bruno Haible [Sat, 22 Apr 2017 12:18:45 +0000 (14:18 +0200)]
poll: Enable argument check.

* lib/poll.c: Include intprops.h.
(poll): Check value of nfd correctly.
* modules/poll (Depends-on): Add intprops.

8 years agoget-rusage-data: Avoid warnings on Mac OS X.
Bruno Haible [Sat, 22 Apr 2017 11:51:02 +0000 (13:51 +0200)]
get-rusage-data: Avoid warnings on Mac OS X.

* lib/get-rusage-data.c: On Mac OS X, don't define
get_rusage_data_via_setrlimit nor get_rusage_data_via_iterator.
(get_rusage_data) [Mac OS X]: Just return 0.

8 years agoxbinary-io: Fix build error.
Bruno Haible [Sat, 22 Apr 2017 10:02:38 +0000 (12:02 +0200)]
xbinary-io: Fix build error.

* modules/xbinary-io (Depends-on): Add gettext-h.
* lib/xbinary-io.c: Include gettext.h and define _().
Reported by Gisle Vanem <gisle.vanem@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00089.html>.

8 years agoparse-datetime: overflow and debug cleanups
Paul Eggert [Sat, 22 Apr 2017 09:11:26 +0000 (02:11 -0700)]
parse-datetime: overflow and debug cleanups

This long patch was triggered by this bug report from Ruediger Meier:
http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00028.html
I fixed the bug he noted, then found some others nearby, and then
still others.  Oh my goodness, there were a lot of bugs.  I cleaned
up some of the code to follow GNU standards while I was at it.
* lib/parse-datetime.y (ISDIGIT): Remove; all callers changed to
use c_isdigit.
(EPOCH_YEAR): Remove; unused.
(TM_YEAR_BASE): Now an enum rather than a macro.
(HOUR, debug_strfdatetime): Multiply hour by 3600, not 60, to get
time zone offset, since timezones now are in terms of seconds and
not minutes.
(long_time_t): Remove.  All uses replaced by time_t or intmax_t as
appropriate.  Verify that intmax_t is wide enough.
(time_overflow, time_zone_str): New functions, used to deal
more reliably with overflow.
(dbg_printf): Add printf attribute, to help catch integer width errors.
(textint, relative_time, parser_control, time_zone_hhmm, set_hhmmss)
(%union, to_hour, yylex, parse_datetime2):
Use intmax_t instead of long int and/or long_time_t.
All uses changed.
(DBGBUFSIZE): Move earlier.
(relative_time, set_hhmmss, parser_control):
Just use int for nanoseconds and for time zones; that’s wide enough.
(parser_control): Use bool for members like year_seen that can
be booleans instead of counters.  All uses changed.
Remove debug_default_input_timezone; no longer needed.
All uses removed.
(apply_relative_time): Return a bool overflow flag.
All uses changed to check for overflow.
(apply_relative_time, zone, date, relunit, relunit_snumber)
(signed_seconds, unsigned_seconds, yylex, parse_datetime2):
Check for integer overflow portably.
(str_days): Use just int for N, as it’s wide enough.
Prefer 2D char arrays to arrays of char * when it looks like
2D is a win on typical platforms.
Prefer snprintf to strncpy/strncat, for simplicity;
all buffers are smaller than INT_MAX so this is safe.
(TIME_ZONE_BUFSiZE, TM_YEAR_BUFSIZE): New constants.
(debug_print_current_time): Don’t assume tv_nsec is of type long,
as this is not true on x32.  Output "." before any nanoseconds.
(debug_print_current_time, parse_datetime2):
Output local zones using a more-consistent format.
(debug_print_current_time, date, parse_datetime2):
(main) [TEST]:
Don’t assume time_t is the same width as long.
(print_rel_part): New function, replacing ...
(PRINT_REL_PART): ... this macro, which was removed.  All uses changed.
(debug_print_relative_time): Use bool for boolean.
(local_zone): dsts_seen now counts only tDST instances.
(date): Fix printf of size_t to use %z.  Do not assume numeric
tokens have negative values merely because the context suggests
a syntax with "-" separating tokens.
(time_zone_hhmm): Return bool success indicator, which checks for
overflow.  Store result into PC->time_zone instead.  All callers
changed.
(tm_year_str): New function.  Return a bool success indicator and
store the result into a buffer.  All callers changed.  Output the
numerically correct string even if adding 1900 to the year would
overflow.
(to_tm_year): New function, replacing the old to_year.  All
callers changed.
(tm_diff): Sync with glibc.
(lookup_word): Use to_uchar instead of doing it by hand.
(TZBUFSIZE): Now local to the only function that needs it.
(debug_strfdatetime): Simplify now that time zones are int seconds.
(debug_strfdate): Work even if tm_year + 1900 would overflow.
(get_effective_timezone): Remove.  All uses removed.
(parse_datetime2): Use fprintf in pieces instead of snprintfing
to a fixed-size buffer.  Don’t assume that gmtime succeeds iff
localtime succeeds.  Use tm_gmtoff if available.  Simplify how
‘goto fail;’ works in conjunction with the ‘ok’ flag.
* m4/parse-datetime.m4 (gl_PARSE_DATETIME): Don’t define
TIME_T_FITS_IN_LONG_INT, as it is no longer needed.
* modules/parse-datetime (Depends-on): Add inttypes.

8 years agogettext-h: Avoid -Wundef warning.
Bruno Haible [Fri, 21 Apr 2017 23:37:22 +0000 (01:37 +0200)]
gettext-h: Avoid -Wundef warning.

* lib/gettext.h: Test the value of ENABLE_NLS only if it is defined.
Reported by Tim Rühsen <tim.ruehsen@gmx.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00022.html>.

8 years agoerror: Avoid "function declaration isn't a prototype" warning.
Tim Rühsen [Wed, 5 Apr 2017 13:58:22 +0000 (15:58 +0200)]
error: Avoid "function declaration isn't a prototype" warning.

* lib/error.c (strerror_r): Turn K&R C prototype to an ANSI C prototype.

8 years agovasnprintf: Fix for MSVC 14.
Bruno Haible [Fri, 21 Apr 2017 15:24:48 +0000 (17:24 +0200)]
vasnprintf: Fix for MSVC 14.

* lib/vasnprintf.c (USE_MSVC__SNPRINTF): New macro.
Everywhere, use !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF instead
of !HAVE_SNPRINTF_RETVAL_C99.

8 years agombrtowc tests: Fix test failures on MSVC 14.
Bruno Haible [Fri, 21 Apr 2017 14:55:49 +0000 (16:55 +0200)]
mbrtowc tests: Fix test failures on MSVC 14.

* tests/test-mbrtowc-w32.c (test_one_locale): Accept MSVC's conversion
behaviour for invalid input.

8 years agombsinit: Fix for MSVC 14.
Bruno Haible [Fri, 21 Apr 2017 14:43:01 +0000 (16:43 +0200)]
mbsinit: Fix for MSVC 14.

* lib/mbsinit.c (mbsinit): If GNULIB_defined_mbstate_t, provide an
implementation that is in sync with mbrtowc.c. On other platforms, use
an adequate ad-hoc implementation.

8 years agoFix test-mbrtowc5.sh failure on native Windows.
Bruno Haible [Fri, 21 Apr 2017 13:41:54 +0000 (15:41 +0200)]
Fix test-mbrtowc5.sh failure on native Windows.

* lib/setlocale.c (setlocale_unixlike): Accept "POSIX" as an alias for
"C".

8 years agoAvoid accidental use of native Windows APIs on Cygwin.
Bruno Haible [Fri, 21 Apr 2017 13:28:40 +0000 (15:28 +0200)]
Avoid accidental use of native Windows APIs on Cygwin.

* lib/getaddrinfo.c (WINDOWS_NATIVE): Don't define on Cygwin.
* lib/localcharset.c (WINDOWS_NATIVE): Likewise.
* lib/localename.c (WINDOWS_NATIVE): Likewise.

8 years agoRemove red warnings from the generated MODULES.html.
Bruno Haible [Fri, 21 Apr 2017 01:10:32 +0000 (03:10 +0200)]
Remove red warnings from the generated MODULES.html.

* modules/fcntl (Description): Disambiguate function references.
* modules/getcwd-lgpl (Description): Likewise.
* modules/hostent (Description): Likewise.
* modules/servent (Description): Likewise.
* modules/tempname (Description): Likewise.

8 years agoverify tests: Fix spurious failure with parallel make.
Bruno Haible [Thu, 20 Apr 2017 19:27:40 +0000 (21:27 +0200)]
verify tests: Fix spurious failure with parallel make.

* gnulib-tool (func_emit_tests_Makefile_am): Emit initialization of
EXTRA_PROGRAMS.
* tests/test-verify.sh: Build test-verify-try.o, not test-verify.o.
* tests/test-verify-try.c: New file.
* modules/verify-tests (Files): Add it.
(EXTRA_PROGRAMS): Add test-verify-try.
(MOSTLYCLEANFILES): Update accordingly.
Reported by Adam James Stewart <ajstewart@anl.gov>.

8 years agovma-iter: Fix compilation error on Solaris 7.
Bruno Haible [Tue, 18 Apr 2017 23:27:17 +0000 (01:27 +0200)]
vma-iter: Fix compilation error on Solaris 7.

* lib/vma-iter.c (vma_iterate): Treat missing MAP_ANONYMOUS on Solaris
like on IRIX, OSF/1.
Reported by Tom G. Christensen <tgc@jupiterrise.com>.

8 years agovma-iter: Fix conflict with module 'largefile' on 32-bit Solaris 9.
Bruno Haible [Tue, 18 Apr 2017 23:03:34 +0000 (01:03 +0200)]
vma-iter: Fix conflict with module 'largefile' on 32-bit Solaris 9.

* modules/vma-iter (configure.ac): Test whether <sys/procfs.h> can be
included.
* lib/vma-iter.c: On Solaris, test HAVE_SYS_PROCFS_H before including
<sys/procfs.h>.
* lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Don't define on Solaris when
<sys/procfs.h> cannot be included.
Reported by Tom G. Christensen <tgc@jupiterrise.com>.

8 years agogetopt-gnu: Add comments.
Bruno Haible [Tue, 18 Apr 2017 22:05:34 +0000 (00:05 +0200)]
getopt-gnu: Add comments.

* m4/getopt.m4 (gl_FUNC_GETOPT_GNU): Add comments.
* modules/getopt-gnu (configure.ac): Likewise.

8 years agoregex: port better to Solaris 10
Paul Eggert [Sun, 16 Apr 2017 19:43:20 +0000 (12:43 -0700)]
regex: port better to Solaris 10

Solaris 10 <locale.h> includes <libintl.h>, which #defines
gettext, and this causes a double #define.
Problem reported by Gavin Smith in:
http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00056.html
* lib/regex_internal.h (gettext): #undef before #defining.

8 years agoautoupdate
Karl Berry [Sat, 15 Apr 2017 21:37:10 +0000 (14:37 -0700)]
autoupdate

8 years agointprops: improve comments
Paul Eggert [Sat, 15 Apr 2017 21:27:11 +0000 (14:27 -0700)]
intprops: improve comments

* lib/intprops.h: Improve and shorten commentary.
For the record, if we ever run into a pedantic compiler that
behaves differently from GCC when converting an out-of-range value
to a signed integer, we can work around the problem with something
like the following code, where UCT is the signed counterpart of T
(UCT is sometimes narrower than UT) and all callers are changed
accordingly:
   ((t) ((ut) (a) op (ut) (b)))
   (TYPE_MINIMUM (t) <= (uct) ((ut) (a) op (ut) (b)) \
    ? ((t) (uct) (((ut) (a) op (ut) (b)) - TYPE_MINIMUM (t)) \
       + TYPE_MINIMUM (t)) \
    : (t) (uct) ((ut) (a) op (ut) (b)))

8 years agointprops: fix comment typo
Paul Eggert [Sat, 15 Apr 2017 02:03:20 +0000 (19:03 -0700)]
intprops: fix comment typo

8 years agointprops: try to avoid tickling similar bugs
Paul Eggert [Sat, 15 Apr 2017 01:55:42 +0000 (18:55 -0700)]
intprops: try to avoid tickling similar bugs

* lib/intprops.h (_GL_INT_OP_CALC): Document that UT no longer
needs to be the same width as T; it can be wider.
Change callers so that UT is at least as wide as unsigned int,
as I suspect that this is less likely to run into compiler bugs.

8 years agointprops: port to Oracle Studio 12.3 x86
Paul Eggert [Sat, 15 Apr 2017 00:38:58 +0000 (17:38 -0700)]
intprops: port to Oracle Studio 12.3 x86

Problem reported by Gavin Smith in:
http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00049.html
* lib/intprops.h (_GL_INT_OP_WRAPV_VIA_UNSIGNED):
Convert unsigned to signed via the usual rather than the standard way,
to avoid a compiler bug in Oracle Studio 12.3 x86.

8 years agogetopt: prefer - to _ in new file names
Paul Eggert [Sun, 9 Apr 2017 06:48:02 +0000 (23:48 -0700)]
getopt: prefer - to _ in new file names

* lib/getopt-cdefs.in.h: Rename from lib/getopt_cdefs.in.h.
* lib/getopt-core.h: Rename from lib/getopt_core.h.
* lib/getopt-ext.h: Rename from lib/getopt_ext.h.
* lib/getopt-pfx-core.h: Rename from lib/getopt_pfx_core.h.
* lib/getopt-pfx-ext.h: Rename from lib/getopt_pfx_ext.h.
All uses changed.

8 years agogetopt: port recent getopt changes to macOS
Paul Eggert [Sun, 9 Apr 2017 00:26:03 +0000 (17:26 -0700)]
getopt: port recent getopt changes to macOS

Problem reported by Harald Maier (Bug#26398).
The macOS C compiler uses __nonnull for its own purposes and that
clashes with glibc's __nonnull.
* lib/getopt.in.h: Add comment for _GL_ARG_NONNULL snippet.
* lib/getopt_cdefs.in.h (__nonnull): Remove.
* lib/getopt_core.h (getopt):
* lib/getopt_ext.h (getopt_long, getopt_long_only):
Use _GL_ARG_NONNULL, not __nonnull.
* lib/unistd.in.h: Move snippet hooks to before where the getopt
.h files are included, so that _GL_ARG_NONNULL is defined in time.
* modules/getopt-posix (Depends-on): Add snippet/arg-nonnull.
(getopt.h): Interpolate _GL_ARG_NONNULL snippet.

8 years agogetopt-gnu: omit some duplicate code
Paul Eggert [Thu, 6 Apr 2017 22:41:05 +0000 (15:41 -0700)]
getopt-gnu: omit some duplicate code

* m4/getopt.m4 (gl_FUNC_GETOPT_GNU): Don’t require
gl_FUNC_GETOPT_POSIX, as the configure.ac code generated by
gnulib-tool already does this.
* modules/getopt-gnu (configure.ac): Omit code duplicated from
getopt-posix, which we depend on.

8 years agogetopt-posix: use angle-bracket include
Paul Eggert [Thu, 6 Apr 2017 20:15:46 +0000 (13:15 -0700)]
getopt-posix: use angle-bracket include

* lib/getopt1.c: Include <config.h>, not "config.h".

8 years agogetopt: annotate files with relationship to glibc
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: annotate files with relationship to glibc

As the final act in this patchset, adjust the message at the top of
each file to indicate which files are synced with glibc.  (This has
already been done for most of the headers.)

* lib/getopt.c, lib/getopt1.c, lib/getopt_int.h:
Mention in top-of-file boilerplate that these files are shared
between glibc and gnulib.

8 years agogetopt: split up getopt.in.h and eliminate __need_getopt
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: split up getopt.in.h and eliminate __need_getopt

Over in glibc, all of the __need macros are being phased out in favor
of small headers that declare only the necessary components, as this
is much simpler and less prone to bugs.  As getopt is shared with
glibc, gnulib needs to do the same for __need_getopt.

__need_getopt is misnamed; what it really means is "we want only the
getopt features specified in POSIX, not the GNU extensions".  glibc
placed the "meat" of getopt.h into getopt_core.h and getopt_ext.h;
these files can be shared verbatim with gnulib.  The portability
wrapper, on the other hand, they have renounced altogether; glibc's
getopt.h will no longer be shared with gnulib at all.  In exchange,
certain glibc-specific quirks (having to do with __posix_getopt) no
longer need appear in gnulib's headers at all.

This patch merges getopt_core.h and getopt_ext.h from glibc, and
splits up the current gnulib-side portability wrapper into three
additional headers: getopt_pfx_core.h and getopt_pfx_ext.h handle
__GETOPT_PREFIX for their respective headers, getopt_cdefs.in.h
handles things like __BEGIN_DECLS and __THROW, and getopt.in.h and
unistd.in.h just use them.  All new files are clearly marked with
whether they are shared with glibc.

* lib/getopt.in.h: Eliminate __need_getopt.  Break up into ...
* lib/getopt_core.h, lib/getopt_ext.h: ... these new files shared
with glibc, and ...
* lib/getopt_cdefs.in.h, lib/getopt_pfx_core.h
* lib/getopt_pfx_ext.h: ... these new files not shared with glibc.
* lib/unistd.in.h: Include getopt_cdefs.h and getopt_pfx_core.h,
instead of defining __need_getopt and including the full getopt.h.

* m4/getopt.m4 (gl_GETOPT_SUBSTITUTE_HEADER): Check for sys/cdefs.h.
Define substitution variables GETOPT_CDEFS_H and HAVE_SYS_CDEFS_H.
* modules/getopt-posix (Files): Add new headers and sort list.
(Depends-on): No longer need snippet/arg-nonnull.
(Makefile.am): Generate getopt_cdefs.h.

8 years agogetopt: better handling of ambiguous options
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: better handling of ambiguous options

glibc's getopt uses alloca to construct a linked list of possibilities
for an "ambiguous" long option.  In gnulib, malloc should be used
instead.  Providing for both cases complicates things a fair bit.

This patch rewrites ambiguous-option handling to use a boolean vector
instead of a linked list.  There is then only one allocation that
might need freeing; in glibc it can honor __libc_use_alloca as usual,
and in gnulib we define __libc_use_alloca to always be false, so we
don't need ifdefs in the middle of the function.  This should also be
slightly more efficient in the normal case of long options being fully
spelled out -- I think most people aren't even aware they _can_
sometimes abbreviate long options.

One interesting consequence is that the list of possibilities is now
printed in exactly the order they appear in the list of long options,
instead of the first possibility being shuffled to the end.

(The patch looks bigger than it really is because there's a fair bit
of reindentation and code rearrangement.)

* lib/getopt.c: When used standalone, define __libc_use_alloca
as always false and alloca to abort if called.
(process_long_option): Rewrite handling of ambiguous long options
to use a single boolean vector, not a linked list; use
__libc_use_alloca to decide whether to allocate this using alloca.

8 years agogetopt: refactor long-option handling
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: refactor long-option handling

There were two copies of the bulk of the code to handle long options.
Now there is only one.

This change temporarily removes the logic to avoid using alloca when
standalone; the next patch in the series will restore it.

* lib/getopt.c (process_long_option): New function split out
from _getopt_internal_r.
(_getopt_internal_r): Replace both copies of the long-option
processing code with calls to process_long_option.

8 years agogetopt: tidy up _getopt_initialize a bit
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: tidy up _getopt_initialize a bit

_getopt_data.__posixly_correct is completely redundant to
_getopt_data.__ordering, and some work that logically belongs in
_getopt_initialize was being done by _getopt_internal_r, making the
code harder to understand.

As a side effect, getenv will no longer be called if the first
character of the options string is '+' or '-', which is probably a
Good Thing.  (Perhaps we should have a flag character that
specifically asks for the permutation behavior?)

* lib/getopt_int.h (_getopt_data): Remove __posixly_correct field.
* lib/getopt.c (_getopt_internal_r): Move some initialization code...
(_getopt_initialize): ...here. Don't set d->__posixly_correct.

8 years agogetopt: merge from glibc: repetition reduction
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: merge from glibc: repetition reduction

The definitions of the entry point functions 'getopt' and
'__posix_getopt' can be made substantially less repetitive with a
helper macro.

While I was merging the const-correctness changes from gnulib into
glibc I noticed there are still some unnecessary casts in
_getopt_internal_r.

* lib/getopt.c (getopt, __posix_getopt): Eliminate repetition with
a macro.  Consistently cast 'argv' to 'char **' when calling
_getopt_internal.
(_getopt_internal_r): Remove unnecessary casts when calling exchange.

8 years agogetopt: clean up error reporting
Zack Weinberg [Thu, 6 Apr 2017 18:14:14 +0000 (11:14 -0700)]
getopt: clean up error reporting

getopt can print a whole bunch of error messages, and when used
standalone (from gnulib) it uses fprintf to do that.  But fprintf is a
cancellation point and getopt isn't, and also applying fprintf to a
stream in wide-character mode is not allowed.  So every single error
reporting case has an #ifdef _LIBC block in which it calls internal
libc functions instead.  The counterpart patch series in glibc makes
it possible to simplify all of that down to a set of #defines at the
top of the file; core code is written as if it is safe to just call
fprintf, flockfile, and funlockfile.  (One caveat: it's *not* safe to
call any *other* stdio functions.)

* lib/getopt.c: When _LIBC is defined, define fprintf to
__fxprintf_nocancel, flockfile to _IO_flockfile, and funlockfile
to _IO_funlockfile.  When neither _LIBC nor
_POSIX_THREAD_SAFE_FUNCTIONS is defined, define flockfile and
funlockfile as no-ops.
(_getopt_internal_r): Remove all internal #ifdef _LIBC blocks; the
standalone error-printing code can now be used for libc as well.
Add an flockfile/funlockfile pair around one case where the error
message is printed in several chunks.  Don't use fputc.

8 years agogetopt: fix fencepost error in ambiguous-W-option handling
Zack Weinberg [Thu, 6 Apr 2017 18:14:13 +0000 (11:14 -0700)]
getopt: fix fencepost error in ambiguous-W-option handling

getopt_long contains an undocumented (AFAICT) feature in which, if you
put "W;" in the short-options list, then '-W foo' and '-Wfoo' are
treated as equivalent to '--foo'.  This is implemented with a partial
second copy of the code for handling long options, and that code
increments optind one too many times when recovering from an ambiguous
abbreviated option, which can cause the main loop to walk past the end
of argv and crash.

I discovered this while writing a test case that tries to exercise all
of getopt's error reporting paths; I wouldn't be surprised to learn
that this feature is never used by real applications.

* lib/getopt.c (_getopt_internal_r): Don't increment
d->optind a second time when reporting ambiguous -W options.

8 years agogetopt: clean up getopt.c and getopt1.c file headers
Zack Weinberg [Thu, 6 Apr 2017 18:14:13 +0000 (11:14 -0700)]
getopt: clean up getopt.c and getopt1.c file headers

In getopt.c, there is no need to include wchar.h at all, and it is
safe nowadays to assume that stdlib.h does declare getenv (several
other gnulib modules make this assumption).

In getopt1.c, the #ifdef _LIBC block at the top can be simplified
by using "" inclusions consistently, and there is no actual need to
include stdlib.h (except in the #ifdef TEST block, where it should be
unconditional), nor to provide a backup definition of NULL at all.

* lib/getopt1.c: Simplify #ifdeffage at top of file.
Move inclusion of stdlib.h to #ifdef TEST block and make
unconditional.  Do not define NULL.
* lib/getopt.c: Don't include wchar.h. No need to declare getenv.
* m4/getopt.m4 (gl_PREREQ_GETENV): Delete.
* modules/getopt-gnu, modules/getopt-posix: Don't call
gl_PREREQ_GETENV.