[PATCH] Improve sc_useless_cpp_parens

2017-04-29 Thread Tim Rühsen
Hi,

just found that sc_useless_cpp_parens doesn't catch #elif and doesn't catch
tabulator indentation (which I use here and there).

I attached a def.txt where the patched versions detects each line, the
original one misses a few.

Please feel free to amend the commit message regarding your preferences.

Regards, Tim
From 7be20f912b443031bf6a92d26e1fcff40189b0a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim Rühsen?= 
Date: Sat, 29 Apr 2017 22:50:50 +0200
Subject: [PATCH] * top/maint.mk: Improve sc_useless_cpp_parens

Also find useles parens in #elif and even when
tabs are used instead of spaces for indentation (before
and after #).
---
 top/maint.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/top/maint.mk b/top/maint.mk
index 0cabd2f31..356c66c82 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -775,7 +775,7 @@ sc_unmarked_diagnostics:
 # Avoid useless parentheses like those in this example:
 # #if defined (SYMBOL) || defined (SYM2)
 sc_useless_cpp_parens:
-	@prohibit='^# *if .*defined *\('\
+	@prohibit='^[ $(printf "\t")]*#[ $(printf "\t")]*(if|elif) .*defined *\(' \
 	halt='found useless parentheses in cpp directive'		\
 	  $(_sc_search_regexp)

--
2.11.0

#if defined(bla)
#elif defined(blu)
# if defined(bla)
# elif defined(blu)
#  if defined(bla)
#  elif defined(blu)
#   if defined(bla)
#   elif defined(blu)
  #if defined(bla)
  #elif defined(blu)
#if defined(bla)
#elif defined(blu)
#   if defined(bla)
#   elif defined(blu)


signature.asc
Description: This is a digitally signed message part.


Re: strerror_r breakage on mingw

2017-04-29 Thread Bruno Haible
> 2017-04-23  Bruno Haible  
> 
>   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.

Oops, there was a mistake in this patch. Fixing it as follows:


2017-04-29  Bruno Haible  

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 *'.

--- a/lib/error.c
+++ b/lib/error.c
@@ -174,7 +174,7 @@ print_errno_message (int errnum)
 
 #if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R
   char errbuf[1024];
-# if _LIBC || GNULIB_STRERROR_R_POSIX || STRERROR_R_CHAR_P
+# if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P)
   s = __strerror_r (errnum, errbuf, sizeof errbuf);
 # else
   if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)




stat: fix time_t values and other problems on native Windows

2017-04-29 Thread Bruno Haible
2017-04-29  Bruno Haible  

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.

diff --git a/doc/posix-functions/stat.texi b/doc/posix-functions/stat.texi
index 33af95d..c30e7e1 100644
--- a/doc/posix-functions/stat.texi
+++ b/doc/posix-functions/stat.texi
@@ -13,6 +13,15 @@ On platforms where @code{off_t} is a 32-bit type, 
@code{stat} may not correctly
 report the size of files or block devices larger than 2 GB.
 (Cf. @code{AC_SYS_LARGEFILE}.)
 @item
+The @code{st_atime}, @code{st_ctime}, @code{st_mtime} field are affected by
+the current time zone and by the DST flag of the current time zone on some
+platforms:
+mingw, MSVC 14 (when the environment variable @code{TZ} is set).
+@item
+On MSVC 14, this function fails with error @code{ENOENT}
+on files such as @samp{C:\pagefile.sys} and
+on directories such as @samp{C:\System Volume Information}.
+@item
 On some platforms, @code{stat("link-to-file/",buf)} succeeds instead
 of failing with @code{ENOTDIR}.
 FreeBSD 7.2, AIX 7.1, Solaris 9, mingw64.
diff --git a/lib/stat.c b/lib/stat.c
index 7e7c2f6..1954449 100644
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program.  If not, see .  */
 
-/* written by Eric Blake */
+/* Written by Eric Blake and Bruno Haible.  */
 
 /* If the user's config.h happens to include , let it include only
the system's  here, so that orig_stat doesn't recurse to
@@ -28,6 +28,7 @@
 #undef __need_system_sys_stat_h
 
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WINDOWS_NATIVE
 # if _GL_WINDOWS_64_BIT_ST_SIZE
 #  undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
 #  define stat _stati64
@@ -42,12 +43,16 @@
 # endif
 #endif
 
+#if !defined WINDOWS_NATIVE
+
 static int
 orig_stat (const char *filename, struct stat *buf)
 {
   return stat (filename, buf);
 }
 
+#endif
+
 /* Specification.  */
 /* Write "sys/stat.h" here, not , otherwise OSF/1 5.1 DTK cc
eliminates this include because of the preliminary #include 
@@ -58,9 +63,16 @@ orig_stat (const char *filename, struct stat *buf)
 #include 
 #include 
 #include 
-#include "dosname.h"
+#include "filename.h"
+#include "malloca.h"
 #include "verify.h"
 
+#ifdef WINDOWS_NATIVE
+# define WIN32_LEAN_AND_MEAN
+# include 
+# include "stat-w32.h"
+#endif
+
 #if REPLACE_FUNC_STAT_DIR
 # include "pathmax.h"
   /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
@@ -70,6 +82,34 @@ orig_stat (const char *filename, struct stat *buf)
 # endif
 #endif
 
+#ifdef WINDOWS_NATIVE
+/* Return TRUE if the given file name denotes an UNC root.  */
+static BOOL
+is_unc_root (const char *rname)
+{
+  /* Test whether it has the syntax '\\server\share'.  */
+  if (ISSLASH (rname[0]) && ISSLASH (rname[1]))
+{
+  /* It starts with two slashes.  Find the next slash.  */
+  const char *p = rname + 2;
+  const char *q = p;
+  while (*q != '\0' && !ISSLASH (*q))
+q++;
+  if (q > p && *q != '\0')
+{
+  /* Found the next slash at q.  */
+  q++;
+  const char *r = q;
+  while (*r != '\0' && !ISSLASH (*r))
+r++;
+  if (r > q && *r == '\0')
+return TRUE;
+}
+}
+  return FALSE;
+}
+#endif
+
 /* Store information about NAME into ST.  Work around bugs with
trailing slashes.  Mingw has other bugs (such as st_ino always
being 0 on success) which this wrapper does not work around.  But
@@ -77,62 +117,296 @@ orig_stat (const char *filename, struct stat *buf)
correctly.  */
 
 int
-rpl_stat (char const *name, struct stat *st)
+rpl_stat (char const *name, struct stat *buf)
 {
-  int result = orig_stat (name, st);
-#if REPLACE_FUNC_STAT_FILE
-  /* Solaris 9 mistakenly succeeds when given a non-directory with a
- trailing slash.  */
-  if (result == 0 && !S_ISDIR (st->st_mode))
+#ifdef WINDOWS_NATIVE
+  /* Fill the fields ourselves, because the original stat function returns
+ values for st_atime, st_mtime, st_ctime that depend on the current time
+ zone.  See
+   */
+  /* XXX Should we convert to

fstat: fix time_t values on native Windows

2017-04-29 Thread Bruno Haible
Per the discussion in the thread of
.


2017-04-29  Bruno Haible  

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.

diff --git a/doc/posix-functions/fstat.texi b/doc/posix-functions/fstat.texi
index 0f5b860..cb662fc 100644
--- a/doc/posix-functions/fstat.texi
+++ b/doc/posix-functions/fstat.texi
@@ -15,6 +15,11 @@ MSVC 9.
 On platforms where @code{off_t} is a 32-bit type, @code{fstat} may not 
correctly
 report the size of files or block devices larger than 2 GB.
 (Cf. @code{AC_SYS_LARGEFILE}.)
+@item
+The @code{st_atime}, @code{st_ctime}, @code{st_mtime} field are affected by
+the current time zone and by the DST flag of the current time zone on some
+platforms:
+mingw, MSVC 14 (when the environment variable @code{TZ} is set).
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/fstat.c b/lib/fstat.c
index a5aabc5..a4896e3 100644
--- a/lib/fstat.c
+++ b/lib/fstat.c
@@ -23,20 +23,28 @@
 /* Get the original definition of fstat.  It might be defined as a macro.  */
 #include 
 #include 
-#if _GL_WINDOWS_64_BIT_ST_SIZE
-# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
-# define stat _stati64
-# undef fstat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
-# define fstat _fstati64
-#endif
 #undef __need_system_sys_stat_h
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WINDOWS_NATIVE
+# if _GL_WINDOWS_64_BIT_ST_SIZE
+#  undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
+#  define stat _stati64
+#  undef fstat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
+#  define fstat _fstati64
+# endif
+#endif
+
+#if !defined WINDOWS_NATIVE
+
 static int
 orig_fstat (int fd, struct stat *buf)
 {
   return fstat (fd, buf);
 }
 
+#endif
+
 /* Specification.  */
 /* Write "sys/stat.h" here, not , otherwise OSF/1 5.1 DTK cc
eliminates this include because of the preliminary #include 
@@ -45,32 +53,11 @@ orig_fstat (int fd, struct stat *buf)
 
 #include 
 #include 
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-# include "msvc-inval.h"
-#endif
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-fstat_nothrow (int fd, struct stat *buf)
-{
-  int result;
-
-  TRY_MSVC_INVAL
-{
-  result = orig_fstat (fd, buf);
-}
-  CATCH_MSVC_INVAL
-{
-  result = -1;
-  errno = EBADF;
-}
-  DONE_MSVC_INVAL;
-
-  return result;
-}
-#else
-# define fstat_nothrow orig_fstat
+#ifdef WINDOWS_NATIVE
+# define WIN32_LEAN_AND_MEAN
+# include 
+# include "msvc-nothrow.h"
+# include "stat-w32.h"
 #endif
 
 int
@@ -84,5 +71,20 @@ rpl_fstat (int fd, struct stat *buf)
 return stat (name, buf);
 #endif
 
-  return fstat_nothrow (fd, buf);
+#ifdef WINDOWS_NATIVE
+  /* Fill the fields ourselves, because the original fstat function returns
+ values for st_atime, st_mtime, st_ctime that depend on the current time
+ zone.  See
+   */
+  HANDLE h = (HANDLE) _get_osfhandle (fd);
+
+  if (h == INVALID_HANDLE_VALUE)
+{
+  errno = EBADF;
+  return -1;
+}
+  return _gl_fstat_by_handle (h, NULL, buf);
+#else
+  return orig_fstat (fd, buf);
+#endif
 }
diff --git a/lib/stat-w32.c b/lib/stat-w32.c
new file mode 100644
index 000..4f4a105
--- /dev/null
+++ b/lib/stat-w32.c
@@ -0,0 +1,293 @@
+/* Core of implementation of fstat and stat for native Windows.
+   Copyright (C) 2017 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see .  */
+
+/* Written by Bruno Haible.  */
+
+#include 
+
+#include 
+#include 
+#if (defined _WIN32 || defined __WIN32__

Re: what shall we do with the drunken time_t ?

2017-04-29 Thread Bruno Haible
I had written:
>  Results ===
> (I am in CEST, i.e. GMT+1 with DST since end of March.)
> 
> A file last touched on 2016-11-27 18:32 GMT:
> $ ls -l t.tar
> -rw-r--r-- 1 bruno None 10240 Nov 27 19:32 t.tar
> 
> Cygwin:
> mtime = 17132 18 1920
> as GMT: Sun Nov 27 18:32:00 2016 (correct)
> as localtime: Sun Nov 27 19:32:00 2016   (correct)
> 
> msvc:
> mtime = 17132 19 1920
> as GMT: Sun Nov 27 19:32:00 2016 (off by 1 h)
> as localtime: Sun Nov 27 19:32:00 2016   (correct)
> 
> mingw:
> mtime = 17132 20 1920
> as GMT: Sun Nov 27 20:32:00 2016 (off by 2 h)
> as localtime: Sun Nov 27 20:32:00 2016   (off by 1 h)
> 
> A file last touched on 2017-04-05 01:49 GMT:
> $ ls -l n.txt
> -rw-r--r-- 1 bruno None 93 Apr  5 03:49 n.txt
> 
> Cygwin:
> mtime = 17261 1 2961
> as GMT: Wed Apr  5 01:49:21 2017 (correct)
> as localtime: Wed Apr  5 03:49:21 2017   (correct)
> 
> msvc:
> mtime = 17261 2 2961
> as GMT: Wed Apr  5 02:49:21 2017 (off by 1 h)
> as localtime: Wed Apr  5 03:49:21 2017   (correct)
> 
> mingw:
> mtime = 17261 2 2961
> as GMT: Wed Apr 05 02:49:21 2017 (off by 1 h)
> as localtime: Wed Apr 05 03:49:21 2017   (correct)

Part of the confusion came from the facts that
  - I'm using Cygwin as development environment,
  - Cygwin defines the environment variable TZ, with value "Europe/Berlin"
in my case [1],
  - the Microsoft CRT interprets TZ, but with a different expected syntax 
[2][3],
which led to tzname[0] = "Eur", tzname[1] = "ope".

The problem is that an absent or empty TZ value means "GMT" for Cygwin,
whereas it means the timezone from the Windows Control Panel in native Windows.
There have been proposals that Cygwin should unset TZ when it invokes a native
Windows program [4][5], but it has not been implemented so far.

Here are updated results (the msvc and mingw programs run with empty TZ):
===

With DST:
$ ls -l n.txt
-rw-r--r-- 1 bruno None 93 Apr  5 03:49 n.txt

Cygwin:
File n.txt mtime = 17261 1 2961   (correct)
  as GMT: Wed Apr  5 01:49:21 2017(correct)
  as localtime: Wed Apr  5 03:49:21 2017  (correct)

msvc with empty TZ:
File n.txt mtime = 17261 1 2961   (correct)
  as GMT: Wed Apr  5 01:49:21 2017(correct)
  as localtime: Wed Apr  5 03:49:21 2017  (correct)
msvc with Cygwin's TZ:
File n.txt mtime = 17261 2 2961   (off by 1 h)
  as GMT: Wed Apr  5 02:49:21 2017(off by 1 h)
  as localtime: Wed Apr  5 03:49:21 2017  (correct)

mingw with empty TZ:
File n.txt mtime = 17261 1 2961   (correct)
  as GMT: Wed Apr 05 01:49:21 2017(correct)
  as localtime: Wed Apr 05 03:49:21 2017  (correct)
mingw with Cygwin's TZ:
File n.txt mtime = 17261 2 2961   (off by 1 h)
  as GMT: Wed Apr 05 02:49:21 2017(off by 1 h)
  as localtime: Wed Apr 05 03:49:21 2017  (correct)

Without DST:
$ ls -l t.tar
-rw-r--r-- 1 bruno None 10240 Nov 27 19:32 t.tar

Cygwin:
File t.tar mtime = 17132 18 1920  (correct)
  as GMT: Sun Nov 27 18:32:00 2016(correct)
  as localtime: Sun Nov 27 19:32:00 2016  (correct)

msvc with empty TZ:
File t.tar mtime = 17132 18 1920  (correct)
  as GMT: Sun Nov 27 18:32:00 2016(correct)
  as localtime: Sun Nov 27 19:32:00 2016  (correct)
msvc with Cygwin's TZ:
File t.tar mtime = 17132 19 1920  (off by 1 h)
  as GMT: Sun Nov 27 19:32:00 2016(off by 1 h)
  as localtime: Sun Nov 27 19:32:00 2016  (correct)

mingw with empty TZ:
File t.tar mtime = 17132 19 1920  (off by 1 h)
  as GMT: Sun Nov 27 19:32:00 2016(off by 1 h)
  as localtime: Sun Nov 27 20:32:00 2016  (off by 1 h)
mingw with Cygwin's TZ:
File t.tar mtime = 17132 20 1920  (off by 2 h)
  as GMT: Sun Nov 27 20:32:00 2016(off by 2 h)
  as localtime: Sun Nov 27 20:32:00 2016  (off by 1 h)

===

I'm still going to override stat() and fstat(), because
  - There are the unlucky Cygwin users like me.
  - Doing time zone sensitive computations for time_t is madness, and leads
to the Notepad++ notifications when the user changes the time zone.
  - These rewrites of stat() and fstat() are the basis for future enhancements
(struct timeval instead of time_t -> higher timestamp precisions,
dev_t and ino_t, and symbolic links).

Bruno

[1] 
https://stackoverflow.com/questions/40350812/cygwin-shows-utc-time-instead-of-local-time
[2] https://msdn.microsoft.com/en-us/library/aa273389.aspx
[3] https://msdn.microsoft.com/en-us/library/90s5c885.aspx
[4] https://cygwin.com/ml/cygwin/2012-03/msg00048.html
[5] https://cygwin.com/ml/cygwin-patches/2012-q2/msg7.html




Re: getopt _getopt_internal declaration clash on Solaris 5.10

2017-04-29 Thread Paul Eggert
Thanks for the heads-up. I installed the attached Gnulib patch, which I hope fix 
things. Please give it a try.
From f3f95f863f63eec80bfe4228719fb0afada5fa05 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Sat, 29 Apr 2017 11:09:39 -0700
Subject: [PATCH] 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.
---
 ChangeLog| 8 
 lib/getopt-pfx-ext.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index d641fb7..5640abe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2017-04-29  Paul Eggert  
+
+	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.
+
 2017-04-29  Bruno Haible  
 
 	strerror_r-posix: Fixes for MSVC 14.
diff --git a/lib/getopt-pfx-ext.h b/lib/getopt-pfx-ext.h
index 2f86b23..d960bb3 100644
--- a/lib/getopt-pfx-ext.h
+++ b/lib/getopt-pfx-ext.h
@@ -40,9 +40,11 @@
 # undef getopt_long
 # undef getopt_long_only
 # undef option
+# undef _getopt_internal
 # define getopt_long __GETOPT_ID (getopt_long)
 # define getopt_long_only __GETOPT_ID (getopt_long_only)
 # define option __GETOPT_ID (option)
