]> git.ipfire.org Git - pakfire.git/commitdiff
file: Allow passing the mode on fopen()
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Dec 2024 18:21:06 +0000 (18:21 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Dec 2024 18:21:06 +0000 (18:21 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/compress.c
src/libpakfire/file.c
src/libpakfire/include/pakfire/file.h

index 6d5d11e96e28f2ab1dbbe73407abc8a5e44ba4e8..0ccbc1030504202213791e13d99e7c66d43aad99 100644 (file)
@@ -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;
index 141bca85c78a04efa72730d22315817fcd3aaf52..f390fb785b53bf09f03eb82e13fd9cfeca048f13 100644 (file)
@@ -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;
index 07005b0aef9f0cb87db8975cb1cd7989fc3b9083..4325c01385392a1d06b09919abdbaf40be48f8da 100644 (file)
@@ -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);