diff --git a/src/conf.h b/src/conf.h index 9d8befda..9db19dda 100644 --- a/src/conf.h +++ b/src/conf.h @@ -236,6 +236,11 @@ typedef unsigned char upx_byte; #undef PAGE_MASK #undef PAGE_SIZE +#if !defined(O_BINARY) || (O_BINARY+0 == 0) +# if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) +# error "missing O_BINARY" +# endif +#endif #if !defined(O_BINARY) # define O_BINARY 0 #endif diff --git a/src/file.cpp b/src/file.cpp index 0f93956e..548ee238 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -429,7 +429,7 @@ off_t OutputFile::seek(upx_int64_t off64, int whence) //{ // fsync(_fd); // InputFile infile; -// infile.open(this->getName(), O_RDONLY); +// infile.open(this->getName(), O_RDONLY | O_BINARY); // infile.seek(this->tell(), SEEK_SET); // return infile.read(buf, len); //} @@ -459,8 +459,8 @@ off_t OutputFile::unset_extent() void OutputFile::dump(const char *name, const void *buf, int len, int flags) { if (flags < 0) - flags = O_CREAT | O_BINARY | O_TRUNC; - flags |= O_WRONLY; + flags = O_CREAT | O_TRUNC; + flags |= O_WRONLY | O_BINARY; OutputFile f; f.open(name, flags, 0600); f.write(buf, len); diff --git a/src/p_djgpp2.cpp b/src/p_djgpp2.cpp index 0b50edb9..b9c77590 100644 --- a/src/p_djgpp2.cpp +++ b/src/p_djgpp2.cpp @@ -170,9 +170,9 @@ static void handle_allegropak(InputFile *fi, OutputFile *fo) if (memcmp(buf, "slh+", 4) != 0) return; pfsize = get_be32_signed(buf+4); - if (pfsize <= 8 || (off_t) pfsize >= (off_t) fi->st.st_size) + if (pfsize <= 8 || pfsize >= (off_t) fi->st.st_size) return; - fi->seek(-pfsize, SEEK_END); + fi->seek(-(off_t)pfsize, SEEK_END); } catch (const IOException&) { return; } diff --git a/src/p_unix.cpp b/src/p_unix.cpp index 5e99d4dc..dca7000e 100644 --- a/src/p_unix.cpp +++ b/src/p_unix.cpp @@ -512,7 +512,7 @@ int PackUnix::canUnpack() bufsize = fi->st_size(); MemBuffer buf(bufsize); - fi->seek(-bufsize, SEEK_END); + fi->seek(-(off_t)bufsize, SEEK_END); fi->readx(buf, bufsize); int i = bufsize; while (i > small && 0 == buf[--i]) { } diff --git a/src/packer.cpp b/src/packer.cpp index 50ffb76e..e002565b 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -626,9 +626,9 @@ unsigned Packer::getRandomId() const unsigned id = 0; #if 0 && defined(__unix__) // Don't consume precious bytes from /dev/urandom. - int fd = open("/dev/urandom", O_RDONLY); + int fd = open("/dev/urandom", O_RDONLY | O_BINARY); if (fd < 0) - fd = open("/dev/random", O_RDONLY); + fd = open("/dev/random", O_RDONLY | O_BINARY); if (fd >= 0) { if (read(fd, &id, 4) != 4) diff --git a/src/util.cpp b/src/util.cpp index b0cf3984..9b7888ed 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -392,7 +392,7 @@ bool file_exists(const char *name) struct stat st; /* return true if we can open it */ - fd = open(name, O_RDONLY, 0); + fd = open(name, O_RDONLY | O_BINARY, 0); if (fd >= 0) { (void) close(fd);