---
name: "elf_cntl"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf_cntl"
---

# elf\_cntl(3)

control an elf file descriptor

## NAME

**elf\_cntl** – control an elf file descriptor

## LIBRARY

library “libelf”

## SYNOPSIS

**#include \<libelf.h\>**

*int*\

**elf\_cntl**(*Elf \*elf*, *Elf\_Cmd cmd*);

## DESCRIPTION

Function **elf\_cntl**() controls the ELF library's subsequent use of the file descriptor used to create ELF descriptor *elf*.

Argument *cmd* informs the library of the action to be taken:

- ELF\_C\_FDDONE

  This value instructs the ELF library not to perform any further I/O on the file descriptor associated with argument *elf*. For ELF descriptors opened with mode *ELF\_C\_WRITE* or *ELF\_C\_RDWR* subsequent **elf\_update**() operations on the descriptor will fail.

- ELF\_C\_FDREAD

  This value instructs the ELF library to read in all necessary data associated with ELF descriptor *elf* into memory so that the underlying file descriptor can be safely closed with command ELF\_C\_FDDONE.

Argument *elf* must be an ELF descriptor associated with a file system object (e.g., an [ar(1)](/ar/1.md) archive, an ELF file, or other data file).

## IMPLEMENTATION NOTES

Due to use of [mmap(2)](/mmap/2.md) internally, this function is a no-op for ELF objects opened in ELF\_C\_READ mode.

## RETURN VALUES

Function **elf\_cntl**() returns 0 on success, or -1 if an error was detected.

## ERRORS

- \[ELF\_E\_ARCHIVE\]

  Argument *elf* is a descriptor for an archive member.

- \[ELF\_E\_ARGUMENT\]

  Argument *elf* was NULL.

- \[ELF\_E\_ARGUMENT\]

  Argument *cmd* was not recognized.

- \[ELF\_E\_MODE\]

  An ELF\_C\_FDREAD operation was requested on an ELF descriptor opened for writing.

## SEE ALSO

[elf(3)](/elf/3.md), [elf\_begin(3)](/elf_begin/3.md), [elf\_end(3)](/elf_end/3.md), [elf\_next(3)](/elf_next/3.md), [elf\_update(3)](/elf_update/3.md), [gelf(3)](/gelf/3.md)
