Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.

Synopsis

Declared in <llvm/Support/MemoryBuffer.h>

static
ErrorOr<std::unique_ptr<MemoryBuffer>>
getFile(
    Twine const& Filename,
    bool IsText = false,
    bool RequiresNullTerminator = true,
    bool IsVolatile = false,
    std::optional<Align> Alignment = std::nullopt);

Return Value

The file contents on success, or an error on failure.

Parameters

Name

Description

Filename

Path of the file to open.

IsText

Set to true to indicate that the file should be read in text mode.

RequiresNullTerminator

Whether the buffer must be null‐terminated.

IsVolatile

Set to true to indicate that the contents of the file can change outside the user's control, e.g. when libclang tries to parse while the user is editing/updating the file or if the file is on an NFS.

Alignment

Set to indicate that the buffer should be aligned to at least the specified alignment.

Created with MrDocs