qh_sticky_error()

Updated: April 19, 2023

Store a new error code as a variable if the new error is not zero and the previously stored one is

Synopsis:

#include <qh/error.h>
int qh_sticky_error(int *sticky_error,
                    int new_error)

Arguments:

sticky_error
The location in which to store the first error code encountered in successive calls to the function.
new_error
The new error code to use, if sticky_error is 0.

Library:

qh

Description:

This function allows a caller to make successive calls with a sticky_error variable and a new, potentially different error. After the caller makes successive calls to the this function, it can look at the value of sticky_error to determine what the first error was, if any.

In addition to standard error numbers (e.g., errno), this function can be used with any set of error codes that consider zero to indicate success (e.g., many enumerated types).

Returns:

The value of new_error.