roken: ROKEN_xxx_ATTRIBUTE macros
authorLuke Howard <lukeh@padl.com>
Sun, 8 Jan 2023 04:54:02 +0000 (15:54 +1100)
committerJeffrey Altman <jaltman@auristor.com>
Mon, 9 Jan 2023 19:09:13 +0000 (14:09 -0500)
Add ROKEN_xxx_ATTRIBUTE macros, derived from krb5-types.h, to aid compiling
with compilers that don't have __attribute__ defined.

lib/roken/roken-common.h
lib/roken/roken.awk
lib/roken/roken.h.in

index 475bb19f5cda1fbb211026efda11b7bad658e76d..906b000336ced27ad27c31b7276af800f2abeb2a 100644 (file)
@@ -509,7 +509,7 @@ free_environment(char **);
 #define warnerr rk_warnerr
 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
 rk_warnerr(int doerrno, const char *fmt, va_list ap)
-    __attribute__ ((__format__ (__printf__, 2, 0)));
+    ROKEN_PRINTF_ATTRIBUTE((__printf__, 2, 0));
 
 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
 rk_realloc(void *, size_t);
@@ -521,7 +521,7 @@ rk_strpoolcollect(struct rk_strpool *);
 
 ROKEN_LIB_FUNCTION struct rk_strpool * ROKEN_LIB_CALL
 rk_strpoolprintf(struct rk_strpool *, const char *, ...)
-    __attribute__ ((__format__ (__printf__, 2, 3)));
+    ROKEN_PRINTF_ATTRIBUTE((__printf__, 2, 3));
 
 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
 rk_strpoolfree(struct rk_strpool *);
index 47313c843af2a1db638cdb1e4fa79e6183dfc21d..00e60f026df9468ebf53bfae25b9449db2fcb94b 100644 (file)
@@ -12,6 +12,14 @@ BEGIN {
        print "#ifdef HAVE_ERRNO_H"
        print "#include <errno.h>"
        print "#endif"
+        print "#if !defined(__has_extension)"
+        print "#define __has_extension(x) 0"
+        print "#endif"
+        print "#ifndef ROKEN_REQUIRE_GNUC"
+        print "#define ROKEN_REQUIRE_GNUC(m,n,p) \\"
+        print "    (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= \\"
+        print "     (((m) * 10000) + ((n) * 100) + (p)))"
+        print "#endif"
        print ""
        print "int main(int argc, char **argv)"
        print "{"
index 9cb8e62f224cc16fe57818cd24b0cb50c0e960d2..c72d259a37a087e82f28830f64897d12d8d91042 100644 (file)
 #  endif
 # endif
 
+#if !defined(__has_extension)
+#define __has_extension(x) 0
+#endif
+
+#ifndef ROKEN_REQUIRE_GNUC
+#define ROKEN_REQUIRE_GNUC(m,n,p) \
+    (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= \
+     (((m) * 10000) + ((n) * 100) + (p)))
+#endif
+
+#ifndef ROKEN_DEPRECATED
+#if __has_extension(deprecated) || ROKEN_REQUIRE_GNUC(3,1,0)
+#define ROKEN_DEPRECATED __attribute__ ((__deprecated__))
+#elif defined(_MSC_VER) && (_MSC_VER>1200)
+#define ROKEN_DEPRECATED __declspec(deprecated)
+#else
+#define ROKEN_DEPRECATED
+#endif
+#endif
+
+#ifndef ROKEN_PRINTF_ATTRIBUTE
+#if __has_extension(format) || ROKEN_REQUIRE_GNUC(3,1,0)
+#define ROKEN_PRINTF_ATTRIBUTE(x) __attribute__ ((__format__ x))
+#else
+#define ROKEN_PRINTF_ATTRIBUTE(x)
+#endif
+#endif
+
+#ifndef ROKEN_NORETURN_ATTRIBUTE
+#if __has_extension(noreturn) || ROKEN_REQUIRE_GNUC(3,1,0)
+#define ROKEN_NORETURN_ATTRIBUTE __attribute__ ((__noreturn__))
+#else
+#define ROKEN_NORETURN_ATTRIBUTE
+#endif
+#endif
+
+#ifndef ROKEN_UNUSED_ATTRIBUTE
+#if __has_extension(unused) || ROKEN_REQUIRE_GNUC(3,1,0)
+#define ROKEN_UNUSED_ATTRIBUTE __attribute__ ((__unused__))
+#else
+#define ROKEN_UNUSED_ATTRIBUTE
+#endif
+#endif
+
+#ifndef ROKEN_WARN_UNUSED_RESULT_ATTRIBUTE
+#if __has_extension(warn_unused_result) || ROKEN_REQUIRE_GNUC(3,3,0)
+#define ROKEN_WARN_UNUSED_RESULT_ATTRIBUTE __attribute__ ((__warn_unused_result__))
+#else
+#define ROKEN_WARN_UNUSED_RESULT_ATTRIBUTE
+#endif
+#endif
+
 #ifdef HAVE_WINSOCK
 /* Declarations for Microsoft Windows */
 
@@ -515,7 +567,7 @@ ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
 #endif
 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
      rk_snprintf (char *, size_t, const char *, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
+     ROKEN_PRINTF_ATTRIBUTE((__printf__, 3, 4));
 #endif
 
 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
@@ -524,7 +576,7 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
 #endif
 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
      rk_vsnprintf (char *, size_t, const char *, va_list)
-     __attribute__ ((__format__ (__printf__, 3, 0)));
+     ROKEN_PRINTF_ATTRIBUTE((__printf__, 3, 0));
 #endif
 
 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
@@ -533,7 +585,7 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
 #endif
 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
      rk_asprintf (char **, const char *, ...)
-     __attribute__ ((__format__ (__printf__, 2, 3)));
+     ROKEN_PRINTF_ATTRIBUTE((__printf__, 2, 3));
 #endif
 
 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
@@ -542,7 +594,7 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
 #endif
 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
     rk_vasprintf (char **, const char *, va_list)
-     __attribute__ ((__format__ (__printf__, 2, 0)));
+    ROKEN_PRINTF_ATTRIBUTE((__printf__, 2, 0));
 #endif
 
 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
@@ -551,7 +603,7 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
 #endif
 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
     rk_asnprintf (char **, size_t, const char *, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
+    ROKEN_PRINTF_ATTRIBUTE((__printf__, 3, 4));
 #endif
 
 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
@@ -560,7 +612,7 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
 #endif
 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
     vasnprintf (char **, size_t, const char *, va_list)
-     __attribute__ ((__format__ (__printf__, 3, 0)));
+    ROKEN_PRINTF_ATTRIBUTE((__printf__, 3, 0));
 #endif
 
 #if !defined(HAVE_EVASPRINTF) || defined(NEED_EVASPRINTF_PROTO)