expand_number(3bsd)
π 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 β1024Mβ mega β1048576Gβ giga β1073741824Tβ tera β1099511627776Pβ peta β1125899906842624Eβ 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 auint64_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_numberis 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
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian bookworm: libbsd-dev 0.11.7-2
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- nixpkgs unstable: libbsd 0.12.2
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 2007 Eric Anderson <anderson@FreeBSD.org>
- Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms