QH_RET_ERRNO_WEOK()

Updated: April 19, 2023

A macro that conditionally sets errno and always returns the specified error

Synopsis:

#include <qh/error.h>
#define QH_RET_ERRNO_WEOK(errno)

Arguments:

errno
The standard errno to set errno to (if not EOK) and then return with.

Library:

qh

Description:

If the errno passed in is not EOK, errno is set to it, and then the pre-evaluated value of errno is returned. If errno evaluates to EOK, errno is not set, but EOK is returned.

Because this is a macro that calls return, the invoking function actually returns when the macro is executed. The invoking function is expected to have an int as its return type.

Because what is passed in to the macro is only evaluated once, it is safe to execute operations as part of calling the macro.