# HG changeset patch # User Matti Hamalainen # Date 1578587268 -7200 # Node ID 70d44ba005aced57e50d414572736dbdab767ac4 # Parent e4ae9ef86332d675285f5260ff06e96bb63bfa32 Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3))) TH_ATTR_PRINTF_FMT(2, 3) and use it, conditionally using a stub for MINGW64 to avoid "useless" warnings. diff -r e4ae9ef86332 -r 70d44ba005ac th_ioctx.h --- a/th_ioctx.h Thu Jan 09 18:17:48 2020 +0200 +++ b/th_ioctx.h Thu Jan 09 18:27:48 2020 +0200 @@ -90,9 +90,9 @@ int th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap); void th_io_msg_v(th_ioctx *ctx, const int level, const char *fmt, va_list ap); int th_io_error(th_ioctx *ctx, const int err, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); + TH_ATTR_PRINTF_FMT(3, 4); void th_io_msg(th_ioctx *ctx, const int level, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); + TH_ATTR_PRINTF_FMT(3, 4); // @@ -112,7 +112,7 @@ int thfputs(const char *ptr, th_ioctx *ctx); int thvfprintf(th_ioctx *ctx, const char *fmt, va_list ap); int thfprintf(th_ioctx *ctx, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + TH_ATTR_PRINTF_FMT(2, 3); int thfread_str(th_ioctx *ctx, void *ptr, const size_t len); BOOL thfread_u8(th_ioctx *ctx, uint8_t *); diff -r e4ae9ef86332 -r 70d44ba005ac th_network.h --- a/th_network.h Thu Jan 09 18:17:48 2020 +0200 +++ b/th_network.h Thu Jan 09 18:27:48 2020 +0200 @@ -10,9 +10,8 @@ #include #include -#include "th_types.h" +#include "th_util.h" #include "th_datastruct.h" -#include "th_util.h" #ifdef TH_PLAT_WINDOWS @@ -142,9 +141,9 @@ ssize_t bufsize); void th_conn_err(th_conn_t *conn, int err, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); + TH_ATTR_PRINTF_FMT(3, 4); void th_conn_msg(th_conn_t *conn, int loglevel, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); + TH_ATTR_PRINTF_FMT(3, 4); int th_conn_set_proxy(th_conn_t *conn, int type, int port, const char *host, int auth_type); int th_conn_set_proxy_mode(th_conn_t *conn, const int mode); diff -r e4ae9ef86332 -r 70d44ba005ac th_string.h --- a/th_string.h Thu Jan 09 18:17:48 2020 +0200 +++ b/th_string.h Thu Jan 09 18:27:48 2020 +0200 @@ -105,19 +105,19 @@ int th_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap); int th_snprintf(char *buf, size_t size, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); + TH_ATTR_PRINTF_FMT(3, 4); int th_vfprintf(FILE *fh, const char *fmt, va_list ap); int th_fprintf(FILE *fh, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + TH_ATTR_PRINTF_FMT(2, 3); char *th_strdup_vprintf(const char *fmt, va_list ap); char *th_strdup_printf(const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + TH_ATTR_PRINTF_FMT(1, 2); void th_pstr_vprintf(char **buf, const char *fmt, va_list ap); void th_pstr_printf(char **buf, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + TH_ATTR_PRINTF_FMT(2, 3); int th_pstr_cpy(char **pdst, const char *src); int th_pstr_cat(char **pdst, const char *src); diff -r e4ae9ef86332 -r 70d44ba005ac th_util.h --- a/th_util.h Thu Jan 09 18:17:48 2020 +0200 +++ b/th_util.h Thu Jan 09 18:27:48 2020 +0200 @@ -40,6 +40,15 @@ #endif +// Kludge, as MinGW64 cross-compiler does not like certain +// printf( +#if defined(__MINGW64__) +# define TH_ATTR_PRINTF_FMT(xstart, xend) +#else +# define TH_ATTR_PRINTF_FMT(xstart, xend) __attribute__ ((__format__ (__printf__, (xstart), (xend)))) +#endif + + // Replacement for assert() #ifdef HAVE_NO_ASSERT # ifdef NDEBUG @@ -125,11 +134,11 @@ const char *th_error_str(int error); void THERR(const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + TH_ATTR_PRINTF_FMT(1, 2); void THMSG(int level, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + TH_ATTR_PRINTF_FMT(2, 3); void THPRINT(int level, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + TH_ATTR_PRINTF_FMT(2, 3); void THERR_V(const char *fmt, va_list ap); void THMSG_V(int level, const char *fmt, va_list ap);