Mercurial > hg > th-libs
changeset 577:70d44ba005ac
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.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 09 Jan 2020 18:27:48 +0200 |
parents | e4ae9ef86332 |
children | ac2947ac9ef8 |
files | th_ioctx.h th_network.h th_string.h th_util.h |
diffstat | 4 files changed, 22 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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 *);
--- 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 <stdio.h> #include <unistd.h> -#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);
--- 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);
--- 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);