From 149232c38eec558ddb1097698d1570aacb67b59f Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Wed, 16 May 2012 13:24:08 -0700 Subject: Big kenlm change includes lower order models for probing only. And other stuff. --- klm/util/mmap.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'klm/util/mmap.cc') diff --git a/klm/util/mmap.cc b/klm/util/mmap.cc index 2db35b56..e0d2570b 100644 --- a/klm/util/mmap.cc +++ b/klm/util/mmap.cc @@ -171,6 +171,20 @@ void *MapZeroedWrite(int fd, std::size_t size) { return MapOrThrow(size, true, kFileFlags, false, fd, 0); } +namespace { + +int CreateOrThrow(const char *name) { + int ret; +#if defined(_WIN32) || defined(_WIN64) + UTIL_THROW_IF(-1 == (ret = _open(name, _O_CREAT | _O_TRUNC | _O_RDWR, _S_IREAD | _S_IWRITE)), ErrnoException, "while creating " << name); +#else + UTIL_THROW_IF(-1 == (ret = open(name, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)), ErrnoException, "while creating " << name); +#endif + return ret; +} + +} // namespace + void *MapZeroedWrite(const char *name, std::size_t size, scoped_fd &file) { file.reset(CreateOrThrow(name)); try { -- cgit v1.2.3 From ff497ae4fa2e96f3b0970647029082764b890acd Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Sun, 27 May 2012 15:00:41 -0400 Subject: Guard unistd.h for windows :-( --- klm/util/file.cc | 3 ++- klm/util/mmap.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'klm/util/mmap.cc') diff --git a/klm/util/file.cc b/klm/util/file.cc index 1bd056fc..6a3885a7 100644 --- a/klm/util/file.cc +++ b/klm/util/file.cc @@ -10,11 +10,12 @@ #include #include #include -#include #if defined(_WIN32) || defined(_WIN64) #include #include +#else +#include #endif namespace util { diff --git a/klm/util/mmap.cc b/klm/util/mmap.cc index e0d2570b..576fd4cc 100644 --- a/klm/util/mmap.cc +++ b/klm/util/mmap.cc @@ -14,12 +14,12 @@ #include #include #include -#include #if defined(_WIN32) || defined(_WIN64) #include #include #else +#include #include #endif -- cgit v1.2.3