[sheepdog] [PATCH 4/5] add helper attribute __printf

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Feb 22 01:38:41 CET 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/logger.h  |    4 +++-
 include/strbuf.h  |    5 ++---
 include/util.h    |    3 ++-
 lib/logger.c      |    2 +-
 sheepfs/core.c    |    4 ++--
 sheepfs/sheepfs.h |    2 +-
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/logger.h b/include/logger.h
index 2e10f6a..a8c558a 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -17,6 +17,8 @@
 #include <stdbool.h>
 #include <sys/syslog.h>
 
+#include "util.h"
+
 #define LOG_SPACE_SIZE (32 * 1024 * 1024)
 #define MAX_MSG_SIZE 1024
 #define MAX_THREAD_NAME_LEN	20
@@ -32,7 +34,7 @@ int log_init(const char *progname, int size, bool to_stdout, int level,
 void log_close(void);
 void dump_logmsg(void *);
 void log_write(int prio, const char *func, int line, const char *fmt, ...)
-	__attribute__ ((format (printf, 4, 5)));
+	__printf(4, 5);
 void set_thread_name(const char *name, int idx);
 void get_thread_name(char *name);
 
diff --git a/include/strbuf.h b/include/strbuf.h
index 605e861..1500afc 100644
--- a/include/strbuf.h
+++ b/include/strbuf.h
@@ -7,7 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "util.h"
+#include "logger.h"
 
 struct strbuf {
 	size_t alloc;
@@ -88,8 +88,7 @@ static inline void strbuf_addbuf(struct strbuf *sb, struct strbuf *sb2)
 	strbuf_add(sb, sb2->buf, sb2->len);
 }
 
-__attribute__((format(printf, 2, 3)))
-void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
+void strbuf_addf(struct strbuf *sb, const char *fmt, ...) __printf(2, 3);
 
 size_t strbuf_fread(struct strbuf *, size_t, FILE *);
 /* XXX: if read fails, any partial read is undone */
diff --git a/include/util.h b/include/util.h
index 7776225..d1b2e41 100644
--- a/include/util.h
+++ b/include/util.h
@@ -12,7 +12,6 @@
 
 #include "bitops.h"
 #include "list.h"
-#include "logger.h"
 
 #define SECTOR_SIZE (1U << 9)
 
@@ -40,6 +39,8 @@
 #define notrace __attribute__((no_instrument_function))
 #define __packed __attribute((packed))
 
+#define __printf(a, b)                  __attribute__((format(printf, a, b)))
+
 #define uninitialized_var(x) (x = x)
 
 static inline int before(uint32_t seq1, uint32_t seq2)
diff --git a/lib/logger.c b/lib/logger.c
index 987379d..5164acf 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -39,7 +39,7 @@
 struct logger_user_info *logger_user_info;
 
 static void dolog(int prio, const char *func, int line, const char *fmt,
-		  va_list ap) __attribute__ ((format (printf, 4, 0)));
+		  va_list ap) __printf(4, 0);
 
 union semun {
 	int val;
diff --git a/sheepfs/core.c b/sheepfs/core.c
index fdb0f97..b232429 100644
--- a/sheepfs/core.c
+++ b/sheepfs/core.c
@@ -78,7 +78,7 @@ static struct sheepfs_file_operation {
 				volume_sync, volume_open },
 };
 
-__attribute__ ((format (__printf__, 3, 4)))
+__printf(3, 4)
 static void fg_printf(const char *func, int line, const char *fmt, ...)
 {
 	va_list ap;
@@ -89,7 +89,7 @@ static void fg_printf(const char *func, int line, const char *fmt, ...)
 	va_end(ap);
 }
 
-__attribute__ ((format (__printf__, 3, 4)))
+__printf(3, 4)
 static void bg_printf(const char *func, int line, const char *fmt, ...)
 {
 	va_list ap;
diff --git a/sheepfs/sheepfs.h b/sheepfs/sheepfs.h
index 0f855de..cfd2cad 100644
--- a/sheepfs/sheepfs.h
+++ b/sheepfs/sheepfs.h
@@ -29,7 +29,7 @@ struct strbuf *sheepfs_run_cmd(const char *command);
 int sheepfs_set_op(const char *path, unsigned opcode);
 
 typedef void (*printf_fn)(const char *func, int line, const char *, ...)
-__attribute__ ((format (__printf__, 3, 4)));
+	__printf(3, 4);
 
 extern printf_fn fs_printf;
 
-- 
1.7.9.5




More information about the sheepdog mailing list