---
name: "elf_next"
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_next"
---

# elf\_next(3)

provide sequential access to the next archive member

## NAME

**elf\_next** – provide sequential access to the next archive member

## LIBRARY

library “libelf”

## SYNOPSIS

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

*Elf\_Cmd*\

**elf\_next**(*Elf \*elf*);

## DESCRIPTION

The **elf\_next**() function causes the ELF archive descriptor corresponding to argument *elf* to be adjusted to provide access to the next member in the archive on a subsequent call to **elf\_begin**().

The return value of **elf\_next**() is suitable for use in a loop invoking **elf\_begin**().

## RETURN VALUES

If successful, function **elf\_next**() returns the value ELF\_C\_READ. Otherwise, if argument *elf* was not associated with an archive, or if it was NULL, or if any other error occurred, the value ELF\_C\_NULL is returned.

## EXAMPLES

To process all the members of an archive use:

```
Elf_Cmd cmd;
Elf *archive, *e;
...
cmd = ELF_C_READ;
archive = elf_begin(fd, cmd, NULL);
while ((e = elf_begin(fd, cmd, archive)) != (Elf *) 0)
{
	... process `e' here ...
	cmd = elf_next(e);
	elf_end(e);
}
elf_end(archive);
```

## ERRORS

Function **elf\_next**() may fail with the following error:

- \[ELF\_E\_ARGUMENT\]

  Argument *elf* was not associated with a containing [ar(1)](/ar/1.md) archive.

- \[ELF\_E\_ARGUMENT\]

  An error was encountered while parsing the archive containing argument *elf*.

## SEE ALSO

[elf(3)](/elf/3.md), [elf\_begin(3)](/elf_begin/3.md), [elf\_end(3)](/elf_end/3.md), [elf\_rand(3)](/elf_rand/3.md)
