]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include: [c.h] add fallback for alloc_size attributes
authorKarel Zak <kzak@redhat.com>
Mon, 7 Feb 2011 16:29:47 +0000 (17:29 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Feb 2011 16:29:47 +0000 (17:29 +0100)
Reported-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/c.h
include/xalloc.h

index 02c29e960a00d9b7f66734deac06a4a5a94f6064..f50a338c9c9af30a916ceb2fef89c5719aa960a6 100644 (file)
 /*
  * Compiler specific stuff
  */
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+#  define __GNUC_PREREQ(maj, min) \
+       ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+#  define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
 #ifdef __GNUC__
 
 /* &a[0] degrades to a pointer: a different type from an array */
 # define ignore_result(x) ((void) (x))
 #endif /* !__GNUC__ */
 
+/*
+ * Function attributes
+ */
+#ifndef __ul_alloc_size
+# if __GNUC_PREREQ (3, 0)
+#  define __ul_alloc_size(s) __attribute__((alloc_size(s)))
+# else
+#  define __ul_alloc_size(s)
+# endif
+#endif
+
+#ifndef __ul_calloc_size
+# if __GNUC_PREREQ (3, 0)
+#  define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s)))
+# else
+#  define __ul_calloc_size(n, s)
+# endif
+#endif
 
 /* Force a compilation error if condition is true, but also produce a
  * result (of value 0 and type size_t), so the expression can be used
index fc2f886dd239ecaf123c6b4063fd81c6d7a7f05b..27efa30c58aadcd68e8f5618612a5815265ce9e0 100644 (file)
 #include <stdlib.h>
 #include <err.h>
 
+#include "c.h"
+
 #ifndef XALLOC_EXIT_CODE
 # define XALLOC_EXIT_CODE EXIT_FAILURE
 #endif
 
-static inline __attribute__((alloc_size(1)))
+static inline __ul_alloc_size(1)
 void *xmalloc(const size_t size)
 {
         void *ret = malloc(size);
@@ -27,7 +29,7 @@ void *xmalloc(const size_t size)
         return ret;
 }
 
-static inline __attribute__((alloc_size(2)))
+static inline __ul_alloc_size(2)
 void *xrealloc(void *ptr, const size_t size)
 {
         void *ret = realloc(ptr, size);
@@ -37,7 +39,7 @@ void *xrealloc(void *ptr, const size_t size)
         return ret;
 }
 
-static inline __attribute__((alloc_size(1,2)))
+static inline __ul_calloc_size(1, 2)
 void *xcalloc(const size_t nelems, const size_t size)
 {
         void *ret = calloc(nelems, size);