]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
ext2fs: fix undeclared posix_memalign() warning
authorAndreas Dilger <adilger@whamcloud.com>
Sat, 11 Jun 2011 15:04:42 +0000 (11:04 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 11 Jun 2011 15:04:42 +0000 (11:04 -0400)
Older distros do not define posix_memalign() by default in the
headers.  If ext2fs.h is included early in the headers, it is
possible to "#define _XOPEN_SOURCE 600" so that the stdlib.h
header will define it, but if ext2fs.h is included after stdlib.h
there is no posix_memalign() declaration.

Add a posix_memalign() declaration if stdlib.h didn't do it.  This
is a bit of a hack for GNU headers, but it works on Linux and OS/X
without problems.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2fs.h

index 889c77163de1b96b52e83f2cba6a03241559efac..b0e73b650b2dbc43ab411ea93999ebc45123470a 100644 (file)
@@ -29,6 +29,10 @@ extern "C" {
 #define NO_INLINE_FUNCS
 #endif
 
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE 600      /* for posix_memalign() */
+#endif
+
 /*
  * Where the master copy of the superblock is located, and how big
  * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
@@ -37,7 +41,7 @@ extern "C" {
  * 1032 bytes long).
  */
 #define SUPERBLOCK_OFFSET      1024
-#define SUPERBLOCK_SIZE        1024
+#define SUPERBLOCK_SIZE                1024
 
 /*
  * The last ext2fs revision level that this version of the library is
@@ -54,6 +58,13 @@ extern "C" {
 #include <string.h>
 #include <errno.h>
 
+#ifndef __USE_XOPEN2K
+/* If the "#define _XOPEN_SOURCE 600" didn't succeed in declaring
+ * posix_memalign(), maybe due to <features.h> or <stdlib.h> included beforej
+ * _XOPEN_SOURCE, declare it here to avoid compiler warnings. */
+extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
+#endif
+
 #if EXT2_FLAT_INCLUDES
 #include "e2_types.h"
 #include "ext2_fs.h"