scan_ulong(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– scan_ulong(3) πŸ’–

okay bestie, welcome to scan_ulong(3) from the Library Functions Manual β€” she's a lil libowfat legend and she's here to turn your text into a number, no drama, no detours. let's get into it 🫢


✨ NAME ✨

scan_ulong β€” parse an unsigned long integer in decimal ASCII representation


🌸 SYNTAX 🌸

#include <libowfat/scan.h>

size_t scan_ulong(const char *src,unsigned long *dest);

πŸ’… DESCRIPTION πŸ’…

so scan_ulong does the thing: it parses an unsigned long integer in decimal ASCII representation out of src, and writes the result straight into dest. and then β€” the part everyone forgets β€” it returns the number of bytes it read from src. periodt.

now, she is picky and we love that for her. a leading + or - or space (or literally anything outside of 0-9) is not accepted. and no, she does not do the libc conventions where "023" means octal or "0x23" means hexadecimal β€” those are not supported. nope. not the vibe. πŸ™ˆ

she also knows when to stop: scan_ulong will abort the scan if the next character is not a digit, or if it is a digit but adding it to the number would lead to an integer overflow. she's not about to let you overflow, bestie, that's not happening on her watch. πŸ’€


πŸŽ€ RETURN VALUE πŸŽ€

scan_ulong returns the number of characters successfully scanned and processed from src. that's it, that's the tea β€” how far she got, in bytes. ✨


πŸ¦‹ EXAMPLES πŸ¦‹

okay these are so satisfying, watch:

scan_ulong("23",&i) -> i=23, return 2

scan_ulong("+23",&i) -> return 0

scan_ulong("-23",&i) -> return 0

scan_ulong(" 23",&i) -> return 0

scan_ulong("23,42",&i) -> i=23, return 2

scan_ulong("023",&i) -> i=23, return 3

scan_ulong("0x23",&i) -> i=0, return 1

scan_ulong("4294967296",&i") -> i=429496729, return 9 // 32-bit system

see how "023" gives you i=23 with return 3 β€” she read all three digits, she just doesn't do octal. and "0x23"? she grabs the 0, hits the x, and bails β€” i=0, return 1. iconic behaviour honestly. πŸ‘‘


🌈 SEE ALSO 🌈


and that's the whole page, bestie!! this was scan_ulong(3), living in section 3 of the Library Functions Manual, and yeah β€” same name up top, same name down at the bottom, she's consistent like that. πŸ’œ go forth and parse responsibly, mwah πŸ§šπŸ’–