]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Remove file mode hardcode from file_write
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 6 May 2024 19:19:18 +0000 (13:19 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 6 May 2024 19:20:16 +0000 (13:20 -0600)
This function was always including the binary flag ("b") during
fopen(2), which seems to be inappropriate for the --output.roa and
--output.bgpsec files.

Well, the Unixes don't do anything with this flag, so this is more of a
semantic fine-tune than a bugfix.

src/file.c
src/file.h
src/http/http.c
src/output_printer.c
src/rrdp.c

index 40a2da8270f6a6efcaa5e04e999dea5f57ff86bc..d31c81349e209f6e3a08516721eb3e609da0f4c8 100644 (file)
@@ -39,12 +39,12 @@ fail:
 }
 
 int
-file_write(char const *file_name, FILE **result)
+file_write(char const *file_name, char const *mode, FILE **result)
 {
        FILE *file;
        int error;
 
-       file = fopen(file_name, "wb");
+       file = fopen(file_name, mode);
        if (file == NULL) {
                error = errno;
                pr_val_err("Could not open file '%s': %s", file_name,
@@ -140,7 +140,7 @@ file_valid(char const *file_name)
        if (file_name == NULL)
                return false;
 
-       error = file_write(file_name, &tmp);
+       error = file_write(file_name, "w", &tmp);
        if (error)
                return false;
 
index cdcd01167ab880bc3b004359a06ce48fc6748da3..d38290e8c2e0bad6dd3f98fd37545648805037f4 100644 (file)
@@ -24,7 +24,7 @@ struct file_contents {
 };
 
 int file_open(char const *, FILE **, struct stat *);
-int file_write(char const *, FILE **);
+int file_write(char const *, char const *, FILE **);
 void file_close(FILE *);
 
 int file_load(char const *, struct file_contents *);
index 53a681b789aed143cba3f35f2ba9c5cbc7c5e6e9..7bf062de48031baf7d15b7e5b568fef086c00703 100644 (file)
@@ -108,7 +108,7 @@ write_callback(void *data, size_t size, size_t nmemb, void *userp)
        }
 
        if (arg->file == NULL) {
-               arg->error = file_write(arg->file_name, &arg->file);
+               arg->error = file_write(arg->file_name, "wb", &arg->file);
                if (arg->error)
                        return 0;
        }
index 8f185ad24bb8339032d7a34a8452c521252672e8..e321ebdc65f9b82634343f53e9a5fad4b4fa872e 100644 (file)
@@ -31,7 +31,7 @@ load_output_file(char const *output, FILE **result, bool *fopen)
                return 0;
        }
 
-       error = file_write(output, &tmp);
+       error = file_write(output, "w", &tmp);
        if (error) {
                *result = NULL;
                return error;
index a8251b6e3cdc988f18b36319a9208503d99e5bb8..efd18dbf6d78d821fc5c366cc8749c41edca8fc6 100644 (file)
@@ -587,7 +587,7 @@ write_file(struct rpki_uri *uri, unsigned char *content, size_t content_len)
        if (error)
                return error;
 
-       error = file_write(uri_get_local(uri), &out);
+       error = file_write(uri_get_local(uri), "wb", &out);
        if (error)
                return error;