From: Michael Tremer Date: Tue, 31 Dec 2024 18:21:06 +0000 (+0000) Subject: file: Allow passing the mode on fopen() X-Git-Tag: 0.9.30~618 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87358067ff1054d147d10c8dbc8cc28fb5a559f2;p=pakfire.git file: Allow passing the mode on fopen() Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/compress.c b/src/libpakfire/compress.c index 6d5d11e96..0ccbc1030 100644 --- a/src/libpakfire/compress.c +++ b/src/libpakfire/compress.c @@ -610,7 +610,7 @@ static int __pakfire_compress_entry(struct pakfire_ctx* ctx, struct pakfire_file // Copy the data if there is any if (archive_entry_size(entry)) { // Open the file - f = pakfire_file_fopen(file); + f = pakfire_file_fopen(file, "r"); if (!f) { r = -errno; goto ERROR; diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 141bca85c..f390fb785 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -1108,17 +1108,17 @@ int pakfire_file_open(struct pakfire_file* file, int flags) { return fd; } -FILE* pakfire_file_fopen(struct pakfire_file* file) { +FILE* pakfire_file_fopen(struct pakfire_file* file, const char* mode) { + const char* path = NULL; FILE* f = NULL; - int fd = -EBADF; - // Open the file descriptor - fd = pakfire_file_open(file, O_RDONLY); - if (fd < 0) + // Fetch the absolute path of the file + path = pakfire_file_get_abspath(file); + if (!path) return NULL; // Return a file handle - f = fdopen(fd, "r"); + f = fopen(path, mode); if (!f) { ERROR(file->ctx, "Could not open file handle for %s: %m\n", pakfire_file_get_path(file)); @@ -1148,7 +1148,7 @@ int pakfire_file_payload_matches(struct pakfire_file* file, return 0; // Open the file - f = pakfire_file_fopen(file); + f = pakfire_file_fopen(file, "r"); if (!f) { r = 1; goto ERROR; @@ -1196,7 +1196,7 @@ static int __pakfire_file_compute_digests(struct pakfire_file* file, pakfire_digests_reset(digests, types); // Open the file - f = pakfire_file_fopen(file); + f = pakfire_file_fopen(file, "r"); if (!f) { r = -errno; goto ERROR; @@ -1461,7 +1461,7 @@ static int pakfire_file_classify_elf(struct pakfire_file* file) { return r; // Open the file - f = pakfire_file_fopen(file); + f = pakfire_file_fopen(file, "r"); if (!f) { ERROR(file->ctx, "Could not open %s: %m\n", pakfire_file_get_path(file)); return 1; diff --git a/src/libpakfire/include/pakfire/file.h b/src/libpakfire/include/pakfire/file.h index 07005b0ae..4325c0138 100644 --- a/src/libpakfire/include/pakfire/file.h +++ b/src/libpakfire/include/pakfire/file.h @@ -157,7 +157,7 @@ char* pakfire_file_dump(struct pakfire_file* file, int flags); const char* pakfire_file_get_abspath(struct pakfire_file* file); int pakfire_file_open(struct pakfire_file* file, int flags); -FILE* pakfire_file_fopen(struct pakfire_file* file); +FILE* pakfire_file_fopen(struct pakfire_file* file, const char* mode); int pakfire_file_payload_matches(struct pakfire_file* file, const void* needle, const size_t length);