aprintf(3)

πŸ“¦
version 6.20 Β· 3 versions
, in arch rolling, nixpkgs unstable

✨ 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 β†’ -1 is returned, and errno is 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