|
|
#include <libelf.h>char *elf_rawfile(Elf *elf, size_t *ptr);
This function should be used only to retrieve a file being read. For example, a program might use elf_rawfile( ) to retrieve the bytes for an archive member.
A program may not close or disable (see elf_cntl(S-osr5)) the file descriptor associated with elf before the initial call to elf_rawfile( ), because elf_rawfile( ) might have to read the data from the file if it does not already have the original bytes in memory.
Generally, this function is more efficient for unknown file types than for object files. The library implicitly translates object files in memory, while it leaves unknown files unmodified. Thus asking for the uninterpreted image of an object file may create a duplicate copy in memory.
elf_rawdata(S-osr5) (see elf_getdata(S-osr5)) is a related function, providing access to sections within a file.
If ptr is non-null, the library also stores the file's size, in bytes, in the location that ptr points to. If no data is present, elf is null, or an error occurs, the return value is a null pointer, with zero optionally stored through ptr.
Consequently, the application should view the raw file image returned by elf_rawfile( ) as a read-only buffer, unless it wants to alter its own view of data subsequently translated. In any case, the application may alter the translated objects without changing bytes visible in the raw image.
Multiple calls to elf_rawfile( ) with the same ELF descriptor return the same value; the library does not create duplicate copies of the file.