Whamcloud - gitweb
libext2fs: allow ext2fs_get_memalign() to compile w/o posix_memalign()
authorTheodore Ts'o <tytso@mit.edu>
Mon, 17 Oct 2011 01:50:26 +0000 (21:50 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 17 Oct 2011 01:50:26 +0000 (21:50 -0400)
Addresses-Sourceforge-Bug: #3219173

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/inline.c

index 57c5bfa..d90c1ee 100644 (file)
@@ -1479,22 +1479,6 @@ _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
        return 0;
 }
 
-_INLINE_ errcode_t ext2fs_get_memalign(unsigned long size,
-                                      unsigned long align, void *ptr)
-{
-       errcode_t retval;
-
-       if (align == 0)
-               align = 8;
-       retval = posix_memalign((void **) ptr, align, size);
-       if (retval) {
-               if (retval == ENOMEM)
-                       return EXT2_ET_NO_MEMORY;
-               return retval;
-       }
-       return 0;
-}
-
 _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
 {
        void *pp;
index 02deda1..d786937 100644 (file)
 #define INCLUDE_INLINE_FUNCS
 #include "ext2fs.h"
 
+/*
+ * We used to define this as an inline, but since we are now using
+ * autoconf-defined #ifdef's, we need to export this as a
+ * library-provided function exclusively.
+ */
+errcode_t ext2fs_get_memalign(unsigned long size,
+                             unsigned long align, void *ptr)
+{
+       errcode_t retval;
+
+       if (align == 0)
+               align = 8;
+#ifdef HAVE_POSIX_MEMALIGN
+       retval = posix_memalign((void **) ptr, align, size);
+       if (retval) {
+               if (retval == ENOMEM)
+                       return EXT2_ET_NO_MEMORY;
+               return retval;
+       }
+#else
+#ifdef HAVE_MEMALIGN
+       *ptr = memalign(align, size);
+       if (*ptr == NULL) {
+               if (errno)
+                       return errno;
+               else
+                       return EXT2_ET_NO_MEMORY;
+       }
+#else
+#error memalign or posix_memalign must be defined!
+#endif
+#endif
+       return 0;
+}
+