Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

a64l / l64a (3) - glibc

Split from the chapter glibc: strings, ctype and stdlib arithmetic into the per-function layout; see the method page and the glibc ledger for coverage status.

FieldValue
Headerstdlib.h
StandardsPOSIX.1-2001, POSIX.1-2008 (XSI heritage; a64l(3) CONFORMING TO)
Exporteda64l@@GLIBC_2.2.5 (strong), l64a@@GLIBC_2.2.5 (strong) (nm, host glibc 2.41)
Thread-safetya64l: MT-Safe; l64a: MT-Unsafe race:l64a (a64l(3) ATTRIBUTES)
Ledger IDGLIBC-a64l, GLIBC-l64a

Declaration and gates

#include <stdlib.h>

long a64l(const char *str64);
char *l64a(long value);

Declared in stdlib.h lines 503-511 under defined __USE_MISC || defined __USE_XOPEN_EXTENDED (/usr/include/stdlib.h). The man page records the same history as feature macros: _XOPEN_SOURCE >= 500, else _DEFAULT_SOURCE (glibc 2.19 and later), else _SVID_SOURCE (before 2.19) - so both are visible in default builds.

Semantics

The pair converts between 32-bit long values and little-endian base-64 ASCII strings of up to six bytes. The digit order runs . (0), / (1), 0-9 (2-11), A-Z (12-37), a-z (38-63); the man page example encodes 123 as "v/". a64l uses only the first six bytes of its input and sign-extends the 32-bit result; l64a uses only the low 32 bits of value and returns a pointer to static storage (a64l(3)).

Gotchas and portability

  • l64a is the only MT-Unsafe member of this batch: it returns a static buffer that the next call overwrites (a64l(3) ATTRIBUTES MT-Unsafe race:l64a and NOTES). Serialize it or copy the result immediately.
  • l64a(0) returns the empty string, and its behavior is undefined for negative value (a64l(3) NOTES) - sign handling is entirely on the caller.
  • Round-tripping is not trivial: a64l reads at most six bytes, so an l64a string embedded in longer text must be cut out first.
  • glibc before 2.2.5 had the digit order backwards (most significant digit first) - old binaries and old docs disagree with modern output (a64l(3) NOTES).
  • This is not the uuencode(1) alphabet (a64l(3) NOTES) - the leading .// digits are the giveaway.
  • musl 1.2.5 implements both (musl include/stdlib.h lines 125-126).

References

  • glibc manual: string.texi, node Encode Binary Data (documents both as XPG, @standards{XPG, stdlib.h}, with the digit table; the man-page digit list matches it)
  • man3: a64l(3) (covers l64a)
  • header: /usr/include/stdlib.h
  • symbols: nm -D --with-symbol-versions libc.so.6