nbdkit_parse_int - Man Page
parse numbers for nbdkit
Synopsis
#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);
Description
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.
History
nbdkit_parse_int
and the others were added in nbdkit 1.16.
See Also
nbdkit(1), nbdkit_parse_bool(3), nbdkit_parse_delay(3), nbdkit_parse_probability(3), nbdkit_parse_size(3), nbdkit-plugin(3), nbdkit-filter(3).
Authors
Richard W.M. Jones
Copyright
Copyright Red Hat
License
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Referenced By
nbdkit_parse_bool(3), nbdkit_parse_delay(3), nbdkit_parse_probability(3), nbdkit_parse_size(3), nbdkit-plugin(3).
The man pages nbdkit_parse_int16_t(3), nbdkit_parse_int32_t(3), nbdkit_parse_int64_t(3), nbdkit_parse_int8_t(3), nbdkit_parse_uint16_t(3), nbdkit_parse_uint32_t(3), nbdkit_parse_uint64_t(3), nbdkit_parse_uint8_t(3) and nbdkit_parse_unsigned(3) are aliases of nbdkit_parse_int(3).