diff options
author | Taku Kudo <taku@google.com> | 2018-09-01 04:10:01 +0300 |
---|---|---|
committer | Taku Kudo <taku@google.com> | 2018-09-01 04:10:01 +0300 |
commit | f617fcb697eaeaa09b7b4d73559def57f042194e (patch) | |
tree | d7c28921348ceadc478b0118d966bc32686c0821 /src/util.cc | |
parent | 9f63c57e4b51952b236672a17d6d8c15f25c3d68 (diff) |
Introduced new Filesystem API.
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 51 |
1 files changed, 1 insertions, 50 deletions
diff --git a/src/util.cc b/src/util.cc index c223053..2569889 100644 --- a/src/util.cc +++ b/src/util.cc @@ -215,55 +215,6 @@ std::string UnicodeTextToUTF8(const UnicodeText &utext) { } } // namespace string_util -namespace io { - -InputBuffer::InputBuffer(absl::string_view filename) - : is_(filename.empty() ? &std::cin - : new std::ifstream(WPATH(filename.data()))) { - if (!*is_) - status_ = util::StatusBuilder(util::error::NOT_FOUND) - << "\"" << filename.data() << "\": " << util::StrError(errno); -} - -InputBuffer::~InputBuffer() { - if (is_ != &std::cin) { - delete is_; - } -} - -util::Status InputBuffer::status() const { return status_; } - -bool InputBuffer::ReadLine(std::string *line) { - return static_cast<bool>(std::getline(*is_, *line)); -} - -OutputBuffer::OutputBuffer(absl::string_view filename) - : os_(filename.empty() - ? &std::cout - : new std::ofstream(WPATH(filename.data()), OUTPUT_MODE)) { - if (!*os_) - status_ = util::StatusBuilder(util::error::PERMISSION_DENIED) - << "\"" << filename.data() << "\": " << util::StrError(errno); -} - -OutputBuffer::~OutputBuffer() { - if (os_ != &std::cout) { - delete os_; - } -} - -util::Status OutputBuffer::status() const { return status_; } - -bool OutputBuffer::Write(absl::string_view text) { - os_->write(text.data(), text.size()); - return os_->good(); -} - -bool OutputBuffer::WriteLine(absl::string_view text) { - return Write(text) && Write("\n"); -} -} // namespace io - namespace random { #ifdef SPM_NO_THREADLOCAL namespace { @@ -307,7 +258,7 @@ std::string StrError(int errnum) { constexpr int kStrErrorSize = 1024; char buffer[kStrErrorSize]; char *str = nullptr; -#if defined(_GLIBC__) && defined(_GNU_SOURCE) +#if defined(__GLIBC__) && defined(_GNU_SOURCE) str = strerror_r(errnum, buffer, kStrErrorSize - 1); #elif defined(_WIN32) strerror_s(buffer, kStrErrorSize - 1, errnum); |