+# define _getopt_internal __GETOPT_ID (getopt_internal)
 #endif
 
 /* Standalone applications get correct prototypes for getopt_long and
-- 
2.7.4



getopt _getopt_internal declaration clash on Solaris 5.10

2017-04-29 Thread Gavin Smith
On Sun, Apr 23, 2017 at 08:20:20PM -0400, Assaf Gordon wrote:
> ---
> 
> On Solaris 5.10, compilation fails due to a conflict in gnulib's getopt 
> module.
> See full build log here: 
>  https://pretest.housegordon.org/g/4602/logs/make.log?inlined=1
> (search for "getopt_int" to find the error).
> Snippet below:
> ===
> gcc -DHAVE_CONFIG_H -I. -I../..-D_REENTRANT  -g -O2 -MT getopt.o -MD -MP 
> -MF $depbase.Tpo -c -o getopt.o getopt.c &&\
> mv -f $depbase.Tpo $depbase.Po
> In file included from getopt.c:80:0:
> getopt_int.h:25:12: error: conflicting types for '_getopt_internal'
>  extern int _getopt_internal (int ___argc, char **___argv,
> ^
> In file included from ./getopt.h:34:0,
>  from getopt.h:34,
>  from getopt.c:24:
> /opt/csw/include/getopt.h:118:12: note: previous declaration of 
> '_getopt_internal' was here
>  extern int _getopt_internal (int argc, char *const *argv,
> ^
> getopt.c:702:1: error: conflicting types for '_getopt_internal'
>  _getopt_internal (int argc, char **argv, const char *optstring,
>  ^
> In file included from ./getopt.h:34:0,
>  from getopt.h:34,
>  from getopt.c:24:
> /opt/csw/include/getopt.h:118:12: note: previous declaration of 
> '_getopt_internal' was here
>  extern int _getopt_internal (int argc, char *const *argv,
> ^
> *** Error code 1
> make: Fatal error: Command failed for target `getopt.o'

On a Solaris 5.10 system I have access to, /opt/csw/include/getopt.h
is a GNU libc include file from 1997. It is probably the same file that
you are using, as the declaration is on the same line (118).

I know it is possible to compile on this system with the right 
environment because it's done successfully on the OpenCSW buildfarm.  
(See https://buildfarm.opencsw.org/buildbot/waterfall?category=texinfo
for logs).

I tried compiling Texinfo 6.3 the same way and didn't get the same 
error, so it is probably due to a change in Gnulib.

I found in the older gnulib, the _getopt_internal had been redefined
as rpl_getopt_internal after the system header had been read, so the
definition clash did not occur.

I'm copying bug-gnulib into this email to see if the Gnulib developers 
can take this any further.

I believe the section that #define's the function names is now in
getopt-pfx-ext.h. _getopt_internal is not redefined there. Formerly,
I believe it was in getopt.h that _getopt_internal was redefined,
like this:

# define _getopt_internal __GETOPT_ID (getopt_internal)




strerror_r-posix: fixes for MSVC 14

2017-04-29 Thread Bruno Haible
This patch fixes two problems with MSVC 14 support in module 'strerror_r-posix':

1) The function local_snprintf uses va_list, va_start, va_end, without including
the required header .

2) Test failures of strerror_r-posix and perror, reported in
https://lists.gnu.org/archive/html/bug-gnulib/2016-12/msg00112.html
The cause is that MSVC's  now defines ETIMEDOUT and other errno
values in the range 100..140, but without adding them to the _sys_errlist
array. _sys_nerr still is = 43.


2017-04-29  Bruno Haible  

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

diff --git a/doc/posix-functions/strerror_r.texi 
b/doc/posix-functions/strerror_r.texi
index 06fdfd2..8554a29 100644
--- a/doc/posix-functions/strerror_r.texi
+++ b/doc/posix-functions/strerror_r.texi
@@ -39,6 +39,10 @@ glibc 2.12 with @code{-D_POSIX_C_SOURCE=200112L}, AIX 6.1, 
OSF/1 5.1.
 When this function fails, it corrupts @code{errno}, on some platforms:
 Solaris 10.
 @item
+This function does not support many error values defined in @code{} on
+some platforms:
+MSVC 14.
+@item
 This function does not support the error values that are specified by POSIX
 but not defined by the system, on some platforms:
 OpenBSD 4.0, OSF/1 5.1, NonStop Kernel, Cygwin 1.5.x.
diff --git a/lib/strerror_r.c b/lib/strerror_r.c
index d7b0f77..650751f 100644
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -28,6 +28,9 @@
 #include 
 #include 
 #include 
+#if !HAVE_SNPRINTF
+# include 
+#endif
 
 #include "strerror-override.h"
 
@@ -329,6 +332,115 @@ strerror_r (int errnum, char *buf, size_t buflen)
 
 #endif
 
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+/* MSVC 14 defines names for many error codes in the range 100..140,
+   but _sys_errlist contains strings only for the error codes
+   < _sys_nerr = 43.  */
+if (ret == EINVAL)
+  {
+const char *errmsg;
+
+switch (errnum)
+  {
+  case 100 /* EADDRINUSE */:
+errmsg = "Address already in use";
+break;
+  case 101 /* EADDRNOTAVAIL */:
+errmsg = "Cannot assign requested address";
+break;
+  case 102 /* EAFNOSUPPORT */:
+errmsg = "Address family not supported by protocol";
+break;
+  case 103 /* EALREADY */:
+errmsg = "Operation already in progress";
+break;
+  case 105 /* ECANCELED */:
+errmsg = "Operation canceled";
+break;
+  case 106 /* ECONNABORTED */:
+errmsg = "Software caused connection abort";
+break;
+  case 107 /* ECONNREFUSED */:
+errmsg = "Connection refused";
+break;
+  case 108 /* ECONNRESET */:
+errmsg = "Connection reset by peer";
+break;
+  case 109 /* EDESTADDRREQ */:
+errmsg = "Destination address required";
+break;
+  case 110 /* EHOSTUNREACH */:
+errmsg = "No route to host";
+break;
+  case 112 /* EINPROGRESS */:
+errmsg = "Operation now in progress";
+break;
+  case 113 /* EISCONN */:
+errmsg = "Transport endpoint is already connected";
+break;
+  case 114 /* ELOOP */:
+errmsg = "Too many levels of symbolic links";
+break;
+  case 115 /* EMSGSIZE */:
+errmsg = "Message too long";
+break;
+  case 116 /* ENETDOWN */:
+errmsg = "Network is down";
+break;
+  case 117 /* ENETRESET */:
+errmsg = "Network dropped connection on reset";
+break;
+  case 118 /* ENETUNREACH */:
+errmsg = "Network is unreachable";
+break;
+  case 119 /* ENOBUFS */:
+errmsg = "No buffer space available";
+break;
+  case 123 /* ENOPROTOOPT */:
+errmsg = "Protocol not available";
+break;
+  case 126 /* ENOTCONN */:
+errmsg = "Transport endpoint is not connected";
+break;
+  case 128 /* ENOTSOCK */:
+errmsg = "Socket operation on non-socket";
+break;
+  case 129 /* ENOTSUP */:
+errmsg = "Not supported";
+break;
+  case 130 /* EOPNOTSUPP */:
+errmsg = "Operation not supported";
+break;
+  case 132 /* EOVERFLOW */:
+errmsg = "Value too large for defined data type";
+break;
+  case 133 /* EOWNERDEAD */:
+errmsg = "Owner died";
+break;
+  case 134 /* EPROTO */:
+errmsg = "Protocol error";
+break;
+  case 135 /* EPROTONOSUPPORT */:
+errmsg = "Protocol not sup

Re: new module 'noreturn'

2017-04-29 Thread Bruno Haible
Paul Eggert wrote:
> It was more like this:
> 
>#define _GL_NORETURN_FUNC_Noreturn __attribute_noreturn__
>#define _GL_NORETURN_FUNCPTR __attribute_noreturn__

Per [1] (compare fptr33 and fptr34), this has identical effects as

   #define _GL_NORETURN_FUNC__attribute_noreturn__
   #define _GL_NORETURN_FUNCPTR __attribute_noreturn__

In other words, when __attribute__ ((__noreturn__)) works, there is
no point in even looking whether _Noreturn works as well.

> Perhaps your draft has an identical effect to this

Yes, it what I pushed has identical effects.

Bruno

[1] https://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00152.html




Re: Gnulib's wctype.h fails to compile with MinGW

2017-04-29 Thread Gavin Smith
On Thu, Apr 27, 2017 at 08:50:25PM +0300, Eli Zaretskii wrote:
> > From: Bruno Haible 
> > Date: Thu, 27 Apr 2017 19:03:35 +0200
> > 
> > Thanks for the report and suggested fix.
> > 
> > The #ifdefology here seems a bit fragile to me (will likely break in other
> > forks of mingw), therefore I'm using an Autoconf test instead:
> 
> I only know of 2 flavors of MinGW (and wish there were only one), but
> of course an Autoconf test is even better.  Thanks.
> 
> Gavin, could this be part of the next pretest, please?

Yes, I will make sure the Gnulib files have been updated.