elf_cntl(3E) (ELF Library) elf_cntl(3E)
NAME
elfcntl - control a file descriptor
SYNOPSIS
cc [flag ...] file ... -lelf [library ...]
#include <libelf.h>
int elfcntl(Elf *elf, ElfCmd cmd);
DESCRIPTION
elfcntl instructs the library to modify its behavior with respect to
an ELF descriptor, elf. As elfbegin(3E) describes, an ELF
descriptor can have multiple activations, and multiple ELF
descriptors may share a single file descriptor. Generally, elfcntl
commands apply to all activations of elf. Moreover, if the ELF
descriptor is associated with an archive file, descriptors for
members within the archive will also be affected as described below.
Unless stated otherwise, operations on archive members do not affect
the descriptor for the containing archive.
The cmd argument tells what actions to take and may have the
following values.
ELFCFDDONE
This value tells the library not to use the file descriptor
associated with elf. A program should use this command
when it has requested all the information it cares to use
and wishes to avoid the overhead of reading the rest of the
file. The memory for all completed operations remains
valid, but later file operations, such as the initial
elfgetdata for a section, will fail if the data are not in
memory already.
ELFCFDREAD
This command is similar to ELFCFDDONE, except it forces
the library to read the rest of the file. A program should
use this command when it must close the file descriptor but
has not yet read everything it needs from the file. After
elfcntl completes the ELFCFDREAD command, future
operations, such as elfgetdata, will use the memory
version of the file without needing to use the file
descriptor.
If elfcntl succeeds, it returns zero. Otherwise elf was null or an
error occurred, and the function returns -1.
SEE ALSO
elf(3E), elfbegin(3E), elfgetdata(3E), elfrawfile(3E).
8/91 Page 1
elf_cntl(3E) (ELF Library) elf_cntl(3E)
NOTE
If the program wishes to use the ``raw'' operations [see elfrawdata,
which elfgetdata(3E) describes, and elfrawfile(3E)] after disabling
the file descriptor with ELFCFDDONE or ELFCFDREAD, it must
execute the raw operations explicitly beforehand. Otherwise, the raw
file operations will fail. Calling elfrawfile makes the entire
image available, thus supporting subsequent elfrawdata calls.
Page 2 8/91