git » libfiu » commit 4d48770

preload/posix: Use limits.h instead of features.h for portability reasons

author Alberto Bertogli
2010-10-17 01:57:49 UTC
committer Alberto Bertogli
2010-10-17 01:57:49 UTC
parent ddd73f0c12197fc3361db4c6fe548d55191b57f0

preload/posix: Use limits.h instead of features.h for portability reasons

We want to know if we're building against glibc. glibc defines __GLIBC__ for
those purposes, and to get it defined we must include features.h.

The problem is features.h is NOT standard, and not available on some
platforms.

So we include limits.h, because we know it includes features.h, and we get the
define indirectly.

This is UGLY but sadly the other choices are not much more attractive. This
may get better if we used some script like autotools to detect features.h
availability, and we may do that in the future.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

preload/posix/modules/libc.mm.custom.c +7 -1

diff --git a/preload/posix/modules/libc.mm.custom.c b/preload/posix/modules/libc.mm.custom.c
index 9878ea3..4ed23e7 100644
--- a/preload/posix/modules/libc.mm.custom.c
+++ b/preload/posix/modules/libc.mm.custom.c
@@ -8,7 +8,13 @@
  * We use __malloc_hook, the glibc-specific interface, so this is glibc-only.
  */
 
-#include <features.h>
+/* We need to include features.h, which in turns defines __GLIBC__. However,
+ * features.h is glibc-specific and does not exist on other platforms, so we
+ * can't include it directly or the file won't build.
+ * Instead, we have to resort to this ugly trick of including limits.h, which
+ * is standard and we know glibc's implementation includes features.h.
+ */
+#include <limits.h>
 
 #ifndef __GLIBC__
   #warning "Not using glibc, so no malloc() wrappers will be available"