nbdkit_parse_unsigned3
Parse numbers for nbdkit
Part of nbdkit_parse_int(3).
Usage
#include <nbdkit-plugin.h>int nbdkit_parse_int (const char *what, const char *str, int *r);int nbdkit_parse_unsigned (const char *what,const char *str, unsigned *r);int nbdkit_parse_int8_t (const char *what,const char *str, int8_t *r);int nbdkit_parse_uint8_t (const char *what,const char *str, uint8_t *r);int nbdkit_parse_int16_t (const char *what,const char *str, int16_t *r);int nbdkit_parse_uint16_t (const char *what,const char *str, uint16_t *r);int nbdkit_parse_int32_t (const char *what,const char *str, int32_t *r);int nbdkit_parse_uint32_t (const char *what,const char *str, uint32_t *r);int nbdkit_parse_int64_t (const char *what,const char *str, int64_t *r);int nbdkit_parse_uint64_t (const char *what,const char *str, uint64_t *r);
Overview
Parse string "str" into an integer of various types. These functions parse a decimal, hexadecimal ("0x...") or octal ("0...") number.
These functions deal correctly with overflow, out of range and parse errors, and you should use them instead of unsafe functions like sscanf(3), atoi(3) and similar.
The "what" parameter is printed in error messages to provide context. It should usually be a short descriptive string of what you are trying to parse, eg:
if (nbdkit_parse_int ("random seed", value, &seed) == -1)return -1;
might print an error:
random seed: could not parse number: "lalala"
Return value
On success the functions return 0 and set *r to the parsed value (unless "*r == NULL" in which case the result is discarded).
On error, nbdkit_error(3) is called and the functions return -1. On error *r is always unchanged.