Skip to content

Libbpf userspace function libbpf_get_error

0.0.1

Extracts the error code from the passed pointer

Definition

long libbpf_get_error(const void *ptr);

Parameters

  • ptr: pointer returned from libbpf API function

Return

error code; or 0 if no error occurred

Usage

As of libbpf 1.0 this function is not necessary and not recommended to be used. Libbpf doesn't return error code embedded into the pointer itself. Instead, NULL is returned on error and error code is passed through thread-local errno variable. libbpf_get_error() is just returning -errno value if it receives NULL, which is correct only if errno hasn't been modified between libbpf API call and corresponding libbpf_get_error() call. Prefer to check return for NULL and use errno directly.

This API is left in libbpf 1.0 to allow applications that were 1.0-ready before final libbpf 1.0 without needing to change them.

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome