Windows: fix missing O_BINARY

This commit is contained in:
Jean-Francois Dockes 2015-12-02 11:42:44 +01:00
parent a783ab17dc
commit a95dcbd4b0
3 changed files with 9 additions and 5 deletions

View File

@ -23,7 +23,7 @@
#include "safesysstat.h"
#include <time.h>
#if 1 || defined(_WIN32)
#if defined(_WIN32)
#define USING_STD_REGEX
#endif

View File

@ -33,6 +33,7 @@
#ifndef _WIN32
#include <sys/uio.h>
#define O_BINARY 0
#else
struct iovec {
void *iov_base;
@ -722,7 +723,7 @@ bool CirCache::create(off_t maxsize, int flags)
}
if ((m_d->m_fd = ::open(m_d->datafn(m_dir).c_str(),
O_CREAT | O_RDWR | O_TRUNC, 0666)) < 0) {
O_CREAT|O_RDWR|O_TRUNC|O_BINARY, 0666)) < 0) {
m_d->m_reason << "CirCache::create: open/creat(" <<
m_d->datafn(m_dir) << ") failed " << "errno " << errno;
return false;
@ -754,7 +755,8 @@ bool CirCache::open(OpMode mode)
::close(m_d->m_fd);
if ((m_d->m_fd = ::open(m_d->datafn(m_dir).c_str(),
mode == CC_OPREAD ? O_RDONLY : O_RDWR)) < 0) {
mode == CC_OPREAD ?
O_RDONLY|O_BINARY : O_RDWR|O_BINARY)) < 0) {
m_d->m_reason << "CirCache::open: open(" << m_d->datafn(m_dir) <<
") failed " << "errno " << errno;
return false;

View File

@ -22,7 +22,9 @@
#include <sys/types.h>
#include "safesysstat.h"
#include "safeunistd.h"
#ifndef _WIN32
#define O_BINARY 0
#endif
#include <string>
#include "readfile.h"
@ -92,7 +94,7 @@ bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs,
// If we have a file name, open it, else use stdin.
if (!fn.empty()) {
fd = open(fn.c_str(), O_RDONLY);
fd = open(fn.c_str(), O_RDONLY|O_BINARY);
if (fd < 0 || fstat(fd, &st) < 0) {
catstrerror(reason, "open/stat", errno);
return false;