ELF\_RAND(3) Libelf Programmer's Manual ELF\_RAND(3)

# [NAME](#NAME)

elf\_rand - Set the offset for the next archive member in an ELF file.

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
size_t elf_rand(Elf *elf, size_t offset);
```

# [DESCRIPTION](#DESCRIPTION)

The **elf\_rand**() function sets the current archive member offset for the ELF archive descriptor *elf* to *offset*.

This function is only valid when *elf* refers to an archive descriptor (i.e., its kind is **ELF\_K\_AR**).

Archive member offsets can be acquired from the *Elf\_Arsym* array returned by [**elf\_getarsym**(3)](/man/os/elfutils/elf_getarsym.3).

If the archive header at the given offset cannot be parsed or validated, then 0 is returned.

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

A pointer to an ELF archive descriptor.

[*offset*](#offset)

A byte offset to the archive header, indicating the desired member position.

# [RETURN VALUE](#RETURN_VALUE)

Returns the input *offset* if successful. Returns 0 if *elf* is NULL, is not an archive descriptor, or if an error occurs while reading the member at *offset*.

# [SEE ALSO](#SEE_ALSO)

[**elf\_getarsym**(3)](/man/os/elfutils/elf_getarsym.3), [**elf\_next**(3)](/man/os/elfutils/elf_next.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** elf\_rand () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;elfutils-devel@sourceware.org&gt; or https://sourceware.org/bugzilla/.

2025-06-30 Libelf

---

Document: elf_rand(3) from elfutils 0.196-r1 (Chainguard OS)
Source: https://sourceware.org/git/elfutils.git
