Add method raw_fd_ostream::seek() for random access within a file.
authorTed Kremenek <kremenek@apple.com>
Mon, 26 Jan 2009 21:42:04 +0000 (21:42 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 26 Jan 2009 21:42:04 +0000 (21:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63044 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp

index 1a4f6bf6f47174a5e02e58bec9fb28ec8b82d36a..030412169d8a703875baf2d6e4e28f57ab406886 100644 (file)
@@ -181,7 +181,11 @@ public:
   /// tell - Return the current offset with the file.
   uint64_t tell() {
     return pos + (OutBufCur - OutBufStart);
-  }  
+  }
+  
+  /// seek - Flushes the stream and repositions the underlying file descriptor
+  ///  positition to the offset specified from the beginning of the file.
+  uint64_t seek(uint64_t off);
 };
   
 /// raw_stdout_ostream - This is a stream that always prints to stdout.
index 96c9a3a263d025e15cb634622293f3e1b9f739f2..29665dc350c6ae303db854537ea5f3b1b297558d 100644 (file)
@@ -255,6 +255,12 @@ void raw_fd_ostream::close() {
   FD = -1;
 }
 
+uint64_t raw_fd_ostream::seek(uint64_t off) {
+  flush();
+  pos = lseek(FD, off, SEEK_SET);
+  return pos;  
+}
+
 //===----------------------------------------------------------------------===//
 //  raw_stdout/err_ostream
 //===----------------------------------------------------------------------===//