aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-14 18:32:15 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-14 18:32:51 +0100
commitf4e1c379a96021497acad5fe2ded09fcdb791f58 (patch)
treecb2d9883ebcbe427fe251a064fc13919f4938849
parentc76eaea4eecbe4b5b6c5c0eb0f82d23491f87dba (diff)
downloadqtmips-f4e1c379a96021497acad5fe2ded09fcdb791f58.tar.gz
qtmips-f4e1c379a96021497acad5fe2ded09fcdb791f58.tar.bz2
qtmips-f4e1c379a96021497acad5fe2ded09fcdb791f58.zip
Correct program loader to open ELF file in binary mode on Windows.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
-rw-r--r--qtmips_machine/programloader.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/qtmips_machine/programloader.cpp b/qtmips_machine/programloader.cpp
index 7722774..750fd00 100644
--- a/qtmips_machine/programloader.cpp
+++ b/qtmips_machine/programloader.cpp
@@ -41,6 +41,10 @@
#include <cstring>
#include "qtmipsexception.h"
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
using namespace machine;
ProgramLoader::ProgramLoader(const char *file) {
@@ -49,7 +53,7 @@ ProgramLoader::ProgramLoader(const char *file) {
if (elf_version(EV_CURRENT) == EV_NONE)
throw QTMIPS_EXCEPTION(Input, "Elf library initialization failed", elf_errmsg(-1));
// Open source file
- if ((this->fd = open(file, O_RDONLY, 0)) < 0)
+ if ((this->fd = open(file, O_RDONLY | O_BINARY, 0)) < 0)
throw QTMIPS_EXCEPTION(Input, QString("Can't open input elf file for reading (") + QString(file) + QString(")"), std::strerror(errno));
// Initialize elf
if (!(this->elf = elf_begin(this->fd, ELF_C_READ, NULL)))