aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-12-22 23:28:19 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-12-22 23:28:19 +0100
commitea69cc7d9eecbaab1d3b63868b1af959050db5eb (patch)
tree0a8580323c645071b8bef47e5738cb60cc09cf06
parent128fb157b302f0f0881844fc7a2fa5653c74a197 (diff)
downloadbfc-ea69cc7d9eecbaab1d3b63868b1af959050db5eb.tar.gz
bfc-ea69cc7d9eecbaab1d3b63868b1af959050db5eb.tar.xz
bfc-ea69cc7d9eecbaab1d3b63868b1af959050db5eb.zip
Make the output binary executable if possible
-rw-r--r--bfc-amd64-linux.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/bfc-amd64-linux.c b/bfc-amd64-linux.c
index 039e224..eb54e43 100644
--- a/bfc-amd64-linux.c
+++ b/bfc-amd64-linux.c
@@ -7,6 +7,10 @@
#include <assert.h>
#include <errno.h>
+#ifdef __unix__
+#include <fcntl.h>
+#endif
+
#define exit_fatal(...) \
do { \
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
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")))
exit_fatal ("fopen: %s: %s\n", output_path, strerror (errno));
+#endif
fwrite (buffer.str, buffer.len, 1, output_file);
fwrite (code.str, code.len, 1, output_file);