diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-22 00:17:14 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-22 00:17:14 +0200 |
commit | b968f8ed826b9cc662c1a484040c55b0e0ad18c4 (patch) | |
tree | 9b69a95fb5154d14837991bef604fd25585f7087 /io.c | |
parent | Periodically save progress (diff) | |
download | deadshred-b968f8ed826b9cc662c1a484040c55b0e0ad18c4.tar.gz deadshred-b968f8ed826b9cc662c1a484040c55b0e0ad18c4.tar.bz2 deadshred-b968f8ed826b9cc662c1a484040c55b0e0ad18c4.tar.xz |
Expose device information in confirmation prompt
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -2,6 +2,45 @@ #include "common.h" +char * +readtextfileat(int dfd, const char *path) +{ + int fd; + char *text = NULL; + size_t size = 0; + size_t len = 0; + ssize_t r; + + fd = openat(dfd, path, O_RDONLY); + if (fd < 0) + return NULL; + + for (;;) { + if (len == size) { + size = size ? size * 2U : 64U; + text = erealloc(text, size); + } + r = read(fd, &text[len], size - len); + if (r <= 0) { + if (!r) + break; + if (errno == EINTR) + continue; + close(fd); + return NULL; + } + len += (size_t)r; + } + + close(fd); + + if (len == size) + text = erealloc(text, len + 1U); + text[len] = '\0'; + return text; +} + + void writeall(int fd, const void *data, size_t n, const char *fname) { |