diff --git a/lib/roken/roken-common.h b/lib/roken/roken-common.h index 475bb19f5..906b00033 100644 --- a/lib/roken/roken-common.h +++ b/lib/roken/roken-common.h @@ -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 *); diff --git a/lib/roken/roken.awk b/lib/roken/roken.awk index 47313c843..00e60f026 100644 --- a/lib/roken/roken.awk +++ b/lib/roken/roken.awk @@ -12,6 +12,14 @@ BEGIN { print "#ifdef HAVE_ERRNO_H" print "#include " 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 "{" diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index 9cb8e62f2..c72d259a3 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -96,6 +96,58 @@ # 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)