aprintf(3)
β¨ aprintf β allocate and print formatted string β¨
okay bestie, sit DOWN, because this is one of those little gnulib gems that's lowkey iconic π It's from the Library Functions Manual, and it's about aprintf and vaprintf β the two functions that format your string AND hand you a freshly allocated buffer for it. no cap, it's giving "sprintf but it actually brings its own house" π β¨
πΈ LIBRARY πΈ
gnulib β The GNU Portability Library π«Ά
π SYNOPSIS π
#include <stdio.h>
char *aprintf(const char *restrict fmt, ...);
char *vaprintf(const char *restrict fmt, va_list ap);
like. look at it. two little lines and they carry so much power π
π¦ DESCRIPTION π¦
so here's the tea, bestie β β aprintf() and vaprintf() are analogs of sprintf(3) and vsprintf(3). same energy, same formatting, everything. the ONE difference? instead of making you bring your own buffer and pray you sized it right, their output gets written into a space that's allocated as if by a call to malloc(3). it just. does it for you. main character behavior, honestly π
and because it's malloc'd, that pointer should be passed to free(3) to release the allocated storage when it's no longer needed. yes bestie, you gotta clean up after yourself. free is not optional, it's the whole vibe check π§Ή
β οΈ do not lose that pointer. do not forget to free it. the allocator is watching. π
π RETURN VALUE π
- on success β you get back a pointer to the first character of the formatted string β¨
- on error β
-1is returned, anderrnois set to indicate the error π
π ERRORS π
fr fr, just go check sprintf(3) and malloc(3). they've got the receipts π
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7). π§
aprintf(),vaprintf()β Thread safety:MT-Safe localeπ«Ά
β STANDARDS β
None. π not a single one. it's a gnulib thing, bestie, it lives outside the standards, we don't ask questions.
π°οΈ HISTORY π°οΈ
gnulib 202607 π (yes, that's a version string. no, we are not elaborating.)
π SEE ALSO π
free(3), malloc(3), sprintf(3), strdup(3), asprintf(3) πΈ
go read them. iykyk. they're the friend group and this page is the group chat π
like that's the whole page, bestie. go format something, allocate something, and free it after. periodt. π
β¨
signing off from Linux man-pages 6.20, dated 2026-03-16 β this has been your girl for aprintf(3) ππ¦π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms