[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


elf_cntl Subroutine

Purpose

Control a file descriptor

Library

cc [flag...] file... -lelf [library]...
#include <libelf.h>

Syntax


int elf_cntl(Elf * elf, Elf_Cmd cmd);

Description

elf_cntl instructs the library to modify its behavior with respect to an ELF descriptor, elf. Just as with elf_begin, an ELF descriptor can have multiple activations, and multiple ELF descriptors may share a single file descriptor. Generally, elf_cntl 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.

If the program wishes to use the raw operations [see the elf_rawdata and elf_rawfile subroutines] after disabling the file descriptor with ELF_C_FDDONE or ELF_C_FDREAD, it must execute the raw operations explicitly beforehand. Otherwise, the raw file operations will fail. Calling elf_rawfile makes the entire image available, thus supporting subsequent elf_rawdata calls.

Parameters


cmd Specifies the action to take and can be set to any of the following values.

ELF_C_FDDONE
Specifies to 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 elf_getdata for a section, will fail if the data is not in memory already.

ELF_C_FDREAD
Specifies to the library not to use the file descriptor associated with elf, but in addition it also 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 elf_cntl completes the ELF_C_FDREAD command, future operations, such as elf_getdata, will use the memory version of the file without needing to use the file descriptor.

Return Values

On successful completion, the elf_cntl subroutine returns a value of 0. Otherwise, a value of -1 is returned and the errno global value is set to indicate an error.

Related Information

The elf_begin (elf_begin Subroutine) subroutine, elf_getdata (elf_getdata, elf_newdata, elf_rawdata Subroutine) subroutine, elf_rawfile (elf_rawfile Subroutine) subroutine.

Introduction to ELF Subroutines.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]