From: Alberto Leiva Popper Date: Mon, 6 May 2024 19:19:18 +0000 (-0600) Subject: Remove file mode hardcode from file_write X-Git-Tag: 1.6.2~31 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=cffd42181ec2f4958c334edf6b88453a88abb09c;p=thirdparty%2FFORT-validator.git Remove file mode hardcode from file_write 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. --- diff --git a/src/file.c b/src/file.c index 40a2da82..d31c8134 100644 --- a/src/file.c +++ b/src/file.c @@ -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; diff --git a/src/file.h b/src/file.h index cdcd0116..d38290e8 100644 --- a/src/file.h +++ b/src/file.h @@ -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 *); diff --git a/src/http/http.c b/src/http/http.c index 53a681b7..7bf062de 100644 --- a/src/http/http.c +++ b/src/http/http.c @@ -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; } diff --git a/src/output_printer.c b/src/output_printer.c index 8f185ad2..e321ebdc 100644 --- a/src/output_printer.c +++ b/src/output_printer.c @@ -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; diff --git a/src/rrdp.c b/src/rrdp.c index a8251b6e..efd18dbf 100644 --- a/src/rrdp.c +++ b/src/rrdp.c @@ -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;