expand_number(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– expand_number β€” the 3bsd page, but make it cute πŸ’–

okay bestie, so this is expand_number(3bsd), aka the libbsd girlie who takes your lil human-readable number string and turns it into a real actual number. she's from the 3bsd manual section, she's serving utility, she's iconic, let's go 🫢


✨ NAME ✨

expand_number β€” format a number from human readable form

yes that's the whole vibe. un-formatting. reverse-formatting. taking the cute lil 1K you wrote and making it a whole real integer. the way that she does that πŸ’…


πŸ“š LIBRARY πŸ“š

Utility functions from BSD systems (libbsd, -lbsd)

so like, she lives in libbsd, and when you're linking you hit her with -lbsd. no cap.


🌸 SYNOPSIS 🌸

#include <libutil.h>

(See libbsd(7) for include usage.)

int
expand_number(const char *buf, uint64_t *num);
not me reminding you that you gotta peep libbsd(7) for how the include situation actually works. read it. it's giving necessary. πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

The expand_number() function unformats the buf string and stores an unsigned 64-bit quantity at address pointed out by the num argument.

fr fr that's the whole job. you hand her a string, she hands you back a uint64_t at the address num points to. glow up complete ✨

The expand_number() function follows the SI power of two convention.

periodt. SI power of two. not power of ten. remember that, it matters, iykyk.

The prefixes are:

  • k β€” kilo β€” 1024
  • M β€” mega β€” 1048576
  • G β€” giga β€” 1073741824
  • T β€” tera β€” 1099511627776
  • P β€” peta β€” 1125899906842624
  • E β€” exa β€” 1152921504606846976

those are the whole alphabet besties, k through E, no more, no less. memorize them or don't, she'll tell you if you're wrong (see ERRORS, she's dramatic about it πŸ’€)


πŸ‘‘ RETURN VALUES πŸ‘‘

Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

so: 0 = slay, -1 = not slay, and errno is the group chat message explaining what went wrong. always check her. she's not gonna text you twice. πŸ’–


πŸ’€ ERRORS πŸ’€

The expand_number() function will fail if:

  • [EINVAL] β€” The given string contains no digits. β€” like bestie there is literally nothing numeric in here. what am i supposed to do with that. 😭
  • [EINVAL] β€” An unrecognized prefix was given. β€” you gave her a prefix that is not in the list above. she checked. she's not mad, she's just disappointed.
  • [ERANGE] β€” Result doesn't fit into 64 bits. β€” you asked for a number so big it cannot exist in a uint64_t. that's not a number, that's a dream. it does not fit. πŸ’€

🌈 SEE ALSO 🌈

  • humanize_number(3bsd) β€” the other direction. she's the one who makes numbers look cute, expand_number is the one who un-cutes them. they're a duo. main character energy from both of them honestly.

πŸ“œ HISTORY πŸ“œ

The expand_number() function first appeared in FreeBSD 6.3.

she's been serving since FreeBSD 6.3 and she has not missed a day since πŸŽ€


and that's the whole page bestie!! mwah πŸ’‹

this lil rewrite is from the Debian crew, dated August 15, 2010 β€” the expand_number(3bsd) era. take care of her, she's a legacy icon πŸ‘‘βœ¨

πŸ“¦ where this page comes from