---
name: "elf_errmsg"
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_errmsg"
---

# elf\_errmsg(3)

ELF library error message handling

## NAME

**elf\_errmsg**, **elf\_errno** – ELF library error message handling

## LIBRARY

library “libelf”

## SYNOPSIS

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

*int*\

**elf\_errno**(*void*);

*const char \**\

**elf\_errmsg**(*int error*);

## DESCRIPTION

When an error occurs during an ELF library API call, the library encodes the error using an error number and stores the error number internally for retrieval by the application at a later point of time. Error numbers may contain an OS supplied error code in addition to an ELF API specific error code. An error number value of zero indicates no error.

Function **elf\_errno**() is used to retrieve the last error recorded by the ELF library. Invoking this function has the side-effect of resetting the ELF library's recorded error number to zero.

The function **elf\_errmsg**() returns a null-terminated string with a human readable description of the error specified in argument *error*. A zero value for argument *error* retrieves the most recent error encountered by the ELF library. An argument value of -1 behaves identically, except that it guarantees a non-NULL return from **elf\_errmsg**().

## RETURN VALUES

Function **elf\_errno**() returns a non-zero value encoding the last error encountered by the ELF library, or zero if no error was encountered.

Function **elf\_errmsg**() returns a pointer to library local storage for non-zero values of argument *error*. With a zero argument, the function will return a NULL pointer if no error had been encountered by the library, or will return a pointer to library local storage containing an appropriate message otherwise.

## EXAMPLES

Clearing the ELF library's recorded error number can be accomplished by invoking **elf\_errno**() and discarding its return value.

```
/* clear error */
(void) elf_errno();
```

Retrieving a human-readable description of the current error number can be done with the following snippet:

```
int err;
const char *errmsg;
...
err = elf_errno();
if (err != 0)
	errmsg = elf_errmsg(err);
```

## SEE ALSO

[elf(3)](/elf/3.md), [gelf(3)](/gelf/3.md)

## BUGS

Function **elf\_errmsg**() is not localized.
