--- configure.works	Wed Jan 25 18:21:48 2006
+++ configure.in	Wed Jan 25 18:47:40 2006
@@ -523,7 +523,6 @@
 AC_FUNC_VPRINTF
 AC_FUNC_MMAP
 AC_FUNC_ALLOCA
-AC_CHECK_FUNCS(posix_memalign)
 AC_CHECK_FUNCS(memalign)
 AC_CHECK_FUNCS(valloc)
 
@@ -1023,42 +1022,45 @@
 dnl ****************************************
 dnl *** posix_memalign                   ***
 dnl ****************************************
-AC_MSG_CHECKING(for a compliant posix_memalign() implementation)
-AC_CACHE_VAL(glib_cv_compliant_posix_memalign,[
-    glib_cv_compliant_posix_memalign=0
-    if test "$ac_cv_func_posix_memalign" = "yes" ; then
-	AC_TRY_RUN([
-                #define _XOPEN_SOURCE 600
-                #include <stdlib.h>
-                #include <malloc.h>
-		static void test_memalign (size_t boundary, size_t size) {
-		    void *mem = 0;
-		    if (posix_memalign (&mem, boundary, size) != 0 || !mem)
-			exit (1);
-		}
-		int main() {
-		    test_memalign (  128,   128 - 2 * sizeof (void*));
-		    test_memalign (  256,   256 - 2 * sizeof (void*));
-		    test_memalign (  512,   512 - 2 * sizeof (void*));
-		    test_memalign ( 1024,  1024 - 2 * sizeof (void*));
-		    test_memalign ( 2048,  2048 - 2 * sizeof (void*));
-		    test_memalign ( 4096,  4096 - 2 * sizeof (void*));
-		    test_memalign ( 8192,  8192 - 2 * sizeof (void*));
-		    test_memalign (16384, 16384 - 2 * sizeof (void*));
-		    test_memalign (32768, 32768 - 2 * sizeof (void*));
-		    exit (0); /* success */
-		}
-		],
-	    [glib_cv_compliant_posix_memalign=1], [], [:])
-      :
-    fi
+dnl glibc 2.2.2 is known to enforce bogus size restrictions
+AC_CHECK_FUNC([posix_memalign],
+    AC_MSG_CHECKING(whether posix_memalign actually works)
+    AC_CACHE_VAL(glib_cv_compliant_posix_memalign,[
+        glib_cv_compliant_posix_memalign=0
+        AC_TRY_RUN([
+            #define _XOPEN_SOURCE 600
+            #include <stdlib.h>
+            #include <malloc.h>
+            static void test_memalign (size_t boundary, size_t size) {
+                void *mem = 0;
+                if (posix_memalign (&mem, boundary, size) != 0 || !mem)
+                    exit (1);
+                else free(mem);
+            }
+            int main() {
+                test_memalign (  128,   128 - 2 * sizeof (void*));
+                test_memalign (  256,   256 - 2 * sizeof (void*));
+                test_memalign (  512,   512 - 2 * sizeof (void*));
+                test_memalign ( 1024,  1024 - 2 * sizeof (void*));
+                test_memalign ( 2048,  2048 - 2 * sizeof (void*));
+                test_memalign ( 4096,  4096 - 2 * sizeof (void*));
+                test_memalign ( 8192,  8192 - 2 * sizeof (void*));
+                test_memalign (16384, 16384 - 2 * sizeof (void*));
+                test_memalign (32768, 32768 - 2 * sizeof (void*));
+                exit (0); /* success */
+           }
+        ],
+        [glib_cv_compliant_posix_memalign=1], [], [:])
+        :
     ])
-if test "$glib_cv_compliant_posix_memalign" = "1"; then
-    AC_MSG_RESULT(yes)
-    AC_DEFINE(POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS, 1, [define if posix_memalign() can allocate any size])
-else
-    AC_MSG_RESULT(no)
-fi
+    if test "$glib_cv_compliant_posix_memalign" = "1"; then
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_POSIX_MEMALIGN, 1,
+            [Define to 1 if posix_memalign is available and can allocate any size])
+    else
+        AC_MSG_RESULT(no)
+    fi
+)
 
 
 dnl ****************************************
