From: Alejandro Colomar <alx@kernel.org>
To: libc-alpha@sourceware.org, Joseph Myers <josmyers@redhat.com>,
Paul Eggert <eggert@cs.ucla.edu>
Cc: Alejandro Colomar <alx@kernel.org>
Subject: [RFC v2] Add [v]aprintf(3)
Date: Tue, 17 Mar 2026 20:26:16 +0100 [thread overview]
Message-ID: <916855e5ad90ca3611a235ecbcf08a1359771eb9.1773775432.git.alx@kernel.org> (raw)
In-Reply-To: <abSVWeS3nHmkZSKn@devuan>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
Hi!
I've figured out how to add these to the Makefiles. I'm now having
issues with the aliases, which I don't understand at all. I more or
less imitated how [v]asprintf(3) are implemented, but obviously did
something wrong.
Would you mind helping with this error?
In file included from <command-line>:
./../include/libc-symbols.h:474:33: error: ‘__EI_aprintf’ aliased to undefined symbol ‘__GI_aprintf’
474 | extern thread __typeof (name) __EI_##name \
| ^~~~~
./../include/libc-symbols.h:470:3: note: in expansion of macro ‘__hidden_ver2’
470 | __hidden_ver2 (, local, internal, name)
| ^~~~~~~~~~~~~
./../include/libc-symbols.h:478:41: note: in expansion of macro ‘__hidden_ver1’
478 | # define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
| ^~~~~~~~~~~~~
./../include/libc-symbols.h:559:32: note: in expansion of macro ‘hidden_def’
559 | # define libc_hidden_def(name) hidden_def (name)
| ^~~~~~~~~~
../sysdeps/generic/math_ldbl_opt.h:13:38: note: in expansion of macro ‘libc_hidden_def’
13 | #define ldbl_hidden_def(local, name) libc_hidden_def (name)
| ^~~~~~~~~~~~~~~
aprintf.c:37:1: note: in expansion of macro ‘ldbl_hidden_def’
37 | ldbl_hidden_def (__aprintf, aprintf)
| ^~~~~~~~~~~~~~~
Cheers,
Alex
libio/Makefile | 3 ++-
libio/stdio.h | 8 ++++++++
libio/vaprintf.c | 39 +++++++++++++++++++++++++++++++++++++++
stdio-common/Makefile | 2 ++
stdio-common/aprintf.c | 40 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 91 insertions(+), 1 deletion(-)
create mode 100644 libio/vaprintf.c
create mode 100644 stdio-common/aprintf.c
diff --git a/libio/Makefile b/libio/Makefile
index 08e1e0ec..acb578db 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 \
diff --git a/libio/stdio.h b/libio/stdio.h
index 3bf6a1f6..3db363f1 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -410,6 +410,14 @@ extern int __asprintf (char **__restrict __ptr,
extern int asprintf (char **__restrict __ptr,
const char *__restrict __fmt, ...)
__THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
+
+/* 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
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
+ <https://www.gnu.org/licenses/>.
+
+ 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 <libioP.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+
+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/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/aprintf.c b/stdio-common/aprintf.c
new file mode 100644
index 00000000..f2d0dbb2
--- /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
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdarg.h>
+#include <libioP.h>
+
+/* 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)
Range-diff against v1:
1: e5defcbd ! 1: 916855e5 libio/: Add [v]aprintf()
@@ Metadata
Author: Alejandro Colomar <alx@kernel.org>
## Commit message ##
- libio/: Add [v]aprintf()
+ Add [v]aprintf(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
+ ## libio/Makefile ##
+@@ libio/Makefile: 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 \
+@@ libio/Makefile: routines_no_fortify += \
+ iovdprintf \
+ swprintf \
+ vasprintf \
++ vaprintf \
+ vsnprintf \
+ vswprintf \
+ vwprintf \
+
## libio/stdio.h ##
@@ libio/stdio.h: extern int __asprintf (char **__restrict __ptr,
extern int asprintf (char **__restrict __ptr,
@@ libio/vaprintf.c (new)
+ This exception applies to code released by its copyright holders
+ in files containing the exception. */
+
-+#include "libioP.h"
++#include <libioP.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+
-+char **
++char *
+__vaprintf (const char *fmt, va_list args)
+{
+ char *p;
+
-+ return (__vasprintf_internal (&p, fmt, args, 0) < 0 ? NULL : p;
++ return __vasprintf_internal (&p, fmt, args, 0) < 0 ? NULL : p;
+}
+ldbl_weak_alias (__vaprintf, vaprintf)
+
+ ## stdio-common/Makefile ##
+@@ stdio-common/Makefile: routines := \
+ _itoa \
+ _itowa \
+ asprintf \
++ aprintf \
+ ctermid \
+ cuserid \
+ dprintf \
+@@ stdio-common/Makefile: routines := \
+ # Exclude fortified routines from being built with _FORTIFY_SOURCE
+ routines_no_fortify += \
+ asprintf \
++ aprintf \
+ dprintf \
+ fprintf \
+ printf \
+
+ ## stdio-common/aprintf.c (new) ##
+@@
++/* Copyright (C) 2026 Free Software Foundation, Inc.
++ This file is part of the GNU C Library.
+
-+char **
-+__aprintf (const char *fmt, ...)
++ 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
++ <https://www.gnu.org/licenses/>. */
++
++#include <stdarg.h>
++#include <libioP.h>
++
++/* 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);
-+ p = __vaprintf(fmt, ap);
-+ va_end(ap);
++ va_start (ap, fmt);
++ if (__vasprintf_internal (&p, fmt, ap, 0) < 0)
++ p = NULL;
++ va_end (ap);
+
+ return p;
+}
-+ldbl_weak_alias (__aprintf, aprintf)
++ldbl_hidden_def (__aprintf, aprintf)
++
++ldbl_strong_alias (___aprintf, __aprintf)
++ldbl_weak_alias (___aprintf, aprintf)
--
2.53.0
next prev parent reply other threads:[~2026-03-17 19:26 UTC|newest]
Thread overview: 61+ 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 ` Alejandro Colomar [this message]
2026-03-17 20:16 ` [RFC v2] Add [v]aprintf(3) 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 ` [RFC v4 2/2] manual/: Prefer aprintf(3) over asprintf(3) Alejandro Colomar
2026-03-20 16:50 ` [RFC v4 0/2] Add [v]aprintf(3) 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
2026-05-18 17:32 ` Joseph Myers
2026-05-18 21:11 ` Alejandro Colomar
2026-05-18 21:20 ` [PATCH v6 " Alejandro Colomar
2026-05-18 21:20 ` [PATCH v6 1/3] " Alejandro Colomar
2026-05-20 13:59 ` Andreas Schwab
2026-05-20 14:43 ` Alejandro Colomar
2026-05-21 8:21 ` Andreas Schwab
2026-05-21 9:27 ` Alejandro Colomar
2026-05-27 19:28 ` Alejandro Colomar
2026-05-18 21:20 ` [PATCH v6 2/3] manual/: Prefer aprintf(3) over asprintf(3) Alejandro Colomar
2026-05-18 21:20 ` [PATCH v6 3/3] sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c: Fix typo Alejandro Colomar
2026-05-30 10:59 ` [PATCH v7 0/3] Add [v]aprintf(3) Alejandro Colomar
2026-05-30 10:59 ` [PATCH v7 1/3] " Alejandro Colomar
2026-06-03 16:45 ` Adhemerval Zanella Netto
2026-06-03 20:37 ` Alejandro Colomar
2026-06-05 18:42 ` Adhemerval Zanella Netto
2026-06-05 20:42 ` Alejandro Colomar
2026-05-30 10:59 ` [PATCH v7 2/3] manual/: Prefer aprintf(3) over asprintf(3) Alejandro Colomar
2026-05-30 10:59 ` [PATCH v7 3/3] sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c: Fix typo Alejandro Colomar
2026-06-01 13:17 ` Carlos O'Donell
2026-06-01 21:09 ` Alejandro Colomar
2026-06-03 14:10 ` Adhemerval Zanella Netto
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=916855e5ad90ca3611a235ecbcf08a1359771eb9.1773775432.git.alx@kernel.org \
--to=alx@kernel.org \
--cc=eggert@cs.ucla.edu \
--cc=josmyers@redhat.com \
--cc=libc-alpha@sourceware.org \
/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).