summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-05-24 10:03:20 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:12:02 +0100
commit810841e1b944bb034ddef854e916e4bf4aab3b45 (patch)
tree175c113be8832c2cc1ec6845d1e0d11fa3d0da20
parent19be1beffb857b32c77adf1d993beb61b3c99b82 (diff)
Added afb-helpers-utils.h
Added this file to some useful macros, the first one here is INT_STR_MAX that permits to get rid of a warning with gcc >= 7.2.0 Change-Id: I768d216ab5494d346d5ee6e0df66f93410bfab57 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
-rw-r--r--afb-helpers-utils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/afb-helpers-utils.h b/afb-helpers-utils.h
new file mode 100644
index 0000000..d180f08
--- /dev/null
+++ b/afb-helpers-utils.h
@@ -0,0 +1,17 @@
+#ifndef AFB_HELPERS_UTILS_H
+#define AFB_HELPERS_UTILS_H
+
+#include <limits.h>
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+/* with gcc >= 7.2.0, this macro is useful when printing an int with snprintf:
+ *
+ * char[INT_STR_MAX]; // smaller value leads to a warning
+ * snprintf(targetS, sizeof (targetS), "%d", target);
+ * */
+
+#define INT_STR_MAX sizeof(xstr(INT_MAX))
+
+#endif /* AFB_HELPERS_UTILS_H */