From patchwork Wed Mar 18 18:15:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 131917 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 4B2404BBC0BC for ; Wed, 18 Mar 2026 18:16:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B2404BBC0BC Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=A0vr8LzT X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) by sourceware.org (Postfix) with ESMTPS id DA8094BC89A2 for ; Wed, 18 Mar 2026 18:15:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA8094BC89A2 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DA8094BC89A2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2600:3c0a:e001:78e:0:1991:8:25 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773857706; cv=none; b=RxFfDd+cZxCP097KbP/TMt+tFCc3FUgncUwAznaxajA7Q+o3LsaxPZfaNiyjJz+Mv0YEMTCbew27hjX+QUjL72P0gHVgKmiETTyZ23shhkoVCsN0db3vMm0HnCfbqYI/xsLlQylyOTuCKMkarUVULhecJwS2pj89d8PGwNMWqhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773857706; c=relaxed/simple; bh=xVr4+d/sH3Rm5NxSv4SpjRJVgAyDpTOgBM+yv4A+w0Q=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=wHHQKh/haorZX7deazZbRdFij88P2Cv44R6hp4nvEjEqCT5IJEkQGoxbMh/h4oCVY96PeYHTCHt1d/BNQ7RMzXPdHor2KeapPiPL2fYL1YoweOBGz+r5BZ4G71F3e582DPMVUAf/UXTGBBN93LoIDTTnx/MJhSiB/mLK32ynbs4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA8094BC89A2 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 2BCC940905; Wed, 18 Mar 2026 18:15:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2952C19421; Wed, 18 Mar 2026 18:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773857705; bh=xVr4+d/sH3Rm5NxSv4SpjRJVgAyDpTOgBM+yv4A+w0Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A0vr8LzTs7K5+O3TWQj3w/YIHWWYnXxRuudjlYME7hPS8xTHnOe2wn5E6fXglKdZs mH8cNed5d/4/6o+uvO5H0dKXaAsibYkezZE1OoiBMXbektrOSEXab0j1tzRIlbDC8I oepqMDFI2K4yK5vHKvzNek4lIMo5k2uupcONko8O/xdjxO1aq5TLJXSO8JCcVP26k1 tlsNSNMLUwiPnecb01p35VuY6XXeES+XyQeV9sBwAG3Byep4wb1oRhHopWy3AUpvo0 HkmZ9QAXf3nSCiWFSrW57qQym313sgpyyGxjSHywKe2uOpf2T9XfpBEiDGb7Z93p53 I2JAOQpN2SEKg== Date: Wed, 18 Mar 2026 19:15:01 +0100 From: Alejandro Colomar To: libc-alpha@sourceware.org Cc: Alejandro Colomar , Joseph Myers , Paul Eggert , Adhemerval Zanella Netto , Florian Weimer , "Dmitry V. Levin" , Archie Cobbs , Solar Designer , Sam James Subject: [RFC v3 1/2] Add [v]aprintf(3) Message-ID: X-Mailer: git-send-email 2.53.0 References: <916855e5ad90ca3611a235ecbcf08a1359771eb9.1773775432.git.alx@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Signed-off-by: Alejandro Colomar --- debug/Versions | 3 +++ include/stdio.h | 3 +++ libio/Makefile | 4 ++- libio/Versions | 3 +++ libio/bits/stdio-ldbl.h | 2 ++ libio/bits/stdio2-decl.h | 8 ++++++ libio/bits/stdio2.h | 42 ++++++++++++++++++++++++++++++ libio/stdio.h | 10 +++++++ libio/tst-aprintf.c | 56 ++++++++++++++++++++++++++++++++++++++++ libio/vaprintf.c | 39 ++++++++++++++++++++++++++++ manual/stdio.texi | 26 +++++++++++++++++++ stdio-common/Makefile | 2 ++ stdio-common/Versions | 2 ++ stdio-common/aprintf.c | 40 ++++++++++++++++++++++++++++ 14 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 libio/tst-aprintf.c create mode 100644 libio/vaprintf.c create mode 100644 stdio-common/aprintf.c diff --git a/debug/Versions b/debug/Versions index fc818d29..d87148f5 100644 --- a/debug/Versions +++ b/debug/Versions @@ -71,6 +71,9 @@ libc { GLIBC_2.43 { __memset_explicit_chk; } + GLIBC_2.44 { + __aprintf_chk; __vaprintf_chk; + } GLIBC_PRIVATE { __fortify_fail; } diff --git a/include/stdio.h b/include/stdio.h index 88166993..cb9b9210 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -241,6 +241,9 @@ extern const char *__get_errname (int) attribute_hidden; libc_hidden_ldbl_proto (__asprintf) +extern __typeof (aprintf) __aprintf; +libc_hidden_ldbl_proto (__aprintf) + # if IS_IN (libc) extern FILE *_IO_new_fopen (const char*, const char*); # define fopen(fname, mode) _IO_new_fopen (fname, mode) diff --git a/libio/Makefile b/libio/Makefile index 08e1e0ec..cbf311e1 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -43,7 +43,7 @@ routines := \ \ clearerr feof ferror fileno fputc freopen fseek getc getchar \ memstream pclose putc putchar rewind setbuf setlinebuf vasprintf \ - iovdprintf vscanf vsnprintf obprintf fcloseall fseeko ftello \ + vaprintf iovdprintf vscanf vsnprintf obprintf fcloseall fseeko ftello \ freopen64 fseeko64 ftello64 \ \ __fbufsize __freading __fwriting __freadable __fwritable __flbf \ @@ -63,6 +63,7 @@ routines_no_fortify += \ iovdprintf \ swprintf \ vasprintf \ + vaprintf \ vsnprintf \ vswprintf \ vwprintf \ @@ -90,6 +91,7 @@ tests = \ test-fputs-unbuffered-full \ test-fputws-unbuffered-full \ tst-asprintf-null \ + tst-aprintf \ tst-atime \ tst-bz22415 \ tst-bz24051 \ diff --git a/libio/Versions b/libio/Versions index b91a7bc9..48ffe3d3 100644 --- a/libio/Versions +++ b/libio/Versions @@ -155,6 +155,9 @@ libc { # f* fmemopen; } + GLIBC_2.44 { + vaprintf; + } GLIBC_PRIVATE { # Used by NPTL and librt __libc_fatal; diff --git a/libio/bits/stdio-ldbl.h b/libio/bits/stdio-ldbl.h index 3cbff14e..d76720f0 100644 --- a/libio/bits/stdio-ldbl.h +++ b/libio/bits/stdio-ldbl.h @@ -125,6 +125,8 @@ __LDBL_REDIR2_DECL (vdprintf_chk) # ifdef __USE_GNU __LDBL_REDIR2_DECL (asprintf_chk) __LDBL_REDIR2_DECL (vasprintf_chk) +__LDBL_REDIR2_DECL (aprintf_chk) +__LDBL_REDIR2_DECL (vaprintf_chk) __LDBL_REDIR2_DECL (obstack_printf_chk) __LDBL_REDIR2_DECL (obstack_vprintf_chk) # endif diff --git a/libio/bits/stdio2-decl.h b/libio/bits/stdio2-decl.h index ada092ea..d59ac647 100644 --- a/libio/bits/stdio2-decl.h +++ b/libio/bits/stdio2-decl.h @@ -72,6 +72,14 @@ extern int __asprintf_chk (char **__restrict __ptr, int __flag, extern int __vasprintf_chk (char **__restrict __ptr, int __flag, const char *__restrict __fmt, __gnuc_va_list __arg) __THROW __attribute__ ((__format__ (__printf__, 3, 0))) __wur; +extern char *__aprintf_chk (int __flag, + const char *__restrict __fmt, ...) + __THROW __attribute__ ((__format__ (__printf__, 2, 3))) + __attribute_malloc__; +extern char *__vaprintf_chk (int __flag, + const char *__restrict __fmt, __gnuc_va_list __arg) + __THROW __attribute__ ((__format__ (__printf__, 2, 0))) + __attribute_malloc__; extern int __obstack_printf_chk (struct obstack *__restrict __obstack, int __flag, const char *__restrict __format, ...) diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index 193494db..92fe35b5 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -215,6 +215,18 @@ __NTH (__asprintf (char **__restrict __ptr, const char *__restrict __fmt, __va_arg_pack ()); } +__fortify_function char * +__NTH (aprintf (const char *__restrict __fmt, ...)) +{ + return __aprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); +} + +__fortify_function char * +__NTH (__aprintf (const char *__restrict __fmt, ...)) +{ + return __aprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); +} + __fortify_function int __NTH (obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __fmt, ...)) @@ -247,6 +259,26 @@ __NTH (__asprintf (__fortify_clang_overload_arg (char **, __restrict, __ptr), return __r; } +__fortify_function char * +__NTH (aprintf (const char *__restrict __fmt, ...)) +{ + __gnuc_va_list __fortify_ap; + __builtin_va_start (__fortify_ap, __fmt); + char * __p = __vaprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __fortify_ap); + __builtin_va_end (__fortify_ap); + return __p; +} + +__fortify_function char * +__NTH (__aprintf (const char *__restrict __fmt, ...)) +{ + __gnuc_va_list __fortify_ap; + __builtin_va_start (__fortify_ap, __fmt); + char *__p = __vaprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __fortify_ap); + __builtin_va_end (__fortify_ap); + return __p; +} + __fortify_function_error_function __attribute_overloadable__ int __NTH (obstack_printf (__fortify_clang_overload_arg (struct obstack *, __restrict, __obstack), @@ -264,6 +296,10 @@ __NTH (obstack_printf (__fortify_clang_overload_arg (struct obstack *, __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # define __asprintf(ptr, ...) \ __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) +# define aprintf(...) \ + __aprintf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) +# define __aprintf(...) \ + __aprintf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # define obstack_printf(obstack, ...) \ __obstack_printf_chk (obstack, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # endif @@ -275,6 +311,12 @@ __NTH (vasprintf (char **__restrict __ptr, const char *__restrict __fmt, return __vasprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); } +__fortify_function char * +__NTH (vaprintf (const char *__restrict __fmt, __gnuc_va_list __ap)) +{ + return __vaprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __ap); +} + __fortify_function int __NTH (obstack_vprintf (struct obstack *__restrict __obstack, const char *__restrict __fmt, __gnuc_va_list __ap)) diff --git a/libio/stdio.h b/libio/stdio.h index 3bf6a1f6..179441ed 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -412,6 +412,16 @@ extern int asprintf (char **__restrict __ptr, __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur; #endif +#ifdef __USE_GNU +/* Write formatted output to a string dynamically allocated with `malloc'. */ +extern char *vaprintf (const char *__restrict __f, __gnuc_va_list __arg) + __THROWNL __attribute__ ((__format__ (__printf__, 1, 0))) + __attribute_malloc__; +extern char *aprintf (const char *__restrict __fmt, ...) + __THROWNL __attribute__ ((__format__ (__printf__, 1, 2))) + __attribute_malloc__; +#endif + #ifdef __USE_XOPEN2K8 /* Write formatted output to a file descriptor. */ extern int vdprintf (int __fd, const char *__restrict __fmt, diff --git a/libio/tst-aprintf.c b/libio/tst-aprintf.c new file mode 100644 index 00000000..e2c3c911 --- /dev/null +++ b/libio/tst-aprintf.c @@ -0,0 +1,56 @@ +/* Test aprintf. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include + +static int +do_test (void) +{ + char *buf; + { + /* Avoid -Wformat-overflow warning. */ + const char *volatile format = "%2000000000d %2000000000d"; + buf = aprintf (format, 1, 2); + TEST_VERIFY (buf == NULL); + } + if (errno != ENOMEM) + TEST_COMPARE (errno, EOVERFLOW); + + /* Force ENOMEM in the test below. */ + struct rlimit rl; + TEST_COMPARE (getrlimit (RLIMIT_AS, &rl), 0); + rl.rlim_cur = 10 * 1024 * 1024; + TEST_COMPARE (setrlimit (RLIMIT_AS, &rl), 0); + + buf = aprintf ("%20000000d", 1); + TEST_VERIFY (buf == NULL); + TEST_COMPARE (errno, ENOMEM); + + /* Success */ + buf = aprintf ("foo %d", 42); + TEST_COMPARE_STRING (buf, "foo 42"); + free(buf); + + return 0; +} + +#include diff --git a/libio/vaprintf.c b/libio/vaprintf.c new file mode 100644 index 00000000..6789052f --- /dev/null +++ b/libio/vaprintf.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . + + As a special exception, if you link the code in this file with + files compiled with a GNU compiler to produce an executable, + that does not cause the resulting executable to be covered by + the GNU Lesser General Public License. This exception does not + however invalidate any other reasons why the executable file + might be covered by the GNU Lesser General Public License. + This exception applies to code released by its copyright holders + in files containing the exception. */ + +#include +#include +#include +#include + +char * +__vaprintf (const char *fmt, va_list args) +{ + char *p; + + return __vasprintf_internal (&p, fmt, args, 0) < 0 ? NULL : p; +} +ldbl_weak_alias (__vaprintf, vaprintf) diff --git a/manual/stdio.texi b/manual/stdio.texi index c01feaed..e7deca78 100644 --- a/manual/stdio.texi +++ b/manual/stdio.texi @@ -2578,6 +2578,32 @@ other systems offer this function as an async-signal-safe alternative to The functions in this section do formatted output and place the results in dynamically allocated memory. +@deftypefun {char *} aprintf (const char *@var{template}, @dots{}) +@standards{GNU, stdio.h} +@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@ascuheap{}}@acunsafe{@acsmem{}}} +This function is similar to @code{sprintf}, +except that it dynamically allocates a string +(as with @code{malloc}; @pxref{Unconstrained Allocation}) +to hold the output, +instead of putting the output in a buffer you allocate in advance. +A successful call to @code{aprintf} returns +a pointer to the newly allocated string. + +Here is how to use @code{aprintf} +to get the same result as the @code{snprintf} example, +but more easily: + +@smallexample +/* @r{Construct a message describing the value of a variable} + @r{whose name is @var{name} and whose value is @var{value}.} */ +char * +make_message (char *name, char *value) +@{ + return aprintf ("value of %s is %s", name, value); +@} +@end smallexample +@end deftypefun + @deftypefun int asprintf (char **@var{ptr}, const char *@var{template}, @dots{}) @standards{GNU, stdio.h} @safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@ascuheap{}}@acunsafe{@acsmem{}}} diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 21094483..ec52c1ea 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -90,6 +90,7 @@ routines := \ _itoa \ _itowa \ asprintf \ + aprintf \ ctermid \ cuserid \ dprintf \ @@ -178,6 +179,7 @@ routines := \ # Exclude fortified routines from being built with _FORTIFY_SOURCE routines_no_fortify += \ asprintf \ + aprintf \ dprintf \ fprintf \ printf \ diff --git a/stdio-common/Versions b/stdio-common/Versions index 8e1cbf85..aee611b2 100644 --- a/stdio-common/Versions +++ b/stdio-common/Versions @@ -70,6 +70,8 @@ libc { __isoc23_vfscanf; __isoc23_sscanf; __isoc23_vsscanf; + GLIBC_2.44 { + aprintf; } GLIBC_PRIVATE { # global variables diff --git a/stdio-common/aprintf.c b/stdio-common/aprintf.c new file mode 100644 index 00000000..bee49667 --- /dev/null +++ b/stdio-common/aprintf.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* Write formatted output from FORMAT to a string which is + allocated with malloc. */ +/* VARARGS1 */ +char * +___aprintf (const char *fmt, ...) +{ + char *p; + va_list ap; + + va_start (ap, fmt); + if (__vasprintf_internal (&p, fmt, ap, 0) < 0) + p = NULL; + va_end (ap); + + return p; +} +ldbl_hidden_def (___aprintf, __aprintf) + +ldbl_strong_alias (___aprintf, __aprintf) +ldbl_weak_alias (___aprintf, aprintf) From patchwork Wed Mar 18 18:15:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 131916 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 3F1F34C31857 for ; Wed, 18 Mar 2026 18:16:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F1F34C31857 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=PUR/0RRE X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by sourceware.org (Postfix) with ESMTPS id 02E524C31818 for ; Wed, 18 Mar 2026 18:15:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02E524C31818 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02E524C31818 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=172.105.4.254 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773857713; cv=none; b=PQh4H7HpaG5b6tOvc/btoExNp6AjHrqJzA12R0rqR/SYZm++qJSrYqCEFW86EfVldx/aQub5kI2Hf5krRn4VYxgyqNQbd6cDiYDVEvnOmfCAJVpCCvdD93wD/UwAkxDY/Z/HFo6VcEmKNNR+9CEKWGibxjZVflorr2rk7ROYDko= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773857713; c=relaxed/simple; bh=4FTO1QZhtXEVL+/f82nIiwGSCgVQYhwnO5HLbASeKYI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=JAH0tFIz/E1pAAX8MZCqHSTPtiXT0UBgdHCUdsoNPPrVlRdZU/1Czx5RjpdO3jnlEsJkVb1WIsEQRZ8LJmL0eddk4LzeGTw3lu63+jI2PCfpby0pRTXAYohqLOxunh513SBDSVN9Fur+zYOt7zBPJrBK3egHUam+4+9UEzlwFos= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02E524C31818 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 7BD1A60142; Wed, 18 Mar 2026 18:15:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22C04C19421; Wed, 18 Mar 2026 18:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773857709; bh=4FTO1QZhtXEVL+/f82nIiwGSCgVQYhwnO5HLbASeKYI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PUR/0RREBGibRpqhEXE2R91MaYjZqPfPpNldJ/4ec6aHk89RdUP5nYtbSmweCUGk3 ToNiO8sSrTcDk5wcUZjxyK7FORT54qVbr5EqW+oorjMSHa+AoB3RhvHkwqABfyrA15 FcZQmIH2mqpS031fBxyImQLvsKNeN8Q+r1SSAAdh1Cy7YF2VhzIiJ0rZqdrMmgEHpQ 1TI7rrsbYQolVwcp/tEiDPGS7Cq0d0GvTWlOxSmAuR9ttdb4eGKDmOJnfSnWYlxRXA EkrhUyR6xUksQBLktSU+RNZkNi4gHahtAJshma50P5cAUwPMpGFWRTCkzBVIaM9b7h 86LMdqgTqqN+A== Date: Wed, 18 Mar 2026 19:15:05 +0100 From: Alejandro Colomar To: libc-alpha@sourceware.org Cc: Alejandro Colomar , Joseph Myers , Paul Eggert , Adhemerval Zanella Netto , Florian Weimer , "Dmitry V. Levin" , Archie Cobbs , Solar Designer , Sam James Subject: [RFC v3 2/2] manual/: Prefer aprintf(3) over asprintf(3) Message-ID: <131b1f0c5ed14d3f869552bc84488b5877651c80.1773857304.git.alx@kernel.org> X-Mailer: git-send-email 2.53.0 References: <916855e5ad90ca3611a235ecbcf08a1359771eb9.1773775432.git.alx@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Signed-off-by: Alejandro Colomar --- 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, "", w, w->name); - if (len == -1) + buffer = aprintf ("", 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