summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-16 05:04:53 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-16 05:04:53 +0200
commit82da66fb750c91f06e713ff23a5e5c57ff05c2a8 (patch)
treed36730ca6eaca931106b96a90bced84651ce0bf5 /src/shared/util.h
parentd8d3d8a781031d6b1ee4e5f57ec21f16c20a4cf2 (diff)
util: replace decimal_str_max() by a typesafe macro DECIMAL_STR_WIDTH()
DECIMAL_STR_WIDTH() now works on any numeric type, and is easier to distingish from DECIMAL_STR_MAX(). This also replaces another manual implementaiton of ulog10 by this macro.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index b33fdb5b7a..683ff5a4fe 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -649,19 +649,21 @@ static inline bool logind_running(void) {
return access("/run/systemd/seats/", F_OK) >= 0;
}
-static inline unsigned decimal_str_max(unsigned x) {
- unsigned ans = 1;
- while (x /= 10)
- ans ++;
- return ans;
-}
+#define DECIMAL_STR_WIDTH(x) \
+ ({ \
+ typeof(x) _x_ = (x); \
+ unsigned ans = 1; \
+ while (_x_ /= 10) \
+ ans++; \
+ ans; \
+ })
int unlink_noerrno(const char *path);
-#define alloca0(n) \
- ({ \
- char *__new; \
- size_t __len = n; \
- __new = alloca(__len); \
- (void *) memset(__new, 0, __len); \
+#define alloca0(n) \
+ ({ \
+ char *_new_; \
+ size_t _len_ = n; \
+ _new_ = alloca(_len_); \
+ (void *) memset(_new_, 0, _len_); \
})