diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 6b0bde73db6..c378fa95763 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -333,6 +333,8 @@ class raw_fd_ostream : public raw_ostream { uint64_t pos; + bool SupportsSeeking; + /// See raw_ostream::write_impl. void write_impl(const char *Ptr, size_t Size) override; @@ -370,6 +372,8 @@ public: /// fsync. void close(); + bool supportsSeeking() { return SupportsSeeking; } + /// Flushes the stream and repositions the underlying file descriptor position /// to the offset specified from the beginning of the file. uint64_t seek(uint64_t off); diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index b7e9ba616d5..199f0a6185b 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -525,7 +525,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered) // Get the starting position. off_t loc = ::lseek(FD, 0, SEEK_CUR); - if (loc == (off_t)-1) + SupportsSeeking = loc != (off_t)-1; + if (!SupportsSeeking) pos = 0; else pos = static_cast(loc);