---
name: "elf_getshdrnum"
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_getshdrnum"
---

# elf\_getshdrnum(3)

return the number of sections in an ELF file

## NAME

**elf\_getshdrnum** – return the number of sections in an ELF file

## LIBRARY

library “libelf”

## SYNOPSIS

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

*int*\

**elf\_getshdrnum**(*Elf \*elf*, *size\_t \*shnum*);

## DESCRIPTION

Function **elf\_getshdrnum**() retrieves the number of ELF sections associated with descriptor *elf* and stores it into the location pointed to by argument *shnum*.

This routine allows applications to uniformly process both normal ELF objects, and ELF objects that use extended section numbering.

## RETURN VALUES

Function **elf\_getshdrnum**() returns zero value if successful, or -1 in case of an error.

## ERRORS

Function **elf\_getshdrnum**() can fail with the following errors:

- \[ELF\_E\_ARGUMENT\]

  A NULL value was passed in for argument *elf*.

- \[ELF\_E\_ARGUMENT\]

  Argument *elf* was not for an ELF file.

- \[ELF\_E\_ARGUMENT\]

  Argument *elf* lacks an ELF Executable header.

## SEE ALSO

[elf(3)](/elf/3.md), [elf32\_getehdr(3)](/elf32_getehdr/3.md), [elf64\_getehdr(3)](/elf64_getehdr/3.md), [elf\_getident(3)](/elf_getident/3.md), [elf\_getphdrnum(3)](/elf_getphdrnum/3.md), [elf\_getshdrstrndx(3)](/elf_getshdrstrndx/3.md), [gelf(3)](/gelf/3.md), [gelf\_getehdr(3)](/gelf_getehdr/3.md)
