From 16b0fea8ae1a581d568dbee2efa2932aa4e6fcce Mon Sep 17 00:00:00 2001 Message-Id: <16b0fea8ae1a581d568dbee2efa2932aa4e6fcce.1715497414.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 22 Dec 2013 11:17:42 +0000 Subject: [PATCH] disorder.h: more consistent approach to function attributes Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/disorder.h | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/disorder.h b/lib/disorder.h index cb0c070..9fde2d8 100644 --- a/lib/disorder.h +++ b/lib/disorder.h @@ -25,6 +25,12 @@ extern "C" { #endif +#ifdef __GNUC__ +# define DISORDER_IFGNUC(x) x +#else +# define DISORDER_IFGNUC(x) +#endif + /* memory allocation **********************************************************/ void *disorder_malloc(size_t); @@ -47,34 +53,24 @@ char *disorder_strndup(const char *, size_t); * {xmalloc,xrealloc}_noptr don't promise to clear the new space */ -#ifdef __GNUC__ - int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...) - __attribute__((format (printf, 3, 4))); + DISORDER_IFGNUC(__attribute__((format (printf, 3, 4)))); /* like snprintf */ int disorder_asprintf(char **rp, const char *fmt, ...) - __attribute__((format (printf, 2, 3))); -/* like asprintf but uses xmalloc_noptr() */ - -#else - -int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...); -/* like snprintf */ - -int disorder_asprintf(char **rp, const char *fmt, ...); + DISORDER_IFGNUC(__attribute__((format (printf, 2, 3)))); /* like asprintf but uses xmalloc_noptr() */ -#endif - - /* logging ********************************************************************/ -void disorder_error(int errno_value, const char *fmt, ...); +void disorder_error(int errno_value, const char *fmt, ...) + DISORDER_IFGNUC(__attribute__((format (printf, 2, 3)))); /* report an error. If errno_value is nonzero then the errno string * is included. */ -void disorder_fatal(int errno_value, const char *fmt, ...); +void disorder_fatal(int errno_value, const char *fmt, ...) + DISORDER_IFGNUC(__attribute__((noreturn)) + __attribute__((format (printf, 2, 3)))); /* report an error and terminate. If errno_value is nonzero then the * errno string is included. This is the only safe way to terminate * the process. */ -- [mdw]