scan_base64(3)
π scan_base64 β bestie's guide to decoding base64 π
okay so this is scan_base64, a lil function from the Library Functions Manual (section 3, the library-functions girlies), and it does exactly one thing: it takes base64 text and turns it back into actual bytes. that's it. that's the whole job. and she ate. π
β¨ NAME β¨
scan_base64 β decode base64 encoded data π
πΈ SYNTAX πΈ
lowkey the first thing you do is include the header, no cap:
#include <libowfat/textcode.h>
size_t scan_base64(const char *src,char *dest,size_t* destlen);
look at that signature. src goes in, dest comes out, and destlen is a pointer so she can tell you how much she wrote. the way that this is such a clean API?? obsessed. π¦
π§ DESCRIPTION π§
so like. scan_base64 decodes base64 encoded data from src into dest. it'll stop the instant it runs into any non-valid input character β like, she is not playing around, one bad character and she's done. when she stops, she writes the number of decoded bytes she put into dest into *destlen, and she returns the number of bytes she decoded from src. two numbers, two places, very demure, very mindful. β¨
β οΈ heads up bestie: real-world base64 data is sometimes allowed to have whitespace characters or new lines in it. this function does not allow those, and it'll just return the decoded data up until that point. so if your input has random spaces or line breaks in it, she is going to stop right there and hand you back whatever she got. not her problem, fr fr. π
now about padding β many base64 variants demand padding in the last block. some don't. this implementation is chill like that: she will consume padding if it's there, but she will not complain if it's not. queen behavior honestly. π
and the flex that matters:
destcan beNULL.destlencan beNULL.destcan besrc. (yes, in place, she's versatile like that π )
π₯ RETURN VALUE π₯
scan_base64 returns the number of bytes successfully scanned and processed from src. that's the number. that's what you get back. periodt. π
β EXAMPLES β
okay here's the iconic one, look at her go:
scan_base64("Zm5vcmQ=",buf,&i) -> return 8, i=5, buf="fnord"
so: returns 8, sets i=5, and buf becomes "fnord". eight bytes eaten from the input, five bytes of actual decoded goodness written out. chef's kiss. π₯
π SEE ALSO π
scan_base64url(3)β the URL-safe cousin π¦scan_xlong(3)β hex-ish long scanning energyscan_8long(3)β octal long scanning, also iconicfmt_ulong(3)β the other direction, formatting aunsigned long
π SIGN-OFF π
that's the whole page, bestie!! and listen, the footer is literally just the page name again β scan_base64(3) β sitting pretty at the bottom of the Library Functions Manual. no extra version number, no date, nothing. she's mysterious like that. π
anyway go decode something cute, drink water, and remember: dest can be src. iykyk. π
β¨ππ«Ά
scan_base64(3) β Library Functions Manual
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms