From: Andreas Dilger <adilger@whamcloud.com>
To: tytso@mit.edu, linux-ext4@vger.kernel.org
Cc: Andreas Dilger <adilger@whamcloud.com>
Subject: [PATCH] ext2fs: fix undeclared posix_memalign() warning
Date: Thu, 9 Jun 2011 23:17:16 -0600 [thread overview]
Message-ID: <1307683036-4564-1-git-send-email-adilger@whamcloud.com> (raw)
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>
---
lib/ext2fs/ext2fs.h | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 9acccf2..975ab9d 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -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"
--
1.7.3.4
next reply other threads:[~2011-06-10 5:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-10 5:17 Andreas Dilger [this message]
2011-06-11 15:05 ` [PATCH] ext2fs: fix undeclared posix_memalign() warning Ted Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1307683036-4564-1-git-send-email-adilger@whamcloud.com \
--to=adilger@whamcloud.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).