qh_str_to_errno()

QNX SDP8.0QNX Helpers Developer's GuideAPIDeveloper

Safely converts a string that represents an errno symbol or number into its corresponding errno value (an int)

Synopsis:

#include <qh/string.h>
int qh_str_to_errno(const char *str,
                    int *number,
                    size_t *end_offset)

Arguments:

str
The string to convert into an errno number.
number
Pointer to the location where the errno value can be stored.
end_offset
The offset where parsing stopped.

Library:

qh

Description:

The qh_str_to_errno() function converts a string that represents an errno symbol or number (e.g., ENOMEM, EOK, etc.) to an errno number. The string is interpreted as a symbol first, and as a decimal (base 10) otherwise.

When passed a number, it is similar to strtoll(), but does more error checking on the result of the conversion and ensures that the result fits in an int. This simplifies the work the caller is required to do, which is only to validate that the return value from qh_str_to_errno() is EOK.

To convert strings that are part of a longer one (e.g., a comma-separated list), you can specify the optional end_offset parameter. When you specify end_offset, the function returns successfully even if there are trailing characters. When non-NULL, end_offset is always updated with the offset of the last character the function parsed. When NULL, the function treats trailing characters as invalid, except for characters recognized by isspace().

For more information on using this function, see the documentation for strtoll().

Returns:

EOK on success or a standard errno on failure (errno is also set, and number isn't updated, even for ERANGE).

ERANGE
The number value is either smaller than INT_MIN or larger than INT_MAX.
Page updated: