public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: libc-alpha@sourceware.org
Cc: Alejandro Colomar <alx@kernel.org>,
	Joseph Myers <josmyers@redhat.com>,
	 Paul Eggert <eggert@cs.ucla.edu>,
	Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	 Florian Weimer <fweimer@redhat.com>,
	"Dmitry V. Levin" <ldv@altlinux.org>,
	 Archie Cobbs <archie.cobbs@gmail.com>,
	Solar Designer <solar@openwall.com>, Sam James <sam@gentoo.org>
Subject: [RFC v4 2/2] manual/: Prefer aprintf(3) over asprintf(3)
Date: Wed, 18 Mar 2026 22:47:56 +0100	[thread overview]
Message-ID: <f1dca5c0dec5a4323888d6392cc80ce2b60f1718.1773870057.git.alx@kernel.org> (raw)
In-Reply-To: <cover.1773870057.git.alx@kernel.org>

While it's less portable at the moment, it's a better API (simpler,
safer, and less error-prone).

The C Committee has expressed strong support for this API, intending to
standardize it.  Thus, it should be more portable in the long term.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 manual/examples/rprintf.c | 4 ++--
 manual/stdio.texi         | 4 ++--
 manual/string.texi        | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/manual/examples/rprintf.c b/manual/examples/rprintf.c
index 734a8768..736ac169 100644
--- a/manual/examples/rprintf.c
+++ b/manual/examples/rprintf.c
@@ -38,8 +38,8 @@ print_widget (FILE *stream,
 
   /* Format the output into a string. */
   w = *((const Widget **) (args[0]));
-  len = asprintf (&buffer, "<Widget %p: %s>", w, w->name);
-  if (len == -1)
+  buffer = aprintf ("<Widget %p: %s>", w, w->name);
+  if (buffer == NULL)
     return -1;
 
   /* Pad to the minimum field width and print to the stream. */
diff --git a/manual/stdio.texi b/manual/stdio.texi
index e7deca78..91149626 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -2458,7 +2458,7 @@ because it can potentially output more characters than can fit in the
 allocation size of the string @var{s}.  Remember that the field width
 given in a conversion specification is only a @emph{minimum} value.
 
-To avoid this problem, you can use @code{snprintf} or @code{asprintf},
+To avoid this problem, you can use @code{snprintf} or @code{aprintf},
 described below.
 @end deftypefun
 
@@ -2543,7 +2543,7 @@ make_message (char *name, char *value)
 @end group
 @end smallexample
 
-In practice, it is often easier just to use @code{asprintf}, below.
+In practice, it is often easier just to use @code{aprintf}, below.
 
 @strong{Attention:} In versions of @theglibc{} prior to 2.1 the
 return value is the number of characters stored, not including the
diff --git a/manual/string.texi b/manual/string.texi
index 24004f1f..7a6ee12a 100644
--- a/manual/string.texi
+++ b/manual/string.texi
@@ -1198,7 +1198,7 @@ strings to fit arbitrary size limits.  @xref{Semantics, , Writing
 Robust Programs, standards, The GNU Coding Standards}.  Instead of
 string-truncation functions, it is usually better to use dynamic
 memory allocation (@pxref{Unconstrained Allocation}) and functions
-such as @code{strdup} or @code{asprintf} to construct strings.
+such as @code{strdup} or @code{aprintf} to construct strings.
 
 @node String/Array Comparison
 @section String/Array Comparison
-- 
2.53.0


  parent reply	other threads:[~2026-03-18 21:48 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <67914111.3F2A3RajZp@nimes>
     [not found] ` <4061901.EY2tGkamZC@nimes>
     [not found]   ` <abGuWoDCvXIak5sO@devuan>
     [not found]     ` <5056394.2IPslxdN4N@nimes>
     [not found]       ` <abM4gjPAfmbwT5zH@devuan>
     [not found]         ` <546935fd-9a3a-4b08-b39a-0c398ddb45d6@cs.ucla.edu>
2026-03-13 23:31           ` New functions [v]aprintf(3) Alejandro Colomar
2026-03-17 18:59             ` [RFC v1] libio/: Add [v]aprintf() Alejandro Colomar
2026-03-17 19:05               ` Alejandro Colomar
2026-03-17 19:26               ` Adhemerval Zanella Netto
2026-03-17 19:40                 ` Alejandro Colomar
2026-03-17 19:56                   ` Adhemerval Zanella Netto
2026-03-17 20:22                     ` Alejandro Colomar
2026-03-18  1:17                     ` Alejandro Colomar
2026-03-21  1:38                       ` Solar Designer
2026-05-17 19:02                         ` Alejandro Colomar
2026-03-17 20:40               ` Joseph Myers
2026-03-17 20:57                 ` Alejandro Colomar
2026-03-17 19:26             ` [RFC v2] Add [v]aprintf(3) Alejandro Colomar
2026-03-17 20:16               ` Adhemerval Zanella Netto
2026-03-17 20:35                 ` Alejandro Colomar
2026-03-17 20:52                   ` Joseph Myers
2026-03-17 21:10                     ` Alejandro Colomar
2026-03-18  7:18                     ` Florian Weimer
2026-03-18 13:51                       ` Alejandro Colomar
2026-03-18 18:14             ` [RFC v3 0/2] " Alejandro Colomar
2026-03-18 18:15               ` [RFC v3 1/2] " Alejandro Colomar
2026-03-18 18:15               ` [RFC v3 2/2] manual/: Prefer aprintf(3) over asprintf(3) Alejandro Colomar
2026-03-18 18:27               ` [RFC v3 0/2] Add [v]aprintf(3) Joseph Myers
2026-03-18 18:49                 ` Alejandro Colomar
2026-03-18 21:47             ` [RFC v4 " Alejandro Colomar
2026-03-18 21:47               ` [RFC v4 1/2] " Alejandro Colomar
2026-03-20 16:53                 ` Joseph Myers
2026-03-20 20:07                   ` Alejandro Colomar
2026-03-20 17:41                 ` Adhemerval Zanella Netto
2026-03-20 20:19                   ` Alejandro Colomar
2026-03-18 21:47               ` Alejandro Colomar [this message]
2026-03-20 16:50               ` [RFC v4 0/2] " Joseph Myers
2026-03-20 20:22                 ` Alejandro Colomar
2026-04-22 18:37             ` [PATCH 0/3] " Alejandro Colomar
2026-04-22 18:37               ` [PATCH 1/3] " Alejandro Colomar
2026-04-22 18:38               ` [PATCH 2/3] manual/: Prefer aprintf(3) over asprintf(3) Alejandro Colomar
2026-04-22 18:38               ` [PATCH 3/3] sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c: Fix typo Alejandro Colomar
2026-04-22 19:34               ` [PATCH 0/3] Add [v]aprintf(3) Alejandro Colomar
2026-05-15 23:28               ` Alejandro Colomar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f1dca5c0dec5a4323888d6392cc80ce2b60f1718.1773870057.git.alx@kernel.org \
    --to=alx@kernel.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=archie.cobbs@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=fweimer@redhat.com \
    --cc=josmyers@redhat.com \
    --cc=ldv@altlinux.org \
    --cc=libc-alpha@sourceware.org \
    --cc=sam@gentoo.org \
    --cc=solar@openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).