mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
make allocator helpers inlines
this gets us better log messages when using -fsanitize=address Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
5fa4e3da62
commit
2b28e8f7d2
30
tools-util.c
30
tools-util.c
@ -51,36 +51,6 @@ char *mprintf(const char *fmt, ...)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *xcalloc(size_t count, size_t size)
|
|
||||||
{
|
|
||||||
void *p = calloc(count, size);
|
|
||||||
|
|
||||||
if (!p)
|
|
||||||
die("insufficient memory");
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *xmalloc(size_t size)
|
|
||||||
{
|
|
||||||
void *p = malloc(size);
|
|
||||||
|
|
||||||
if (!p)
|
|
||||||
die("insufficient memory");
|
|
||||||
|
|
||||||
memset(p, 0, size);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *xrealloc(void *p, size_t size)
|
|
||||||
{
|
|
||||||
p = realloc(p, size);
|
|
||||||
if (!p)
|
|
||||||
die("insufficient memory");
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void xpread(int fd, void *buf, size_t count, off_t offset)
|
void xpread(int fd, void *buf, size_t count, off_t offset)
|
||||||
{
|
{
|
||||||
while (count) {
|
while (count) {
|
||||||
|
33
tools-util.h
33
tools-util.h
@ -28,15 +28,42 @@ void die(const char *, ...)
|
|||||||
__attribute__ ((format (printf, 1, 2))) noreturn;
|
__attribute__ ((format (printf, 1, 2))) noreturn;
|
||||||
char *mprintf(const char *, ...)
|
char *mprintf(const char *, ...)
|
||||||
__attribute__ ((format (printf, 1, 2)));
|
__attribute__ ((format (printf, 1, 2)));
|
||||||
void *xcalloc(size_t, size_t);
|
|
||||||
void *xmalloc(size_t);
|
|
||||||
void *xrealloc(void *, size_t);
|
|
||||||
void xpread(int, void *, size_t, off_t);
|
void xpread(int, void *, size_t, off_t);
|
||||||
void xpwrite(int, const void *, size_t, off_t, const char *);
|
void xpwrite(int, const void *, size_t, off_t, const char *);
|
||||||
struct stat xfstatat(int, const char *, int);
|
struct stat xfstatat(int, const char *, int);
|
||||||
struct stat xfstat(int);
|
struct stat xfstat(int);
|
||||||
struct stat xstat(const char *);
|
struct stat xstat(const char *);
|
||||||
|
|
||||||
|
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 *xcalloc(size_t count, size_t size)
|
||||||
|
{
|
||||||
|
void *p = calloc(count, size);
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
die("insufficient memory");
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *xrealloc(void *p, size_t size)
|
||||||
|
{
|
||||||
|
p = realloc(p, size);
|
||||||
|
if (!p)
|
||||||
|
die("insufficient memory");
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
#define xopenat(_dirfd, _path, ...) \
|
#define xopenat(_dirfd, _path, ...) \
|
||||||
({ \
|
({ \
|
||||||
int _fd = openat((_dirfd), (_path), __VA_ARGS__); \
|
int _fd = openat((_dirfd), (_path), __VA_ARGS__); \
|
||||||
|
Loading…
Reference in New Issue
Block a user