While working on a patch for GSYM: https://reviews.llvm.org/D63828 there is a FileWriter class that is being used to write binary data to a stand alone file. The patch was directly using a std::ostream to do the writing, and multiple people in the comments of the patch suggested that we use llvm::raw_ostream. In order to be able to use raw_ostream in the patch we need to be able to seek to locations in the the stream when writing binary data to apply fixes to offsets.
This patch puts the ability to support seeking into llvm::raw_ostream so that we can end up using it in the FileWriter class in the unit tests. It does this by adding two virtual methods to llvm::raw_ostream:
/// Seek support is optional. virtual bool supportsSeeking() { return false; } /// Optional seek support. Defaults to not changing the file position. virtual uint64_t seek(uint64_t off) { return current_pos(); };
There are default implementations that return false and current_pos() respectively so only changes need to be made to raw_ostream subclasses that need to add seek support. It also fixed raw_fd_ostream and raw_os_ostream to override these methods.
return OS.tellp() != -1;