X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FDataStream.cpp;h=32653de5194383549de9bb6b88b427383cca9f1f;hb=285133714f0d995e0e14a77e23a0abe5dfc32d17;hp=7815d08092e0e0448e9a03045aec354c342464d7;hpb=9f1d9fd1964d82f3e801efb71518144492cdf290;p=oota-llvm.git diff --git a/lib/Support/DataStream.cpp b/lib/Support/DataStream.cpp index 7815d08092e..32653de5194 100644 --- a/lib/Support/DataStream.cpp +++ b/lib/Support/DataStream.cpp @@ -14,22 +14,23 @@ // //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "Data-stream" #include "llvm/Support/DataStream.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" -#include "llvm/Support/system_error.h" #include #include #include +#include #if !defined(_MSC_VER) && !defined(__MINGW32__) #include #else #include #endif -#include using namespace llvm; +#define DEBUG_TYPE "Data-stream" + // Interface goals: // * StreamableMemoryObject doesn't care about complexities like using // threads/async callbacks to actually overlap download+compile @@ -58,26 +59,19 @@ public: virtual ~DataFileStreamer() { close(Fd); } - virtual size_t GetBytes(unsigned char *buf, size_t len) LLVM_OVERRIDE { + size_t GetBytes(unsigned char *buf, size_t len) override { NumStreamFetches++; return read(Fd, buf, len); } - error_code OpenFile(const std::string &Filename) { + std::error_code OpenFile(const std::string &Filename) { if (Filename == "-") { Fd = 0; sys::ChangeStdinToBinary(); - return error_code::success(); + return std::error_code(); } - - int OpenFlags = O_RDONLY; -#ifdef O_BINARY - OpenFlags |= O_BINARY; // Open input file in binary mode on win32. -#endif - Fd = ::open(Filename.c_str(), OpenFlags); - if (Fd == -1) - return error_code(errno, posix_category()); - return error_code::success(); + + return sys::fs::openFileForRead(Filename, Fd); } }; @@ -87,10 +81,10 @@ namespace llvm { DataStreamer *getDataFileStreamer(const std::string &Filename, std::string *StrError) { DataFileStreamer *s = new DataFileStreamer(); - if (error_code e = s->OpenFile(Filename)) { + if (std::error_code e = s->OpenFile(Filename)) { *StrError = std::string("Could not open ") + Filename + ": " + e.message() + "\n"; - return NULL; + return nullptr; } return s; }