From e37b898edbc0aba29782ea0802483912f813aad4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 10 Apr 2015 18:15:51 +0000 Subject: [PATCH] Remember if lseek works in this FD. It will be used in clang in a sec. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234619 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/raw_ostream.h | 4 ++++ lib/Support/raw_ostream.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) 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);