]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - tools-util.h
Fix building on musl
[bcachefs-tools-debian] / tools-util.h
index dcca376b8e4a80925514eda482d6e1c0041d20df..e5c3508474b9431c60a6d63de59cce99965b4e45 100644 (file)
@@ -2,6 +2,7 @@
 #define _TOOLS_UTIL_H
 
 #include <errno.h>
+#include <mntent.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -20,7 +21,8 @@
 #include "ccan/darray/darray.h"
 
 void die(const char *, ...);
-char *mprintf(const char *, ...);
+char *mprintf(const char *, ...)
+       __attribute__ ((format (printf, 1, 2)));
 void *xcalloc(size_t, size_t);
 void *xmalloc(size_t);
 void *xrealloc(void *, size_t);
@@ -28,6 +30,7 @@ void xpread(int, void *, size_t, off_t);
 void xpwrite(int, const void *, size_t, off_t);
 struct stat xfstatat(int, const char *, int);
 struct stat xfstat(int);
+struct stat xstat(const char *);
 
 #define xopenat(_dirfd, _path, ...)                                    \
 ({                                                                     \
@@ -47,6 +50,8 @@ struct stat xfstat(int);
        _ret;                                                           \
 })
 
+int printf_pad(unsigned pad, const char * fmt, ...);
+
 enum units {
        BYTES,
        SECTORS,
@@ -141,7 +146,7 @@ struct fiemap_extent fiemap_iter_next(struct fiemap_iter *);
        for (fiemap_iter_init(&iter, fd);                               \
             (extent = fiemap_iter_next(&iter)).fe_length;)
 
-const char *strcmp_prefix(const char *, const char *);
+char *strcmp_prefix(char *, const char *);
 
 unsigned hatoi_validate(const char *, const char *);
 
@@ -149,6 +154,22 @@ u32 crc32c(u32, const void *, size_t);
 
 char *dev_to_name(dev_t);
 char *dev_to_path(dev_t);
-char *dev_to_mount(char *);
+struct mntent *dev_to_mount(char *);
+bool dev_mounted_rw(char *);
+
+#define args_shift(_nr)                                                        \
+do {                                                                   \
+       unsigned _n = min((_nr), argc);                                 \
+       argc -= _n;                                                     \
+       argv += _n;                                                     \
+} while (0)
+
+#define arg_pop()                                                      \
+({                                                                     \
+       char *_ret = argc ? argv[0] : NULL;                             \
+       if (_ret)                                                       \
+               args_shift(1);                                          \
+       _ret;                                                           \
+})
 
 #endif /* _TOOLS_UTIL_H */