Make the output binary executable if possible

This commit is contained in:
Přemysl Eric Janouch 2016-12-22 23:28:19 +01:00
parent 128fb157b3
commit ea69cc7d9e
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 12 additions and 0 deletions

View File

@ -7,6 +7,10 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#ifdef __unix__
#include <fcntl.h>
#endif
#define exit_fatal(...) \ #define exit_fatal(...) \
do { \ do { \
fprintf (stderr, "fatal: " __VA_ARGS__); \ fprintf (stderr, "fatal: " __VA_ARGS__); \
@ -713,8 +717,16 @@ main (int argc, char *argv[])
// The section header table is optional and we don't need it for anything // The section header table is optional and we don't need it for anything
FILE *output_file; FILE *output_file;
#ifdef __unix__
int output_fd;
if ((output_fd = open (output_path, O_CREAT | O_WRONLY, 0777)) < 0)
exit_fatal ("open: %s: %s\n", output_path, strerror (errno));
if (!(output_file = fdopen (output_fd, "w")))
exit_fatal ("fdopen: %s\n", strerror (errno));
#else
if (!(output_file = fopen (output_path, "w"))) if (!(output_file = fopen (output_path, "w")))
exit_fatal ("fopen: %s: %s\n", output_path, strerror (errno)); exit_fatal ("fopen: %s: %s\n", output_path, strerror (errno));
#endif
fwrite (buffer.str, buffer.len, 1, output_file); fwrite (buffer.str, buffer.len, 1, output_file);
fwrite (code.str, code.len, 1, output_file); fwrite (code.str, code.len, 1, output_file);