Override getpagesize on mingw.
authorMartin Lambers <marlam@marlam.de>
Wed, 26 Dec 2007 15:37:29 +0000 (16:37 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 26 Dec 2007 15:37:29 +0000 (16:37 +0100)
ChangeLog
lib/getpagesize.c [new file with mode: 0644]
lib/unistd.in.h
m4/getpagesize.m4
m4/unistd_h.m4
modules/getpagesize
modules/unistd

index 5e68d46..364a429 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-12-10  Martin Lambers <marlam@marlam.de>
+
+       Override getpagesize on mingw.
+       * lib/getpagesize.c: New file.
+       * m4/getpagesize.m4 (gl_FUNC_GETPAGESIZE): Enable replacement on mingw.
+       * modules/getpagesize (Files): Add lib/getpagesize.c.
+       * lib/unistd.in.h (getpagesize): Declare if we are using a replacement.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
+       REPLACE_GETPAGESIZE.
+       * modules/unistd (Makefile.am): Substitute REPLACE_GETPAGESIZE.
+
 2007-12-25  Bruno Haible  <bruno@clisp.org>
 
        * modules/localcharset (Notice): New field.
diff --git a/lib/getpagesize.c b/lib/getpagesize.c
new file mode 100644 (file)
index 0000000..5498aa9
--- /dev/null
@@ -0,0 +1,39 @@
+/* getpagesize emulation for systems where it cannot be done in a C macro.
+
+   Copyright (C) 2007 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 <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible and Martin Lambers.  */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+/* This implementation is only for native Win32 systems.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+int
+getpagesize (void)
+{
+  SYSTEM_INFO system_info;
+  GetSystemInfo (&system_info);
+  return system_info.dwPageSize;
+}
+
+#endif
index 89c6fd5..5400c86 100644 (file)
@@ -181,7 +181,10 @@ extern int getlogin_r (char *name, size_t size);
 
 
 #if @GNULIB_GETPAGESIZE@
-# if !@HAVE_GETPAGESIZE@
+# if @REPLACE_GETPAGESIZE@
+#  define getpagesize rpl_getpagesize
+extern int getpagesize (void);
+# elif !@HAVE_GETPAGESIZE@
 /* This is for POSIX systems.  */
 #  if !defined getpagesize && defined _SC_PAGESIZE
 #   if ! (defined __VMS && __VMS_VER < 70000000)
index 37a0683..0d07a3a 100644 (file)
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_GETPAGESIZE],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
   AC_CHECK_FUNCS([getpagesize])
   if test $ac_cv_func_getpagesize = no; then
     HAVE_GETPAGESIZE=0
@@ -19,4 +20,10 @@ AC_DEFUN([gl_FUNC_GETPAGESIZE],
       HAVE_SYS_PARAM_H=1
     fi
   fi
+  case "$host_os" in
+    mingw*)
+      REPLACE_GETPAGESIZE=1
+      AC_LIBOBJ([getpagesize])
+      ;;
+  esac
 ])
index 91c02e7..4b8857c 100644 (file)
@@ -55,6 +55,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_CHOWN=0;        AC_SUBST([REPLACE_CHOWN])
   REPLACE_FCHDIR=0;       AC_SUBST([REPLACE_FCHDIR])
   REPLACE_GETCWD=0;       AC_SUBST([REPLACE_GETCWD])
+  REPLACE_GETPAGESIZE=0;  AC_SUBST([REPLACE_GETPAGESIZE])
   REPLACE_LCHOWN=0;       AC_SUBST([REPLACE_LCHOWN])
   REPLACE_LSEEK=0;        AC_SUBST([REPLACE_LSEEK])
 ])
index 91113b9..9cc4f37 100644 (file)
@@ -2,6 +2,7 @@ Description:
 getpagesize() function: Return memory page size.
 
 Files:
+lib/getpagesize.c
 m4/getpagesize.m4
 
 Depends-on:
index 5fb287d..4d16cf3 100644 (file)
@@ -45,6 +45,7 @@ unistd.h: unistd.in.h
              -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
              -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
              -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
+             -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
              -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
              -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
              < $(srcdir)/unistd.in.h; \