summaryrefslogtreecommitdiff
path: root/klm/util/file.cc
diff options
context:
space:
mode:
authorKenneth Heafield <kenlm@kheafield.com>2012-03-09 16:35:10 -0500
committerKenneth Heafield <kenlm@kheafield.com>2012-03-09 16:35:10 -0500
commit249301376865578b7f9678cc97c0f8b6f78623f6 (patch)
treed87bebde8e2294c30d43530b6efa9aa732501275 /klm/util/file.cc
parent78bf1457f606dd3880c2bc912201c4945d3f85b4 (diff)
KenLM d45e2be including CreateOrThrow for Jon
Diffstat (limited to 'klm/util/file.cc')
-rw-r--r--klm/util/file.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/klm/util/file.cc b/klm/util/file.cc
index aee7c77a..176737fa 100644
--- a/klm/util/file.cc
+++ b/klm/util/file.cc
@@ -42,6 +42,16 @@ int OpenReadOrThrow(const char *name) {
return ret;
}
+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;
+}
+
uint64_t SizeFile(int fd) {
#if defined(_WIN32) || defined(_WIN64)
__int64 ret = _filelengthi64(fd);