diff options
Diffstat (limited to '')
| -rw-r--r-- | src/util/io.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/io.h b/src/util/io.h index 8c646cb..44c0a92 100644 --- a/src/util/io.h +++ b/src/util/io.h @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include <fcntl.h> +#include <errno.h> #if defined(POSIX_FADV_SEQUENTIAL) # define fadvise_sequential(...) posix_fadvise(__VA_ARGS__, POSIX_FADV_SEQUENTIAL) @@ -17,6 +18,7 @@ #define ereadall(...) enreadall(1, __VA_ARGS__) #define epwriteall(...) enpwriteall(1, __VA_ARGS__) #define ewritezeroes(...) enwritezeroes(1, __VA_ARGS__) +#define egetfile(...) engetfile(1, __VA_ARGS__) int writeall(int fd, void *buf, size_t n); @@ -55,3 +57,17 @@ enwritezeroes(int status, int fd, void *buf, size_t bufsize, size_t n, const cha if (writezeroes(fd, buf, bufsize, n)) enprintf(status, "write %s:", fname); } + +int getfile(int fd, void *bufp, size_t *restrict ptrp, size_t *restrict sizep); + +static inline void +engetfile(int status, int fd, void *bufp, size_t *restrict ptrp, + size_t *restrict sizep, const char *fname) +{ + if (getfile(fd, bufp, ptrp, sizep)) { + if (errno == ENOMEM) + enprintf(status, "realloc:"); + else + enprintf(status, "read %s:", fname); + } +} |
