summaryrefslogtreecommitdiff
path: root/tools-util.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2017-05-05 00:27:01 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2017-05-05 00:27:50 -0800
commite004b95b88ae95cf7bb26bd7dc80c5dcf2b2664a (patch)
treebfa21c820a15686c5dd93293d38dfb8f19cdd46c /tools-util.h
parent5db58a0baee8e732b9dc8a90dd4a739253e758a5 (diff)
fix sync writes - don't use O_EXCL
Diffstat (limited to 'tools-util.h')
-rw-r--r--tools-util.h75
1 files changed, 8 insertions, 67 deletions
diff --git a/tools-util.h b/tools-util.h
index 8f4e3d73..0b73b283 100644
--- a/tools-util.h
+++ b/tools-util.h
@@ -17,57 +17,14 @@
#include <linux/types.h>
#include "ccan/darray/darray.h"
-#define die(arg, ...) \
-do { \
- fprintf(stderr, arg "\n", ##__VA_ARGS__); \
- exit(EXIT_FAILURE); \
-} while (0)
-
-#define mprintf(...) \
-({ \
- char *_str; \
- int ret = asprintf(&_str, __VA_ARGS__); \
- if (ret < 0) \
- die("insufficient memory"); \
- _str; \
-})
-
-static inline void *xcalloc(size_t count, size_t size)
-{
- void *p = calloc(count, size);
-
- if (!p)
- die("insufficient memory");
-
- return p;
-}
-
-static inline void *xmalloc(size_t size)
-{
- void *p = malloc(size);
-
- if (!p)
- die("insufficient memory");
-
- memset(p, 0, size);
- return p;
-}
-
-static inline void xpread(int fd, void *buf, size_t count, off_t offset)
-{
- ssize_t r = pread(fd, buf, count, offset);
-
- if (r != count)
- die("read error (ret %zi)", r);
-}
-
-static inline void xpwrite(int fd, const void *buf, size_t count, off_t offset)
-{
- ssize_t r = pwrite(fd, buf, count, offset);
-
- if (r != count)
- die("write error (ret %zi err %m)", r);
-}
+void die(const char *, ...);
+char *mprintf(const char *, ...);
+void *xcalloc(size_t, size_t);
+void *xmalloc(size_t);
+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);
#define xopenat(_dirfd, _path, ...) \
({ \
@@ -79,22 +36,6 @@ static inline void xpwrite(int fd, const void *buf, size_t count, off_t offset)
#define xopen(...) xopenat(AT_FDCWD, __VA_ARGS__)
-static inline struct stat xfstatat(int dirfd, const char *path, int flags)
-{
- struct stat stat;
- if (fstatat(dirfd, path, &stat, flags))
- die("stat error: %m");
- return stat;
-}
-
-static inline struct stat xfstat(int fd)
-{
- struct stat stat;
- if (fstat(fd, &stat))
- die("stat error: %m");
- return stat;
-}
-
#define xioctl(_fd, _nr, ...) \
do { \
if (ioctl((_fd), (_nr), ##__VA_ARGS__)) \