[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch for the getpagesize module
From: |
Martin Lambers |
Subject: |
Patch for the getpagesize module |
Date: |
Tue, 27 Nov 2007 10:28:29 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Hi everyone,
MinGW has a getpagesize() function, but does not declare it.
I attached a patch for the getpagesize module. It does the following:
- Don't provide a getpagesize.h header. Modify gnulibs unistd.h
instead.
- Provide a getpagesize declaration if the system does not provide one.
- Provide a getpagesize function (not a macro) if the system does not
have one.
I only tested this on GNU/Linux and MinGW.
The additional code for MSVC in lib/getpagesize.c is untested; it may be
better to remove it from the patch.
Martin
diff --git a/lib/getpagesize.c b/lib/getpagesize.c
index 6a51f04..eb0cafa 100644
--- a/lib/getpagesize.c
+++ b/lib/getpagesize.c
@@ -1,5 +1,5 @@
/* Emulate getpagesize on systems that lack it.
- Copyright (C) 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2004, 2005, 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
@@ -14,53 +14,58 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifndef HAVE_GETPAGESIZE
-
#include <unistd.h>
-#if !defined getpagesize && defined _SC_PAGESIZE
-# if ! (defined __VMS && __VMS_VER < 70000000)
-# define getpagesize() sysconf (_SC_PAGESIZE)
-# endif
+#if HAVE_OS_H
+# include <OS.h>
+#endif
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# include <windows.h>
#endif
-#if !defined getpagesize && defined __VMS
+int
+getpagesize (void)
+{
+#if defined _SC_PAGESIZE
+# if ! (defined __VMS && __VMS_VER < 70000000)
+ return sysconf (_SC_PAGESIZE);
+# endif
+#elif defined __VMS
# ifdef __ALPHA
-# define getpagesize() 8192
+ return 8192;
# else
-# define getpagesize() 512
+ return 512;
# endif
-#endif
-
/* This is for BeOS. */
-#if !defined getpagesize && HAVE_OS_H
-# include <OS.h>
-# if defined B_PAGE_SIZE
-# define getpagesize() B_PAGE_SIZE
-# endif
-#endif
-
+#elif HAVE_OS_H && defined B_PAGE_SIZE
+ return B_PAGE_SIZE;
/* This is for AmigaOS4.0. */
-#if !defined getpagesize && defined __amigaos4__
-# define getpagesize() 2048
-#endif
-
-#if !defined getpagesize && HAVE_SYS_PARAM_H
-# include <sys/param.h>
+#elif defined __amigaos4__
+ return 2048;
+/* This is for MSVC. */
+#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ SYSTEM_INFO system_info;
+ GetSystemInfo (&system_info);
+ return system_info.dwPageSize;
+#elif HAVE_SYS_PARAM_H
# ifdef EXEC_PAGESIZE
-# define getpagesize() EXEC_PAGESIZE
+ return EXEC_PAGESIZE;
# else
# ifdef NBPG
# ifndef CLSIZE
# define CLSIZE 1
# endif
-# define getpagesize() (NBPG * CLSIZE)
+ return (NBPG * CLSIZE);
# else
# ifdef NBPC
-# define getpagesize() NBPC
+ return NBPC;
+# else
+# error "Please port gnulib getpagesize.c to your platform!"
# endif
# endif
# endif
#endif
-
-#endif /* not HAVE_GETPAGESIZE */
+}
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 07c4877..d310f03 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -180,6 +180,20 @@ extern int getlogin_r (char *name, size_t size);
#endif
+#if @GNULIB_GETPAGESIZE@
+# if address@hidden@
+/* Returns the memory page size. */
+extern int getpagesize (void);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getpagesize
+# define getpagesize() \
+ (GL_LINK_WARNING ("getpagesize is unportable - " \
+ "use gnulib module getpagesize for portability"), \
+ getpagesize ())
+#endif
+
+
#if @GNULIB_LCHOWN@
# if @REPLACE_LCHOWN@
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
diff --git a/m4/getpagesize.m4 b/m4/getpagesize.m4
index e8697bd..405699c 100644
--- a/m4/getpagesize.m4
+++ b/m4/getpagesize.m4
@@ -1,13 +1,27 @@
-# getpagesize.m4 serial 6
-dnl Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+# getpagesize.m4 serial 7
+dnl Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
-AC_DEFUN([gl_GETPAGESIZE],
+AC_DEFUN([gl_FUNC_GETPAGESIZE],
[
- dnl Prerequisites of lib/getpagesize.h.
- AC_CHECK_HEADERS_ONCE(sys/param.h)
- AC_CHECK_HEADERS(OS.h)
- AC_CHECK_FUNCS(getpagesize)
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_CHECK_DECLS_ONCE([getpagesize])
+ if test $ac_cv_have_decl_getpagesize = no; then
+ HAVE_DECL_GETPAGESIZE=0
+ fi
+ AC_CHECK_FUNCS_ONCE([getpagesize])
+ if test $ac_cv_func_getpagesize = no; then
+ HAVE_GETPAGESIZE=0
+ AC_LIBOBJ([getpagesize])
+ gl_PREREQ_GETPAGESIZE
+ fi
+])
+
+# Prerequisites of lib/getpagesize.c.
+AC_DEFUN([gl_PREREQ_GETPAGESIZE],
+[
+ AC_CHECK_HEADERS_ONCE([sys/param.h])
+ AC_CHECK_HEADERS([OS.h])
])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index b12f84e..2bc4387 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -32,25 +32,28 @@ AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
AC_DEFUN([gl_UNISTD_H_DEFAULTS],
[
- GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
- GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2])
- GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR])
- GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
- GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
- GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
- GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN])
- GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
- GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
- GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
+ GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
+ GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2])
+ GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR])
+ GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
+ GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
+ GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
+ GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE])
+ GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN])
+ GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
+ GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
+ GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
dnl Assume proper GNU behavior unless another module says otherwise.
- HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
- HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
- HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
- HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
- HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
- REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
- REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR])
- REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
- REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
- REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
+ HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
+ HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
+ HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
+ HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
+ HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
+ HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
+ HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
+ REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
+ REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR])
+ REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
+ REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
+ REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
])
diff --git a/modules/getpagesize b/modules/getpagesize
index 888bb14..9cc4f37 100644
--- a/modules/getpagesize
+++ b/modules/getpagesize
@@ -2,18 +2,20 @@ Description:
getpagesize() function: Return memory page size.
Files:
-lib/getpagesize.h
+lib/getpagesize.c
m4/getpagesize.m4
Depends-on:
+unistd
configure.ac:
-gl_GETPAGESIZE
+gl_FUNC_GETPAGESIZE
+gl_UNISTD_MODULE_INDICATOR([getpagesize])
Makefile.am:
Include:
-"getpagesize.h"
+<unistd.h>
License:
LGPL
diff --git a/modules/unistd b/modules/unistd
index 06156eb..a67908b 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -29,15 +29,18 @@ unistd.h: unistd.in.h
-e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
-e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
-e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
+ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
-e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
-e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
-e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
-e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
-e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
-e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
+ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
-e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
-e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
-e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
+ -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
-e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
-e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
-e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
- Patch for the getpagesize module,
Martin Lambers <=