aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-09-28 15:13:04 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-09-28 15:13:04 +0200
commitabfa3ec0598ff431407224c6b81682f7d0d35495 (patch)
treee5387999595e1f0c383c4aced38fe5a24dd90ef0 /include
parentaae428f0bf0fcd6cd0a2503b3a50de43785b8fd0 (diff)
downloadbusybox-abfa3ec0598ff431407224c6b81682f7d0d35495.tar.gz
move storage helpers to libbb.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 7cad12c44..61fa1e03e 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2127,6 +2127,23 @@ extern const char bb_default_login_shell[] ALIGN1;
# define FB_0 "/dev/fb0"
#endif
+// storage helpers for mk*fs utilities
+char BUG_wrong_field_size(void);
+#define STORE_LE(field, value) \
+do { \
+ if (sizeof(field) == 4) \
+ field = SWAP_LE32((uint32_t)(value)); \
+ else if (sizeof(field) == 2) \
+ field = SWAP_LE16((uint16_t)(value)); \
+ else if (sizeof(field) == 1) \
+ field = (uint8_t)(value); \
+ else \
+ BUG_wrong_field_size(); \
+} while (0)
+
+#define FETCH_LE32(field) \
+ (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size())
+
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))