qh_str_to_char()
Safely converts a string into a char
Synopsis:
#include <qh/string.h>
int qh_str_to_char(const char *str,
int base,
char *number,
size_t *end_offset)
Arguments:
- str
- The string to convert into a number.
- base
- The base of the number to parse.
- number
- Pointer to the location where the number can be stored.
- end_offset
- The offset where parsing stopped.
Library:
qhDescription:
This function is similar to strtoll(), but does more error checking on the result of the conversion and ensures that the result fits in a char. This simplifies the work the caller is required to do, which is only to validate that the return value from qh_str_to_char() is EOK.
For conversion of strings that are part of a longer one (e.g., a comma-separated list), an optional end_offset parameter can be specified. 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().
Depending on target architecture, char may be signed or unsigned. A check is done based on CHAR_MIN to determine which conversion must be made.
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 except for ERANGE).
- ERANGE
- The number value is either smaller than
CHAR_MIN
(andCHAR_MIN
is returned) or larger thanCHAR_MAX
(andCHAR_MAX
is returned).