mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-12 01:25:49 +00:00
Remove static initializer from DataStream.cpp
If someone would prefer a clear name for the 'success' error_value we could come up with one - potentially just a 'named constructor' style 'error_value::success()' to make this expression more self-documenting. If I see this come up in other cases I'll certainly consider it. One step along the way to resolving PR11944. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150120 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -49,8 +49,6 @@ DataStreamer::~DataStreamer() {}
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const static error_code success;
|
|
||||||
|
|
||||||
// Very simple stream backed by a file. Mostly useful for stdin and debugging;
|
// Very simple stream backed by a file. Mostly useful for stdin and debugging;
|
||||||
// actual file access is probably still best done with mmap.
|
// actual file access is probably still best done with mmap.
|
||||||
class DataFileStreamer : public DataStreamer {
|
class DataFileStreamer : public DataStreamer {
|
||||||
@@ -66,18 +64,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_code OpenFile(const std::string &Filename) {
|
error_code OpenFile(const std::string &Filename) {
|
||||||
|
if (Filename == "-") {
|
||||||
|
Fd = 0;
|
||||||
|
sys::Program::ChangeStdinToBinary();
|
||||||
|
return error_code();
|
||||||
|
}
|
||||||
|
|
||||||
int OpenFlags = O_RDONLY;
|
int OpenFlags = O_RDONLY;
|
||||||
#ifdef O_BINARY
|
#ifdef O_BINARY
|
||||||
OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
|
OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
|
||||||
#endif
|
#endif
|
||||||
if (Filename == "-") {
|
Fd = ::open(Filename.c_str(), OpenFlags);
|
||||||
Fd = 0;
|
if (Fd == -1)
|
||||||
sys::Program::ChangeStdinToBinary();
|
return error_code(errno, posix_category());
|
||||||
}
|
return error_code();
|
||||||
else
|
|
||||||
Fd = ::open(Filename.c_str(), OpenFlags);
|
|
||||||
if (Fd == -1) return error_code(errno, posix_category());
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,8 +87,7 @@ namespace llvm {
|
|||||||
DataStreamer *getDataFileStreamer(const std::string &Filename,
|
DataStreamer *getDataFileStreamer(const std::string &Filename,
|
||||||
std::string *StrError) {
|
std::string *StrError) {
|
||||||
DataFileStreamer *s = new DataFileStreamer();
|
DataFileStreamer *s = new DataFileStreamer();
|
||||||
error_code e = s->OpenFile(Filename);
|
if (error_code e = s->OpenFile(Filename)) {
|
||||||
if (e != success) {
|
|
||||||
*StrError = std::string("Could not open ") + Filename + ": " +
|
*StrError = std::string("Could not open ") + Filename + ": " +
|
||||||
e.message() + "\n";
|
e.message() + "\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user