[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [RFC/PATCH v2 2/5] libbb: add DECIMAL_STR_MAX macro
From:       Bartosz Golaszewski <bartekgola () gmail ! com>
Date:       2015-08-21 14:23:40
Message-ID: 1440167023-31099-3-git-send-email-bartekgola () gmail ! com
[Download RAW message or body]

Add a macro returning the maximum required buffer size for given
integer type.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
---
 include/libbb.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/libbb.h b/include/libbb.h
index 478c030..a56b684 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -225,6 +225,13 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
 	: ((T)1 << (sizeof(T)*8-1)) \
 	)
 
+/* Found in systemd, src/basic/macro.h */
+#define DECIMAL_STR_MAX(type) \
+	(2+(sizeof(type) <= 1 ? 3 : \
+	sizeof(type) <= 2 ? 5 : \
+	sizeof(type) <= 4 ? 10 : \
+	sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
+
 /* Large file support */
 /* Note that CONFIG_LFS=y forces bbox to be built with all common ops
  * (stat, lseek etc) mapped to "largefile" variants by libc.
-- 
2.1.4

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic