chiark / gitweb /
util: replace decimal_str_max() by a typesafe macro DECIMAL_STR_WIDTH()
[elogind.git] / src / shared / util.h
index 99ec0a39bdc4ee1212d4f6aec5ab974c3468d4a9..683ff5a4fe03e4af1f8e6de4c2b672876b6c3511 100644 (file)
@@ -52,7 +52,7 @@ union dirent_storage {
 #define WHITESPACE " \t\n\r"
 #define NEWLINE "\n\r"
 #define QUOTES "\"\'"
-#define COMMENTS "#;\n"
+#define COMMENTS "#;"
 
 #define FORMAT_BYTES_MAX 8
 
@@ -649,11 +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_);       \
+        })