nbdkit_parse_int(3)

πŸ’– nbdkit_parse_int(3) πŸ’–

okay bestie, so this is one of the nbdkit manual pages β€” specifically the one for the number-parsing girlies. no cap, it's lowkey the most useful thing in the whole plugin toolkit. let's get into it 🫢


✨ NAME ✨

nbdkit_parse_int, nbdkit_parse_unsigned, nbdkit_parse_int8_t, nbdkit_parse_int16_t, nbdkit_parse_int32_t, nbdkit_parse_int64_t, nbdkit_parse_uint8_t, nbdkit_parse_uint16_t, nbdkit_parse_uint32_t, nbdkit_parse_uint64_t β€” the whole friend group that parses 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 ✨

so the vibe is: you take a string str and you turn it into an integer of literally whatever type you want. glow-up for strings, fr fr. ✨

these functions parse a decimal, a hexadecimal (0x...) or an octal (0...) number. so many bases, so little time. 🌈

here's the part where they ate: these functions deal correctly with overflow, out of range and parse errors. which means you should be using them instead of the unsafe ones like sscanf(3), atoi(3) and similar. those other ones are giving πŸ’€ energy. do not trust them. bestie please.

the what parameter gets printed in error messages so you know what was being parsed when everything went sideways β€” it's the context, the receipts, the "who was this even about". it should usually be a short descriptive string of what you're trying to parse, eg:

if (nbdkit_parse_int ("random seed", value, &seed) == -1)
  return -1;

and that might print an error like:

random seed: could not parse number: "lalala"

see? "lalala" is not a number and the error message is being so real about it. 😭 iconic behavior honestly.


✨ RETURN VALUE ✨

on success the functions return 0. slay. πŸ’–

if r != NULL, they set *r to the parsed value. if r == NULL, the parsing is done but the result is just… discarded. thrown away. ghosted. the parse happened, we just don't care about the outcome. πŸ™ˆ

on error, nbdkit_error(3) is called and the functions return -1. and here's the important bit β€” on error *r is always unchanged. no sneaky half-written garbage in your variable. she's untouched. periodt. πŸ‘‘


✨ HISTORY ✨

nbdkit_parse_int and the others were added in nbdkit 1.16. so they're not new-new but they're not ancient either. the origin story. 🌸


✨ SEE ALSO ✨

the whole parse-y friend group, go read them too iykyk πŸ¦‹


✨ AUTHORS ✨

Richard W.M. Jones β€” the author, the moment, the main character πŸ‘‘


Copyright Red Hat


✨ LICENSE ✨

so legally speaking, bestie, here's the deal β€” 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.

like i said: the legalese stays the legalese, i'm just here to make it cute around the edges. πŸŽ€


and that's the whole page, babe!! this was nbdkit 1.48.1, dated 2026-08-29, and it's the nbdkit_parse_int(3) manual, signing off. go parse some numbers safely. you're gonna do amazing. πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from