Skip to content

Latest commit

 

History

History
93 lines (69 loc) · 1.98 KB

api.rst

File metadata and controls

93 lines (69 loc) · 1.98 KB

Table of Contents

LIBBPF API

Error Handling

When libbpf is used in "libbpf 1.0 mode", API functions can return errors in one of two ways.

You can set "libbpf 1.0" mode with the following line:

libbpf_set_strict_mode(LIBBPF_STRICT_DIRECT_ERRS | LIBBPF_STRICT_CLEAN_PTRS);

If the function returns an error code directly, it uses 0 to indicate success and a negative error code to indicate what caused the error. In this case the error code should be checked directly from the return, you do not need to check errno.

For example:

err = some_libbpf_api_with_error_return(...);
if (err < 0) {
    /* Handle error accordingly */
}

If the function returns a pointer, it will return NULL to indicate there was an error. In this case errno should be checked for the error code.

For example:

ptr = some_libbpf_api_returning_ptr();
if (!ptr) {
    /* note no minus sign for EINVAL and E2BIG below */
    if (errno == EINVAL) {
       /* handle EINVAL error */
    } else if (errno == E2BIG) {
       /* handle E2BIG error */
    }
}

libbpf.h

libbpf.h

bpf.h

bpf.h

btf.h

btf.h

xsk.h

xsk.h

bpf_tracing.h

bpf_tracing.h

bpf_core_read.h

bpf_core_read.h

bpf_endian.h

bpf_endian.h