ioctl on mingw

2010-04-04 Thread Bruno Haible
Similarly, I get this error on mingw in C++ mode:

  ../gllib/sys/ioctl.h:318: error: `ioctl' was not declared in this scope

and, once this is fixed:

  g++-3 -mno-cygwin-L/usr/local/mingw/lib -o test-sys_ioctl-c++.exe 
test-sys_ioctl-c++.o ../gllib/libgnu.a
  ../gllib/libgnu.a(ioctl.o): In function `ioctl':
  /home/bruno/testdir3/gllib/ioctl.c:65: undefined reference to 
`_ioctlsoc...@12'
  ../gllib/libgnu.a(ioctl.o): In function `ioctl':
  /home/bruno/testdir3/gllib/w32sock.h:34: undefined reference to 
`_wsagetlaster...@0'

Here I'm solving the first problem. The second one is common to all sockets
functions:
  - Why don't have modules 'accept' ... 'shutdown' not have a
Link: $(LIBSOCKET) section?
  - Why don't the functions 'accept' ... 'shutdown' initialize the ws2_32
library upon first use?


2010-04-04  Bruno Haible  br...@clisp.org

ioctl: Fix C++ test error on mingw.
* lib/ioctl.c (ioctl): Renamed from rpl_ioctl.
* lib/sys_ioctl.in.h (ioctl): When SYS_IOCTL_H_HAVE_WINSOCK2_H is 1,
use _GL_FUNCDECL_SYS, not _GL_FUNCDECL_RPL.

--- lib/ioctl.c.origSun Apr  4 03:09:17 2010
+++ lib/ioctl.c Sun Apr  4 02:45:30 2010
@@ -50,7 +50,7 @@
 # include w32sock.h
 
 int
-rpl_ioctl (int fd, int req, ...)
+ioctl (int fd, int req, ...)
 {
   void *buf;
   va_list args;
--- lib/sys_ioctl.in.h.orig Sun Apr  4 03:09:17 2010
+++ lib/sys_ioctl.in.h  Sun Apr  4 02:49:51 2010
@@ -44,7 +44,7 @@
 /* Declare overridden functions.  */
 
 #if @GNULIB_IOCTL@
-# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || @REPLACE_IOCTL@
+# if @REPLACE_IOCTL@
 #  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
 #   undef ioctl
 #   define ioctl rpl_ioctl
@@ -54,8 +54,10 @@
 _GL_CXXALIAS_RPL (ioctl, int,
   (int fd, int request, ... /* {void *,char *} arg */));
 # else
+#  if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || 1
 _GL_FUNCDECL_SYS (ioctl, int,
   (int fd, int request, ... /* {void *,char *} arg */));
+#  endif
 _GL_CXXALIAS_SYS (ioctl, int,
   (int fd, int request, ... /* {void *,char *} arg */));
 # endif




measuring elapsed time on mingw

2010-04-04 Thread Bruno Haible
Hi,

Just a side note about how to measure elapsed time on mingw.
(I needed this in order to evaluate how to implement nanosleep on mingw.)

Summary:
  - GetSystemTimeAsFileTime, _ftime, gettimeofday (from newer mingw runtimes)
all have about 15.6 ms resolution.
  - QueryPerformanceCounter [1] has a resolution of 0.5 ms or higher.

There is an explanation how to implement the equivalent of gettimeofday with
a combination of GetSystemTimeAsFileTime and QueryPerformanceCounter [2],
but it appears quite complex, and overkill for gnulib.

As witness, here's a test program that busy-loops for a certain time and
then outputs the time difference, measured according to different system calls:

 gettime-res.c 
#include sys/time.h
#include sys/timeb.h
#include stdio.h
#include stdlib.h
#include windows.h

int main (int argc, char *argv[])
{
  int count = atoi(argv[1]);
  FILETIME ft_before, ft_after;
  struct _timeb tb_before, tb_after;
  struct timeval tv_before, tv_after;
  LARGE_INTEGER pcfreq;
  LARGE_INTEGER pc_before, pc_after;
  int i, j;

  if (!QueryPerformanceFrequency (pcfreq))
printf (QueryPerformanceFrequency failed\n);

  GetSystemTimeAsFileTime (ft_before);
  _ftime (tb_before);
  gettimeofday (tv_before, NULL);
  if (!QueryPerformanceCounter (pc_before))
printf (QueryPerformanceCounter failed\n);


  for (i = 0; i  count; i++)
for (j = 0; j  1; j++)
  ;

  GetSystemTimeAsFileTime (ft_after);
  _ftime (tb_after);
  gettimeofday (tv_after, NULL);
  if (!QueryPerformanceCounter (pc_after))
printf (QueryPerformanceCounter failed\n);

  printf (GetSystemTimeAsFileTime %ld *0.1us\n
  _ftime %ld ms\n
  gettimeofday %ld us\n
  QueryPerformanceCounter %ld (freq %ld) = %g s\n,
  (ft_after.dwHighDateTime - ft_before.dwHighDateTime) * 0x1 + 
ft_after.dwLowDateTime - ft_before.dwLowDateTime,
  (tb_after.time - tb_before.time) * 1000 + tb_after.millitm - 
tb_before.millitm,
  (tv_after.tv_sec - tv_before.tv_sec) * 100 + tv_after.tv_usec - 
tv_before.tv_usec,
  (long) (pc_after.QuadPart - pc_before.QuadPart), (long) 
pcfreq.QuadPart, (double)(pc_after.QuadPart - pc_before.QuadPart) / (double) 
pcfreq.QuadPart);
  return 0;
}
===

And its results on Windows XP:

$ ./gettime-res 100  
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 16 ms
gettimeofday 15625 us
QueryPerformanceCounter 18631 (freq 3579545) = 0.00520485 s

$ ./gettime-res 200
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 16 ms
gettimeofday 15625 us
QueryPerformanceCounter 36574 (freq 3579545) = 0.0102175 s

$ ./gettime-res 300
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 15 ms
gettimeofday 15625 us
QueryPerformanceCounter 54852 (freq 3579545) = 0.0153237 s

$ ./gettime-res 400
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 16 ms
gettimeofday 15625 us
QueryPerformanceCounter 72040 (freq 3579545) = 0.0201255 s

$ ./gettime-res 400
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 16 ms
gettimeofday 15625 us
QueryPerformanceCounter 72194 (freq 3579545) = 0.0201685 s

$ ./gettime-res 400
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 15 ms
gettimeofday 15625 us
QueryPerformanceCounter 72201 (freq 3579545) = 0.0201704 s

$ ./gettime-res 400
GetSystemTimeAsFileTime 156250 *0.1us
_ftime 16 ms
gettimeofday 15625 us
QueryPerformanceCounter 73738 (freq 3579545) = 0.0205998 s

$ ./gettime-res 500
GetSystemTimeAsFileTime 312500 *0.1us
_ftime 31 ms
gettimeofday 31250 us
QueryPerformanceCounter 90478 (freq 3579545) = 0.0252764 s

$ ./gettime-res 500
GetSystemTimeAsFileTime 312500 *0.1us
_ftime 31 ms
gettimeofday 31250 us
QueryPerformanceCounter 91936 (freq 3579545) = 0.0256837 s

Bruno


[1] http://msdn.microsoft.com/en-us/library/ms644904(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/magazine/cc163996.aspx




Re: nanosleep on mingw

2010-04-04 Thread Bruno Haible
The current implementation of nanosleep is broken on mingw for several reasons:

1) It requires linking with -lws2_32, as evidenced by these error messages:

   gcc-3 -mno-cygwin  -g -O2  -L/usr/local/mingw/lib -o test-nanosleep.exe 
test-nanosleep.o ../gllib/libgnu.a  
   ../gllib/libgnu.a(select.o): In function `rpl_select':
   /home/bruno/testdir2/gllib/select.c:93: undefined reference to 
`_wsaenumnetworkeve...@12'
   /home/bruno/testdir2/gllib/select.c:360: undefined reference to 
`_wsaeventsel...@12'
   /home/bruno/testdir2/gllib/select.c:381: undefined reference to `_sel...@20'
   /home/bruno/testdir2/gllib/select.c:434: undefined reference to 
`_wsaeventsel...@12'
   /home/bruno/testdir2/gllib/select.c:435: undefined reference to 
`___wsafdis...@8'
   /home/bruno/testdir2/gllib/select.c:437: undefined reference to 
`___wsafdis...@8'
   /home/bruno/testdir2/gllib/select.c:439: undefined reference to 
`___wsafdis...@8'
   /home/bruno/testdir2/gllib/select.c:414: undefined reference to `_sel...@20'
   collect2: ld returned 1 exit status
   make[4]: *** [test-nanosleep.exe] Error 1

   But there is no good reason to link with a sockets library just to sleep a
   certain amount of time.

2) Use of this the 'select' function in wsock2 requires a prior invocation
   of WSAStartup() (contained in the 'sockets' module).

   Witness: This program
===
#include winsock2.h
#include sys/time.h
#include stdlib.h
#include stdio.h
#include windows.h

int main (int argc, char *argv[])
{
  int usecs = atoi (argv[1]);
  LARGE_INTEGER pcfreq;
  LARGE_INTEGER before, after;
  struct timeval timeout;
  int ret;

  if (!QueryPerformanceFrequency (pcfreq))
printf (QueryPerformanceFrequency failed\n);

  if (!QueryPerformanceCounter (before))
printf (QueryPerformanceCounter failed\n);

  timeout.tv_sec = usecs / 100;
  timeout.tv_usec = usecs % 100;
  ret = select (0, NULL, NULL, NULL, timeout);
  if (ret  0) printf (select failed, error = %d\n, WSAGetLastError());

  if (!QueryPerformanceCounter (after))
printf (QueryPerformanceCounter failed\n);

  printf (time slept: %g s\n, (double) (after.QuadPart - before.QuadPart) / 
(double) pcfreq.QuadPart);
  return 0;
}
===
   produces the output

   $ ./usleep.exe 6000
   select failed, error = 10093
   time slept: 6.87238e-005 s

   Error 10093 is WSANOTINITIALISED.

3) Use of select without a socket descriptor, just a timeout, fails.

   Witness: This program
===
#include winsock2.h
#include sys/time.h
#include stdlib.h
#include stdio.h
#include windows.h

int main (int argc, char *argv[])
{
  int usecs = atoi (argv[1]);
  LARGE_INTEGER pcfreq;
  WSADATA data;
  LARGE_INTEGER before, after;
  struct timeval timeout;
  int ret;

  if (!QueryPerformanceFrequency (pcfreq))
printf (QueryPerformanceFrequency failed\n);

  WSAStartup (0x201, data);

  if (!QueryPerformanceCounter (before))
printf (QueryPerformanceCounter failed\n);

  timeout.tv_sec = usecs / 100;
  timeout.tv_usec = usecs % 100;
  ret = select (0, NULL, NULL, NULL, timeout);
  if (ret  0) printf (select failed, error = %d\n, WSAGetLastError());

  if (!QueryPerformanceCounter (after))
printf (QueryPerformanceCounter failed\n);

  printf (time slept: %g s\n, (double) (after.QuadPart - before.QuadPart) / 
(double) pcfreq.QuadPart);
  return 0;
}
===
   produces the output

   $ ./usleep.exe 6000
   select failed, error = 10022
   time slept: 0.000258971 s

   Error 10022 is WSAEINVAL.

4) select sleeps for at least 6 ms.

   Witness: This program
===
#include winsock2.h
#include sys/time.h
#include stdlib.h
#include stdio.h
#include windows.h

int main (int argc, char *argv[])
{
  int usecs = atoi (argv[1]);
  LARGE_INTEGER pcfreq;
  WSADATA data;
  SOCKET s;
  fd_set dummy;
  LARGE_INTEGER before, after;
  struct timeval timeout;
  int ret;

  if (!QueryPerformanceFrequency (pcfreq))
printf (QueryPerformanceFrequency failed\n);

  WSAStartup (0x201, data);

  s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  FD_ZERO(dummy);
  FD_SET(s, dummy);

  if (!QueryPerformanceCounter (before))
printf (QueryPerformanceCounter failed\n);

  timeout.tv_sec = usecs / 100;
  timeout.tv_usec = usecs % 100;
  ret = select (0, NULL, NULL, dummy, timeout);
  if (ret  0) printf (select failed, error = %d\n, WSAGetLastError());

  if (!QueryPerformanceCounter (after))
printf (QueryPerformanceCounter failed\n);

  printf (time slept: %g s\n, (double) (after.QuadPart - before.QuadPart) / 
(double) pcfreq.QuadPart);
  return 0;
}

tmpfile on mingw

2010-04-04 Thread Bruno Haible
On mingw, one of the unit tests suggested by John Eaton fails:

  g++-3 -mno-cygwin -DHAVE_CONFIG_H -I.  -I. -I. -I.. -I./.. -I../gllib 
-I./../gllib -I/usr/local/mingw/include -Wall   -MT test-stdio-c++2.o -MD -MP 
-MF .deps/test-stdio-c++2.Tpo -c -o test-stdio-c++2.o test-stdio-c++2.cc
  In file included from test-stdio-c++2.cc:20:
  /usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/cstdio:137: error: `::tmpfile' 
has not been declared
  make[4]: *** [test-stdio-c++2.o] Error 1

This error does not occur if #include cstdio is used without gnulib.

The reason is that cstdio does a

  using ::tmpfile;

but gnulib has renamed that function to rpl_tmpfile, already before the system
headers were included. This fixes it:


2010-04-04  Bruno Haible  br...@clisp.org

tmpfile: Fix C++ test error on mingw.
* lib/stdio.in.h (tmpfile): New declaration.
* m4/tmpfile.m4 (gl_TMPFILE): Require gl_STDIO_H_DEFAULTS. Set
REPLACE_TMPFILE instead of defining tmpfile as a macro in config.h.
* modules/tmpfile (Depends-on): Add stdio.
(configure.ac): Invoke gl_STDIO_MODULE_INDICATOR.
* m4/stdio_h.m4 (gl_STDIO_H): Also check whether tmpfile is declared.
(gl_STDIO_H_DEFAULTS): Initialize GNULIB_TMPFILE and REPLACE_TMPFILE.
* modules/stdio (Makefile.am): Substitute GNULIB_TMPFILE and
REPLACE_TMPFILE.
* tests/test-stdio-c++.cc (tmpfile): Verify signature.

--- lib/stdio.in.h.orig Sun Apr  4 15:31:07 2010
+++ lib/stdio.in.h  Sun Apr  4 15:20:14 2010
@@ -838,6 +838,25 @@
  POSIX compliance);
 #endif
 
+#if @GNULIB_TMPFILE@
+# if @REPLACE_TMPFILE@
+#  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
+#   define tmpfile rpl_tmpfile
+#  endif
+_GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
+_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
+# else
+_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
+# endif
+_GL_CXXALIASWARN (tmpfile);
+#elif defined GNULIB_POSIXCHECK
+# undef tmpfile
+# if HAVE_RAW_DECL_TMPFILE
+_GL_WARN_ON_USE (tmpfile, tmpfile is not usable on mingw - 
+ use gnulib module tmpfile for portability);
+# endif
+#endif
+
 #if @GNULIB_VASPRINTF@
 /* Write formatted output to a string dynamically allocated with malloc().
If the memory allocation succeeds, store the address of the string in
--- m4/stdio_h.m4.orig  Sun Apr  4 15:31:07 2010
+++ m4/stdio_h.m4   Sun Apr  4 15:22:49 2010
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 29
+# stdio_h.m4 serial 30
 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -37,7 +37,7 @@
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include stdio.h
 ]], [dprintf fpurge fseeko ftello getdelim getline popen renameat
-snprintf vdprintf vsnprintf])
+snprintf tmpfile vdprintf vsnprintf])
 ])
 
 AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
@@ -83,6 +83,7 @@
   GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
   GNULIB_SPRINTF_POSIX=0;AC_SUBST([GNULIB_SPRINTF_POSIX])
   GNULIB_STDIO_H_SIGPIPE=0;  AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
+  GNULIB_TMPFILE=0;  AC_SUBST([GNULIB_TMPFILE])
   GNULIB_VASPRINTF=0;AC_SUBST([GNULIB_VASPRINTF])
   GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF])
   GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF])
@@ -127,6 +128,7 @@
   REPLACE_SNPRINTF=0;AC_SUBST([REPLACE_SNPRINTF])
   REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
   REPLACE_STDIO_WRITE_FUNCS=0;   AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
+  REPLACE_TMPFILE=0; AC_SUBST([REPLACE_TMPFILE])
   REPLACE_VASPRINTF=0;   AC_SUBST([REPLACE_VASPRINTF])
   REPLACE_VDPRINTF=0;AC_SUBST([REPLACE_VDPRINTF])
   REPLACE_VFPRINTF=0;AC_SUBST([REPLACE_VFPRINTF])
--- m4/tmpfile.m4.orig  Sun Apr  4 15:31:07 2010
+++ m4/tmpfile.m4   Sun Apr  4 15:31:04 2010
@@ -1,5 +1,4 @@
-# Check whether to use a replacement tmpfile() function.
-
+# tmpfile.m4 serial 1
 # Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -7,6 +6,8 @@
 
 # Written by Ben Pfaff.
 
+# Check whether to use a replacement tmpfile() function.
+
 # The native Windows tmpfile function always tries to put the temporary
 # file in the root directory.  (This behaviour is even documented in
 # Microsoft's documentation!)  This often fails for ordinary users who
@@ -18,6 +19,7 @@
 # just test for a Windows platform (excluding Cygwin).
 
 AC_DEFUN([gl_TMPFILE], [
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_CACHE_CHECK([whether tmpfile should be overridden],
 [gl_cv_func_tmpfile_unusable],
 [AC_EGREP_CPP([choke me], [
@@ -28,9 +30,8 @@
[gl_cv_func_tmpfile_unusable=yes],
[gl_cv_func_tmpfile_unusable=no])])
   if test $gl_cv_func_tmpfile_unusable 

Re: tmpfile on mingw

2010-04-04 Thread Bruno Haible
Additionally, tmpfile is just one function, so let's use the common macro
naming scheme (cf. 2010-03-27 commits).


2010-04-04  Bruno Haible  br...@clisp.org

* m4/tmpfile.m4 (gl_FUNC_TMPFILE): Renamed from gl_TMPFILE.
* modules/tmpfile (configure.ac): Update.

--- m4/tmpfile.m4.orig  Sun Apr  4 15:38:26 2010
+++ m4/tmpfile.m4   Sun Apr  4 15:38:08 2010
@@ -18,7 +18,7 @@
 # directory, even though tmpfile wouldn't work in general.  Instead,
 # just test for a Windows platform (excluding Cygwin).
 
-AC_DEFUN([gl_TMPFILE], [
+AC_DEFUN([gl_FUNC_TMPFILE], [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_CACHE_CHECK([whether tmpfile should be overridden],
 [gl_cv_func_tmpfile_unusable],
--- modules/tmpfile.origSun Apr  4 15:38:27 2010
+++ modules/tmpfile Sun Apr  4 15:38:17 2010
@@ -12,7 +12,7 @@
 tmpdir
 
 configure.ac:
-gl_TMPFILE
+gl_FUNC_TMPFILE
 gl_STDIO_MODULE_INDICATOR([tmpfile])
 
 Makefile.am:




rmdir: simplify test

2010-04-04 Thread Bruno Haible
Hi,

The rmdir module does not satisfy the common idiom (distinguish
missing and broken function). But this part is already marked as
  simplify this module in 2010 if no one reports a missing rmdir

Did someone report a missing rmdir? Or can we remove this part of
the autoconf test?

Here's the proposed patch:


2010-04-04  Bruno Haible  br...@clisp.org

Assume rmdir exists.
* m4/rmdir.m4 (gl_FUNC_RMDIR): Remove test whether rmdir exists.
* doc/posix-functions/rmdir.texi: Remove mention of old platforms.

--- doc/posix-functions/rmdir.texi.orig Sun Apr  4 17:06:02 2010
+++ doc/posix-functions/rmdir.texi  Sun Apr  4 17:03:58 2010
@@ -16,8 +16,6 @@
 This function fails with @code{EINVAL} instead of the expected
 @code{ENOTDIR} for @code{rmdir(file/)} on some platforms:
 mingw.
-...@item
-This function is missing on some old platforms.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- m4/rmdir.m4.origSun Apr  4 17:06:02 2010
+++ m4/rmdir.m4 Sun Apr  4 17:05:23 2010
@@ -1,4 +1,4 @@
-# rmdir.m4 serial 7
+# rmdir.m4 serial 8
 dnl Copyright (C) 2002, 2005, 2009-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,37 +8,22 @@
 [
   AC_REQUIRE([gl_AC_DOS])
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
-  dnl FIXME: simplify this module in 2010 if no one reports a missing rmdir
-  AC_REPLACE_FUNCS([rmdir])
-  if test $ac_cv_func_rmdir = no; then
-REPLACE_RMDIR=1
-# If someone lacks rmdir, make configure fail, and request
-# a bug report to inform us about it.
-if test x$SKIP_RMDIR_CHECK != xyes; then
-  AC_MSG_FAILURE([Your system lacks the rmdir function.
-  Please report this, along with the output of uname -a, to the
-  bug-coreut...@gnu.org mailing list.  To continue past this point,
-  rerun configure with SKIP_RMDIR_CHECK=yes.
-  E.g., ./configure SKIP_RMDIR_CHECK=yes])
-fi
-  else
-dnl Detect cygwin 1.5.x bug.
-AC_CACHE_CHECK([whether rmdir works], [gl_cv_func_rmdir_works],
-  [mkdir conftest.dir
-   touch conftest.file
-   AC_RUN_IFELSE(
- [AC_LANG_PROGRAM(
-   [[#include stdio.h
- #include errno.h
- #include unistd.h
+  dnl Detect cygwin 1.5.x bug.
+  AC_CACHE_CHECK([whether rmdir works], [gl_cv_func_rmdir_works],
+[mkdir conftest.dir
+ touch conftest.file
+ AC_RUN_IFELSE(
+   [AC_LANG_PROGRAM(
+ [[#include stdio.h
+   #include errno.h
+   #include unistd.h
 ]], [[return !rmdir (conftest.file/) || errno != ENOTDIR
|| !rmdir (conftest.dir/./);]])],
- [gl_cv_func_rmdir_works=yes], [gl_cv_func_rmdir_works=no],
- [gl_cv_func_rmdir_works=guessing no])
-   rm -rf conftest.dir conftest.file])
-if test x$gl_cv_func_rmdir_works != xyes; then
-  REPLACE_RMDIR=1
-  AC_LIBOBJ([rmdir])
-fi
+   [gl_cv_func_rmdir_works=yes], [gl_cv_func_rmdir_works=no],
+   [gl_cv_func_rmdir_works=guessing no])
+ rm -rf conftest.dir conftest.file])
+  if test x$gl_cv_func_rmdir_works != xyes; then
+REPLACE_RMDIR=1
+AC_LIBOBJ([rmdir])
   fi
 ])




Re: nanosleep on mingw

2010-04-04 Thread Jim Meyering
Bruno Haible wrote:
...
 So here is a proposed patch for implementing a Woe32 nanosleep with a
 resolution of ca. 10 microseconds or higher.

 2010-04-04  Bruno Haible  br...@clisp.org

   Implement nanosleep for native Windows.
   * lib/nanosleep.c (nanosleep): New implementation for native Windows.

 --- lib/nanosleep.c.orig  Sun Apr  4 14:45:40 2010
 +++ lib/nanosleep.c   Sun Apr  4 14:43:28 2010

Nice work.
You're welcome to commit that.




trunc, truncf on Solaris

2010-04-04 Thread Bruno Haible
On Solaris 8, I'm seeing these errors:

  ../gllib/math.h:816: error: 'truncf' was not declared in this scope
  ../gllib/math.h:835: error: 'trunc' was not declared in this scope

This fixes it, by using the simpler idiom for a missing function.


2010-04-04  Bruno Haible  br...@clisp.org

math: Fix some C++ test errors on Solaris 8.
* lib/math.in.h (truncf, trunc): Use simpler idiom.

--- lib/math.in.h.orig  Sun Apr  4 20:08:04 2010
+++ lib/math.in.h   Sun Apr  4 20:07:16 2010
@@ -520,14 +520,9 @@
 
 #if @GNULIB_TRUNCF@
 # if !...@have_decl_truncf@
-#  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
-#   define truncf rpl_truncf
-#  endif
-_GL_FUNCDECL_RPL (truncf, float, (float x));
-_GL_CXXALIAS_RPL (truncf, float, (float x));
-# else
-_GL_CXXALIAS_SYS (truncf, float, (float x));
+_GL_FUNCDECL_SYS (truncf, float, (float x));
 # endif
+_GL_CXXALIAS_SYS (truncf, float, (float x));
 _GL_CXXALIASWARN (truncf);
 #elif defined GNULIB_POSIXCHECK
 # undef truncf
@@ -539,14 +534,9 @@
 
 #if @GNULIB_TRUNC@
 # if !...@have_decl_trunc@
-#  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
-#   define trunc rpl_trunc
-#  endif
-_GL_FUNCDECL_RPL (trunc, double, (double x));
-_GL_CXXALIAS_RPL (trunc, double, (double x));
-# else
-_GL_CXXALIAS_SYS (trunc, double, (double x));
+_GL_FUNCDECL_SYS (trunc, double, (double x));
 # endif
+_GL_CXXALIAS_SYS (trunc, double, (double x));
 _GL_CXXALIASWARN (trunc);
 #elif defined GNULIB_POSIXCHECK
 # undef trunc




Re: nanosleep on mingw

2010-04-04 Thread Bruno Haible
Jim Meyering wrote:
 You're welcome to commit that.

Committed. The only thing I'm worried about is that it's a compromise
between precision of the time interval and ues of CPU time:
Someone who invokes nanosleep with an argument of 0.3 seconds may complain
that 9.4 ms of busy-looping is not acceptable and that - in his application -
sleeping 0.29 or 0.31 s would be more acceptable than burning CPU time.
But nanosleep does not take a precision argument...

Bruno




cosl, sinl, logl on Solaris, Cygwin

2010-04-04 Thread Bruno Haible
On Cygwin 1.7.2 and Solaris 8, I'm seeing these errors:

  ../gllib/math.h:526: error: 'cosl' was not declared in this scope
  ../gllib/math.h:672: error: 'logl' was not declared in this scope
  ../gllib/math.h:766: error: 'sinl' was not declared in this scope

There is no reason to define rpl_cosl instead of cosl, because no
platform is known which has the function in some shared libraries
but does not declare it.


2010-04-04  Bruno Haible  br...@clisp.org

math: Fix some C++ test errors on Solaris 8 and Cygwin.
* lib/math.in.h (cosl, logl, sinl): Use simpler idiom.

--- lib/math.in.h.orig  Sun Apr  4 21:16:50 2010
+++ lib/math.in.h   Sun Apr  4 21:03:11 2010
@@ -225,19 +225,10 @@
 
 
 #if @GNULIB_COSL@
-# if !...@have_cosl@
-#  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
-#   undef cosl
-#   define cosl rpl_cosl
-#  endif
-_GL_FUNCDECL_RPL (cosl, long double, (long double x));
-_GL_CXXALIAS_RPL (cosl, long double, (long double x));
-# else
-#  if !...@have_decl_cosl@
+# if !...@have_cosl@ || !...@have_decl_cosl@
 _GL_FUNCDECL_SYS (cosl, long double, (long double x));
-#  endif
-_GL_CXXALIAS_SYS (cosl, long double, (long double x));
 # endif
+_GL_CXXALIAS_SYS (cosl, long double, (long double x));
 _GL_CXXALIASWARN (cosl);
 #elif defined GNULIB_POSIXCHECK
 # undef cosl
@@ -371,19 +362,10 @@
 
 
 #if @GNULIB_LOGL@
-# if !...@have_logl@
-#  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
-#   undef logl
-#   define logl rpl_logl
-#  endif
-_GL_FUNCDECL_RPL (logl, long double, (long double x));
-_GL_CXXALIAS_RPL (logl, long double, (long double x));
-# else
-#  if !...@have_decl_logl@
+# if !...@have_logl@ || !...@have_decl_logl@
 _GL_FUNCDECL_SYS (logl, long double, (long double x));
-#  endif
-_GL_CXXALIAS_SYS (logl, long double, (long double x));
 # endif
+_GL_CXXALIAS_SYS (logl, long double, (long double x));
 _GL_CXXALIASWARN (logl);
 #elif defined GNULIB_POSIXCHECK
 # undef logl
@@ -465,19 +447,10 @@
 
 
 #if @GNULIB_SINL@
-# if !...@have_sinl@
-#  if !(defined __cplusplus  defined GNULIB_NAMESPACE)
-#   undef sinl
-#   define sinl rpl_sinl
-#  endif
-_GL_FUNCDECL_RPL (sinl, long double, (long double x));
-_GL_CXXALIAS_RPL (sinl, long double, (long double x));
-# else
-#  if !...@have_decl_sinl@
+# if !...@have_sinl@ || !...@have_decl_sinl@
 _GL_FUNCDECL_SYS (sinl, long double, (long double x));
-#  endif
-_GL_CXXALIAS_SYS (sinl, long double, (long double x));
 # endif
+_GL_CXXALIAS_SYS (sinl, long double, (long double x));
 _GL_CXXALIASWARN (sinl);
 #elif defined GNULIB_POSIXCHECK
 # undef sinl




Re: tmpfile on mingw

2010-04-04 Thread Ben Pfaff
Bruno Haible br...@clisp.org writes:

 The reason is that cstdio does a

   using ::tmpfile;

 but gnulib has renamed that function to rpl_tmpfile, already before the system
 headers were included. This fixes it:

I'm happy with these patches.
-- 
Ben Pfaff 
http://benpfaff.org




[Patch] stdio-impl.h has too indiscriminate #ifdef

2010-04-04 Thread Hauke Fath
Hi,

I am seeing a build failure of Gnu m4 on NetBSD 1.5

[...]
source='freadahead.c' object='freadahead.o' libtool=no  DEPDIR=.deps
depmode=gcc /bin/sh ../build-aux/depcomp  cc  -I.  -
O2 -pipe -c freadahead.c
freadahead.c: In function `freadahead':
freadahead.c:41: structure has no member named `_ext'
*** Error code 1

Stop.
bmake: stopped in /var/obj/pkgsrc/devel/m4/work/m4-1.4.14/lib
*** Error code 1

which is due to an #ifdef in gnulib's stdio-impl.h which is too
indiscriminate:

snip
--- lib/stdio-impl.h.orig   Thu Jan 28 13:04:07 2010
+++ lib/stdio-impl.h
@@ -50,7 +50,7 @@
 #  define fp_ fp
 # endif

-# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
+# if (defined __NetBSD__  __NetBSD__ = 10527) || defined
__OpenBSD__ /* NetBSD, OpenBSD */
   /* See
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEADconte
nt-type=text/x-cvsweb-markup
  and
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEADcon
tent-type=text/x-cvsweb-markup */
   struct __sfileext
@@ -59,7 +59,7 @@
   /* More fields, not relevant here.  */
 };
 #  define fp_ub ((struct __sfileext *) fp-_ext._base)-_ub
-# else /* FreeBSD, DragonFly,
MacOS X, Cygwin */
+# else /* Old NetBSD, FreeBSD,
DragonFly, MacOS X, Cygwin */
 #  define fp_ub fp_-_ub
 # endif
/snip

hauke


--
It's never straight up and down (DEVO)






frexpl on Solaris, Cygwin

2010-04-04 Thread Bruno Haible
On Solaris 8 and Cygwin 1.7.2 I'm seeing this error:

  ../gllib/math.h:620: error: 'frexpl' was not declared in this scope

Again, the problem is that REPLACE_FREXPL is set when the function does
not exist. This fixes it.


2010-04-04  Bruno Haible  br...@clisp.org

frexpl: Fix a C++ test error on Solaris 8 and Cygwin.
* m4/frexpl.m4 (gl_FUNC_FREXPL, gl_FUNC_FREXPL_NO_LIBM): When the
function is not declared, set HAVE_DECL_FREXPL to 0, instead of setting
REPLACE_FREXPL to 1.
* doc/posix-functions/frexpl.texi: Update documentation.

--- m4/frexpl.m4.orig   Sun Apr  4 22:10:26 2010
+++ m4/frexpl.m4Sun Apr  4 22:00:06 2010
@@ -7,54 +7,56 @@
 AC_DEFUN([gl_FUNC_FREXPL],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  dnl Check whether it's declared.
+  dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in math.h.
+  AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include math.h])
   FREXPL_LIBM=
-  AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
-[gl_cv_func_frexpl_no_libm],
-[
-  AC_TRY_LINK([#include math.h
-   long double x;],
-  [int e; return frexpl (x, e)  0;],
-[gl_cv_func_frexpl_no_libm=yes],
-[gl_cv_func_frexpl_no_libm=no])
-])
-  if test $gl_cv_func_frexpl_no_libm = no; then
-AC_CACHE_CHECK([whether frexpl() can be used with libm],
-  [gl_cv_func_frexpl_in_libm],
+  if test $HAVE_DECL_FREXPL = 1; then
+AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
+  [gl_cv_func_frexpl_no_libm],
   [
-save_LIBS=$LIBS
-LIBS=$LIBS -lm
 AC_TRY_LINK([#include math.h
  long double x;],
 [int e; return frexpl (x, e)  0;],
-  [gl_cv_func_frexpl_in_libm=yes],
-  [gl_cv_func_frexpl_in_libm=no])
-LIBS=$save_LIBS
+  [gl_cv_func_frexpl_no_libm=yes],
+  [gl_cv_func_frexpl_no_libm=no])
   ])
-if test $gl_cv_func_frexpl_in_libm = yes; then
-  FREXPL_LIBM=-lm
+if test $gl_cv_func_frexpl_no_libm = no; then
+  AC_CACHE_CHECK([whether frexpl() can be used with libm],
+[gl_cv_func_frexpl_in_libm],
+[
+  save_LIBS=$LIBS
+  LIBS=$LIBS -lm
+  AC_TRY_LINK([#include math.h
+   long double x;],
+  [int e; return frexpl (x, e)  0;],
+[gl_cv_func_frexpl_in_libm=yes],
+[gl_cv_func_frexpl_in_libm=no])
+  LIBS=$save_LIBS
+])
+  if test $gl_cv_func_frexpl_in_libm = yes; then
+FREXPL_LIBM=-lm
+  fi
+fi
+if test $gl_cv_func_frexpl_no_libm = yes \
+   || test $gl_cv_func_frexpl_in_libm = yes; then
+  save_LIBS=$LIBS
+  LIBS=$LIBS $FREXPL_LIBM
+  gl_FUNC_FREXPL_WORKS
+  LIBS=$save_LIBS
+  case $gl_cv_func_frexpl_works in
+*yes) gl_func_frexpl=yes ;;
+*)gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
+  esac
+else
+  gl_func_frexpl=no
+fi
+if test $gl_func_frexpl = yes; then
+  AC_DEFINE([HAVE_FREXPL], [1],
+[Define if the frexpl() function is available.])
 fi
   fi
-  if test $gl_cv_func_frexpl_no_libm = yes \
- || test $gl_cv_func_frexpl_in_libm = yes; then
-save_LIBS=$LIBS
-LIBS=$LIBS $FREXPL_LIBM
-gl_FUNC_FREXPL_WORKS
-LIBS=$save_LIBS
-case $gl_cv_func_frexpl_works in
-  *yes) gl_func_frexpl=yes ;;
-  *)gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
-esac
-  else
-gl_func_frexpl=no
-  fi
-  if test $gl_func_frexpl = yes; then
-AC_DEFINE([HAVE_FREXPL], [1],
-  [Define if the frexpl() function is available.])
-dnl Also check whether it's declared.
-dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in math.h.
-AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include math.h])
-  else
-HAVE_DECL_FREXPL=0
+  if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
 AC_LIBOBJ([frexpl])
   fi
   AC_SUBST([FREXPL_LIBM])
@@ -63,34 +65,36 @@
 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
-  AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
-[gl_cv_func_frexpl_no_libm],
-[
-  AC_TRY_LINK([#include math.h
-   long double x;],
-  [int e; return frexpl (x, e)  0;],
-[gl_cv_func_frexpl_no_libm=yes],
-[gl_cv_func_frexpl_no_libm=no])
-])
-  if test $gl_cv_func_frexpl_no_libm = yes; then
-gl_FUNC_FREXPL_WORKS
-case $gl_cv_func_frexpl_works in
-  *yes) gl_func_frexpl_no_libm=yes ;;
-  *)gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
-esac
-  else
-gl_func_frexpl_no_libm=no
-dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
-REPLACE_FREXPL=1
+  dnl Check whether it's declared.
+  dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in math.h.
+  

vfprintf on Solaris

2010-04-04 Thread Bruno Haible
On Solaris 8, with GCC 4.3.3, I'm seeing these errors in the C++ tests:

  g++ -DHAVE_CONFIG_H -I.   -I. -I.  -I.. -I./..  -I../gllib -I./../gllib 
-I/home/haible/prefix-x86/include -Wall   -MT test-stdio-c++.o -MD -MP -MF 
.deps/test-stdio-c++.Tpo -c -o test-stdio-c++.o test-stdio-c++.cc
  In file included from test-stdio-c++.cc:22:
  ../gllib/stdio.h:1232: error: invalid conversion from 'int (*)(FILE*, const 
char*, void*)' to 'int (*)(FILE*, const char*, char*)'
  ../gllib/stdio.h:1258: error: invalid conversion from 'int (*)(const char*, 
void*)' to 'int (*)(const char*, char*)'
  *** Error code 1

These lines correspond to the aliasing of vfprintf and vprintf.

The reason is that these functions take a 'va_list' argument in POSIX, which
for GCC is equivalent to a '__gnuc_va_list' or 'char *'. But Solaris declares
these functions as taking a '__va_list' argument, which is equivalent to
'void *'. For the function vsnprintf, this is corrected by GCC's fixincludes,
but not for vfprintf and vprintf.

This fixes the error.


2010-04-04  Bruno Haible  br...@clisp.org

stdio: Fix some C++ test errors on Solaris 8 with GCC.
* lib/stdio.in.h (vdprintf, vfprintf, vprintf, vsprintf): Use
_GL_CXXALIAS_SYS_CAST.

--- lib/stdio.in.h.orig Sun Apr  4 22:36:42 2010
+++ lib/stdio.in.h  Sun Apr  4 22:34:46 2010
@@ -921,7 +921,10 @@
  __attribute__ ((__format__ (__printf__, 2, 
0)))
  _GL_ARG_NONNULL ((2)));
 #  endif
-_GL_CXXALIAS_SYS (vdprintf, int, (int fd, const char *format, va_list args));
+/* Need to cast, because on Solaris, the third parameter will likely be
+__va_list args.  */
+_GL_CXXALIAS_SYS_CAST (vdprintf, int,
+   (int fd, const char *format, va_list args));
 # endif
 _GL_CXXALIASWARN (vdprintf);
 #elif defined GNULIB_POSIXCHECK
@@ -944,7 +947,11 @@
  _GL_ARG_NONNULL ((1, 2)));
 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
 # else
-_GL_CXXALIAS_SYS (vfprintf, int, (FILE *fp, const char *format, va_list args));
+/* Need to cast, because on Solaris, the third parameter is
+  __va_list args
+   and GCC's fixincludes did not change this to __gnuc_va_list.  */
+_GL_CXXALIAS_SYS_CAST (vfprintf, int,
+   (FILE *fp, const char *format, va_list args));
 # endif
 _GL_CXXALIASWARN (vfprintf);
 #endif
@@ -970,7 +977,10 @@
 _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
 # else
-_GL_CXXALIAS_SYS (vprintf, int, (const char *format, va_list args));
+/* Need to cast, because on Solaris, the second parameter is
+  __va_list args
+   and GCC's fixincludes did not change this to __gnuc_va_list.  */
+_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
 # endif
 _GL_CXXALIASWARN (vprintf);
 #endif
@@ -1026,8 +1036,11 @@
 _GL_CXXALIAS_RPL (vsprintf, int,
   (char *str, const char *format, va_list args));
 # else
-_GL_CXXALIAS_SYS (vsprintf, int,
-  (char *str, const char *format, va_list args));
+/* Need to cast, because on Solaris, the third parameter is
+   __va_list args
+   and GCC's fixincludes did not change this to __gnuc_va_list.  */
+_GL_CXXALIAS_SYS_CAST (vsprintf, int,
+   (char *str, const char *format, va_list args));
 # endif
 _GL_CXXALIASWARN (vsprintf);
 #elif defined GNULIB_POSIXCHECK




Re: [Patch] stdio-impl.h has too indiscriminate #ifdef

2010-04-04 Thread Bruno Haible
Hi,

Hauke Fath wrote:
 -# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
 +# if (defined __NetBSD__  __NetBSD__ = 10527) || defined __OpenBSD__ 
 /* NetBSD, OpenBSD */

The introduction of the '_ext' field happened in NetBSD on 2001-12-07,
according to http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/ungetc.c.
The tags indicate that it is present starting with NetBSD 1.6. What's
the condition for testing for NetBSD = 1.6? Where does your magic number
10527 come from?

Bruno




strerror: Update documentation

2010-04-04 Thread Bruno Haible
The idiom used to declare strerror() in lib/string.in.h does not cope with
the case of a missing strerror function (at least not in C++ mode). But
such platforms are likely older than 1998. Therefore I don't think they
are relevant any more.


2010-04-04  Bruno Haible  br...@clisp.org

strerror: Update documentation.
* doc/posix-functions/strerror.texi: Remove mention of old platforms.

--- doc/posix-functions/strerror.texi.orig  Sun Apr  4 23:05:08 2010
+++ doc/posix-functions/strerror.texi   Sun Apr  4 23:04:27 2010
@@ -9,8 +9,6 @@
 Portability problems fixed by Gnulib:
 @itemize
 @item
-This function is missing on some old platforms.
-...@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, Cygwin 1.5.x, mingw.




strtod: Avoid a possible C++ test error

2010-04-04 Thread Bruno Haible
On platforms where strtod() does not exist, the C++ tests would fail with
g++ = 4.3, because REPLACE_STRTOD would be set in this case. This
supposedly fixes it.


2010-04-04  Bruno Haible  br...@clisp.org

strtod: Avoid a possible C++ test error.
* m4/strtod.m4 (gl_FUNC_STRTOD): When setting HAVE_STRTOD to 0, don't
set REPLACE_STRTOD.

--- m4/strtod.m4.orig   Sun Apr  4 23:10:40 2010
+++ m4/strtod.m4Sun Apr  4 23:09:26 2010
@@ -1,4 +1,4 @@
-# strtod.m4 serial 13
+# strtod.m4 serial 14
 dnl Copyright (C) 2002-2003, 2006-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -11,7 +11,6 @@
   dnl Note: AC_FUNC_STRTOD does AC_LIBOBJ([strtod]).
   if test $ac_cv_func_strtod = no; then
 HAVE_STRTOD=0
-REPLACE_STRTOD=1
 gl_PREREQ_STRTOD
   else
 AC_CACHE_CHECK([whether strtod obeys C99], [gl_cv_func_strtod_works],




Re: [Patch] stdio-impl.h has too indiscriminate #ifdef

2010-04-04 Thread Bruno Haible
Hi Hauke,

 -- it should actually be
 
 if (defined __NetBSD__  __NetBSD_Version__ = 10527)
 
 where __NetBSD_Version__ is defined in sys/param.h, in the kernel source
 tree at src/sys/sys/param.h.
 
 The relevant version bump of this file is
 http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/param.h?rev=1.135content-type=text/x-cvsweb-markup

Thanks, this makes it clear. To be safe, it's necessary to
#include sys/param.h.

I'm applying this patch. (The tiny change is not a devalorisation of your
contribution, but merely an indication that you don't need to start a copyright
assignment for the FSF for this contribution.)


2010-04-04  Hauke Fath  ha...@espresso.rhein-neckar.de  (tiny change)
Bruno Haible  br...@clisp.org

Port extended stdio to NetBSD 1.5.
* lib/stdio-impl.h [NetBSD]: Include sys/param.h.
(struct __sfileext, fp_ub): Define the old way for NetBSD 1.5Z and
older.

--- lib/stdio-impl.h.orig   Mon Apr  5 01:09:55 2010
+++ lib/stdio-impl.hMon Apr  5 01:07:15 2010
@@ -1,5 +1,5 @@
 /* Implementation details of FILE streams.
-   Copyright (C) 2007-2010 Free Software Foundation, Inc.
+   Copyright (C) 2007-2008, 2010 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
@@ -21,6 +21,11 @@
 
 /* BSD stdio derived implementations.  */
 
+#if defined __NetBSD__ /* NetBSD */
+/* Get __NetBSD_Version__.  */
+# include sys/param.h
+#endif
+
 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, 
DragonFly, MacOS X, Cygwin */
 
 # if defined __DragonFly__  /* DragonFly */
@@ -50,7 +55,7 @@
 #  define fp_ fp
 # endif
 
-# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
+# if (defined __NetBSD__  __NetBSD_Version__ = 10527) || defined 
__OpenBSD__ /* NetBSD = 1.5ZA, OpenBSD */
   /* See 
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEADcontent-type=text/x-cvsweb-markup
  and 
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEADcontent-type=text/x-cvsweb-markup
 */
   struct __sfileext
@@ -59,7 +64,7 @@
   /* More fields, not relevant here.  */
 };
 #  define fp_ub ((struct __sfileext *) fp-_ext._base)-_ub
-# else /* FreeBSD, DragonFly, MacOS X, 
Cygwin */
+# else /* FreeBSD, NetBSD = 1.5Z, 
DragonFly, MacOS X, Cygwin */
 #  define fp_ub fp_-_ub
 # endif
 




Re: Zile build breaks in lib/btow.c on NetBSD 1.5

2010-04-04 Thread Bruno Haible
Hi,

Hauke Fath wrote:
 and this NetBSD version's wchar.h does not #define WEOF.
 
 
 btowc.c:37: `WEOF' undeclared (first use in this function)
 btowc.c:37: (Each undeclared identifier is reported only once
 btowc.c:37: for each function it appears in.)
 btowc.c:38: warning: control reaches end of non-void function
 *** Error code 1
 ...
 The patch at
 
 http://la.causeuse.org/hauke/pkgsrc/zile/lib_wchar.in.h.diff
 
 does two things:
 
 (1) decouple the WEOF definition from wint_t availability

Thanks. It needs a minor correction: WEOF should be a member of
type 'wint_t', but we don't know whether the system's wint_t type
is signed or unsigned. I'm applying this:


2010-04-04  Hauke Fath  ha...@espresso.rhein-neckar.de  (tiny change)
Bruno Haible  br...@clisp.org

wchar: Port to NetBSD 1.5.
* lib/wchar.in.h (WEOF): Provide fallback also when wint_t exists.
* lib/wctype.in.h (WEOF): Likewise.

--- lib/wchar.in.h.orig Mon Apr  5 01:28:43 2010
+++ lib/wchar.in.h  Mon Apr  5 01:25:50 2010
@@ -82,12 +82,16 @@
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 
-/* Define wint_t.  (Also done in wctype.in.h.)  */
+/* Define wint_t and WEOF.  (Also done in wctype.in.h.)  */
 #if !...@have_wint_t@  !defined wint_t
 # define wint_t int
 # ifndef WEOF
 #  define WEOF -1
 # endif
+#else
+# ifndef WEOF
+#  define WEOF ((wint_t) -1)
+# endif
 #endif
 
 
--- lib/wctype.in.h.origMon Apr  5 01:28:43 2010
+++ lib/wctype.in.h Mon Apr  5 01:25:49 2010
@@ -58,12 +58,16 @@
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
-/* Define wint_t.  (Also done in wchar.in.h.)  */
+/* Define wint_t and WEOF.  (Also done in wchar.in.h.)  */
 #if !...@have_wint_t@  !defined wint_t
 # define wint_t int
 # ifndef WEOF
 #  define WEOF -1
 # endif
+#else
+# ifndef WEOF
+#  define WEOF ((wint_t) -1)
+# endif
 #endif
 
 




Re: Zile build breaks in lib/btow.c on NetBSD 1.5

2010-04-04 Thread Bruno Haible
Hi,

Hauke Fath wrote:
 misses #including stdlib.h for the definition of mbtowc() alike to the
 BSD/OS case,
 
 
 btowc.c: In function `btowc':
 btowc.c:34: warning: implicit declaration of function `mbtowc'

To fix this warning, you need a #include stdlib.h in btowc.c. I don't
see a reason to include it in wchar.h.


2010-04-04  Bruno Haible  br...@clisp.org

btowc: Avoid warning.
* lib/btowc.c: Include stdlib.h.
Reported by Hauke Fath ha...@espresso.rhein-neckar.de.

--- lib/btowc.c.origMon Apr  5 01:34:57 2010
+++ lib/btowc.c Mon Apr  5 01:27:46 2010
@@ -1,5 +1,5 @@
 /* Convert unibyte character to wide character.
-   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
Written by Bruno Haible br...@clisp.org, 2008.
 
This program is free software: you can redistribute it and/or modify
@@ -21,6 +21,7 @@
 #include wchar.h
 
 #include stdio.h
+#include stdlib.h
 
 wint_t
 btowc (int c)