diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-26 21:42:04 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-26 21:42:04 +0000 |
commit | 9c27886dd5d504f2b03c6fcb57aba23e5e44c4fa (patch) | |
tree | bbfa23593e4dd812821dd2d3a181133910ff7ad9 | |
parent | 4699934647c35a308deb33d9d5e4e811b78139ef (diff) |
Add method raw_fd_ostream::seek() for random access within a file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63044 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Support/raw_ostream.h | 6 | ||||
-rw-r--r-- | lib/Support/raw_ostream.cpp | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 1a4f6bf6f4..030412169d 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -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. diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 96c9a3a263..29665dc350 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -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 //===----------------------------------------------------------------------===// |