Crashpad
Public Member Functions | List of all members
crashpad::StringFile Class Reference

A file reader and writer backed by a virtual file, as opposed to a file on disk or other operating system file descriptor-based file. More...

#include "util/file/string_file.h"

Inheritance diagram for crashpad::StringFile:
crashpad::FileReaderInterface crashpad::FileWriterInterface crashpad::FileSeekerInterface crashpad::FileSeekerInterface

Public Member Functions

const std::string & string () const
 Returns a string containing the virtual file’s contents.
 
void SetString (const std::string &string)
 Sets the virtual file’s contents to string, and resets its file position to 0.
 
void Reset ()
 Resets the virtual file’s contents to be empty, and resets its file position to 0.
 
FileOperationResult Read (void *data, size_t size) override
 Wraps ReadFile(), or provides an implementation with identical semantics. More...
 
bool Write (const void *data, size_t size) override
 Wraps LoggingWriteFile(), or provides an implementation with identical semantics. More...
 
bool WriteIoVec (std::vector< WritableIoVec > *iovecs) override
 Wraps writev() on POSIX or provides an alternate implementation with identical semantics. This method will write entire buffers, continuing after a short write or after being interrupted. On non-POSIX this is a simple wrapper around Write(). More...
 
FileOffset Seek (FileOffset offset, int whence) override
 Wraps LoggingSeekFile() or provides an alternate implementation with identical semantics. More...
 
- Public Member Functions inherited from crashpad::FileReaderInterface
bool ReadExactly (void *data, size_t size)
 Wraps Read(), ensuring that the read succeeded and exactly size bytes were read. More...
 
- Public Member Functions inherited from crashpad::FileSeekerInterface
FileOffset SeekGet ()
 Wraps Seek(), using SEEK_CUR to obtain the file’s current position. More...
 
bool SeekSet (FileOffset offset)
 Wraps Seek(), using SEEK_SET, ensuring that the seek succeeded and the file is positioned as desired. More...
 

Detailed Description

A file reader and writer backed by a virtual file, as opposed to a file on disk or other operating system file descriptor-based file.

The virtual file is a buffer in memory. This class is convenient for use with other code that normally expects to read or write files, when it is impractical or inconvenient to read or write a file. It is expected that tests, in particular, will benefit from using this class.

Member Function Documentation

◆ Read()

FileOperationResult crashpad::StringFile::Read ( void *  data,
size_t  size 
)
overridevirtual

Wraps ReadFile(), or provides an implementation with identical semantics.

Returns
The number of bytes actually read if the operation succeeded, which may be 0 or any positive value less than or equal to size. -1 if the operation failed, with an error message logged.

Implements crashpad::FileReaderInterface.

◆ Seek()

FileOffset crashpad::StringFile::Seek ( FileOffset  offset,
int  whence 
)
overridevirtual

Wraps LoggingSeekFile() or provides an alternate implementation with identical semantics.

Returns
The return value of LoggingSeekFile(). -1 on failure, with an error message logged.

Implements crashpad::FileSeekerInterface.

◆ Write()

bool crashpad::StringFile::Write ( const void *  data,
size_t  size 
)
overridevirtual

Wraps LoggingWriteFile(), or provides an implementation with identical semantics.

Returns
true if the operation succeeded, false if it failed, with an error message logged.

Implements crashpad::FileWriterInterface.

◆ WriteIoVec()

bool crashpad::StringFile::WriteIoVec ( std::vector< WritableIoVec > *  iovecs)
overridevirtual

Wraps writev() on POSIX or provides an alternate implementation with identical semantics. This method will write entire buffers, continuing after a short write or after being interrupted. On non-POSIX this is a simple wrapper around Write().

Returns
true if the operation succeeded, false if it failed, with an error message logged.
Note
The contents of iovecs are undefined when this method returns.

Implements crashpad::FileWriterInterface.


The documentation for this class was generated from the following files: