From b968f8ed826b9cc662c1a484040c55b0e0ad18c4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 22 Sep 2024 00:17:14 +0200 Subject: Expose device information in confirmation prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- io.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'io.c') diff --git a/io.c b/io.c index 98afe53..063265b 100644 --- a/io.c +++ b/io.c @@ -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) { -- cgit v1.2.3-70-g09d2