orc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject orc git commit: ORC-358: windows/msvc version of OrcFile/pread()
Date Thu, 03 May 2018 20:47:15 GMT
Repository: orc
Updated Branches:
  refs/heads/master 2d096b9ef -> 4cc0968f5


ORC-358: windows/msvc version of OrcFile/pread()

Fixes #264

Signed-off-by: Owen O'Malley <omalley@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/orc/repo
Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/4cc0968f
Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/4cc0968f
Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/4cc0968f

Branch: refs/heads/master
Commit: 4cc0968f58238150a035d1983b3ed4b00787546b
Parents: 2d096b9
Author: rip-nsk <rip.nsk@gmail.com>
Authored: Thu May 3 11:51:30 2018 -0700
Committer: Owen O'Malley <omalley@apache.org>
Committed: Thu May 3 13:46:45 2018 -0700

----------------------------------------------------------------------
 c++/src/Adaptor.cc    | 23 +++++++++++++++++++++++
 c++/src/Adaptor.hh.in |  2 +-
 c++/src/OrcFile.cc    | 37 ++++++++++++++-----------------------
 3 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/orc/blob/4cc0968f/c++/src/Adaptor.cc
----------------------------------------------------------------------
diff --git a/c++/src/Adaptor.cc b/c++/src/Adaptor.cc
index 9c0a74c..43236f8 100644
--- a/c++/src/Adaptor.cc
+++ b/c++/src/Adaptor.cc
@@ -41,3 +41,26 @@ char* strptime(const char* s, const char* f, struct tm* tm) {
   return (char*)(s + input.tellg());
 }
 #endif
+
+#ifndef HAS_PREAD
+  #ifdef _WIN32
+#include <Windows.h>
+#include <io.h>
+ssize_t pread(int fd, void* buf, size_t size, off_t offset) {
+  auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
+
+  OVERLAPPED ol;
+  memset(&ol, 0, sizeof(OVERLAPPED));
+  ol.Offset = offset;
+
+  DWORD rt;
+  if (!ReadFile(handle, buf, static_cast<DWORD>(size), &rt, &ol)) {
+    errno = GetLastError();
+    return -1;
+  }
+  return static_cast<ssize_t>(rt);
+}
+  #else
+    #error("pread() undefined: unknown environment")
+  #endif
+#endif

http://git-wip-us.apache.org/repos/asf/orc/blob/4cc0968f/c++/src/Adaptor.hh.in
----------------------------------------------------------------------
diff --git a/c++/src/Adaptor.hh.in b/c++/src/Adaptor.hh.in
index 5fefa3f..3f5c451 100644
--- a/c++/src/Adaptor.hh.in
+++ b/c++/src/Adaptor.hh.in
@@ -46,7 +46,7 @@
 #endif
 
 #ifndef HAS_PREAD
-  ssize_t pread(int fd, void *buf, size_t count, off_t offset);
+  ssize_t pread(int fd, void* buf, size_t count, off_t offset);
 #endif
 
 #ifdef INT64_IS_LL

http://git-wip-us.apache.org/repos/asf/orc/blob/4cc0968f/c++/src/OrcFile.cc
----------------------------------------------------------------------
diff --git a/c++/src/OrcFile.cc b/c++/src/OrcFile.cc
index 3db98fe..009a8ce 100644
--- a/c++/src/OrcFile.cc
+++ b/c++/src/OrcFile.cc
@@ -16,32 +16,37 @@
  * limitations under the License.
  */
 
-#include "orc/OrcFile.hh"
-
 #include "Adaptor.hh"
+#include "orc/OrcFile.hh"
 #include "orc/Exceptions.hh"
 
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <sys/mman.h>
 #include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <io.h>
+#define S_IRUSR _S_IREAD
+#define S_IWUSR _S_IWRITE
+#else
+#include <unistd.h>
+#define O_BINARY 0
+#endif
+
 namespace orc {
 
   class FileInputStream : public InputStream {
   private:
-    std::string filename ;
+    std::string filename;
     int file;
     uint64_t totalLength;
 
   public:
     FileInputStream(std::string _filename) {
-      filename = _filename ;
-      file = open(filename.c_str(), O_RDONLY);
+      filename = _filename;
+      file = open(filename.c_str(), O_BINARY | O_RDONLY);
       if (file == -1) {
         throw ParseError("Can't open " + filename);
       }
@@ -121,7 +126,7 @@ namespace orc {
       closed = false;
       file = open(
                   filename.c_str(),
-                  O_CREAT | O_WRONLY | O_TRUNC,
+                  O_BINARY | O_CREAT | O_WRONLY | O_TRUNC,
                   S_IRUSR | S_IWUSR);
       if (file == -1) {
         throw ParseError("Can't open " + filename);
@@ -175,17 +180,3 @@ namespace orc {
     return std::unique_ptr<OutputStream>(new FileOutputStream(path));
   }
 }
-
-#ifndef HAS_STOLL
-
-  #include <sstream>
-
-  int64_t std::stoll(std::string str) {
-    int64_t val = 0;
-    stringstream ss ;
-    ss << str ;
-    ss >> val ;
-    return val;
-  }
-
-#endif


Mime
View raw message