From patchwork Tue Mar 17 18:59: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: 131881 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 E59C74BB5888 for ; Tue, 17 Mar 2026 18:59:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E59C74BB5888 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=EvFA20l0 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from tor.source.kernel.org (tor.source.kernel.org [IPv6:2600:3c04:e001:324:0:1991:8:25]) by sourceware.org (Postfix) with ESMTPS id C7F984BB3BE3 for ; Tue, 17 Mar 2026 18:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7F984BB3BE3 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 C7F984BB3BE3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2600:3c04:e001:324:0:1991:8:25 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773773950; cv=none; b=ABRJCbAZ7vl/AMet77qdTn0lrejiHxof01QidBhz34ZYiaSJS3Ix63UJov4JrypdI6Mxnn5UDFlPookd5V8U5Uv3NQbhYdYeSJimCqGXWtseoVfFEbvQG/+cmlpoiySXHOINjuqmzn3dI9Dx4JLNJyEeExeLKZ+udLEwrL5spRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773773950; c=relaxed/simple; bh=NvxerliVQe6ukJqCf8Wel5EnKgoWTaqQyIgImvL5sR8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=f4UMOk4DUzJP4YYvCVlMjXt+wxM/H93Z4J/4f38Sad7CtEQeR03j2D48lCc+Vh/2FYCY8SMhmGOBWjd9KFRCNWZcHz/YF1BCj+V9fLPZ1sFUdYuveLZu+f7brM1mSBjM9Un/slsR3vDo4c+vj/lL2QWBvFNepBlSYRX9hCQ/0P4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7F984BB3BE3 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 32D1D60018; Tue, 17 Mar 2026 18:59:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAE56C4CEF7; Tue, 17 Mar 2026 18:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773773948; bh=NvxerliVQe6ukJqCf8Wel5EnKgoWTaqQyIgImvL5sR8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EvFA20l0k0uks5jqufQhREDUKz9zr206rHe/73wOHfQiGxGugy53JkSo0kRPuwz7H hUGK6I4+GyK8m1uFAAp1MyMeXP19A7JbCDxOpvDMMKp4bCEm1BpEIzAAzqhSvULzZX bj2ByJp+izI6XhBDKaUL6EzCJd0ET6+hRLrax3ZLCzQToB57bqB4P9WbY2Zv0yCK7Q c2h/2a+ZbEcbWw312bQ3l6oAKugcPQW67AKzWvJM5SKBFFq+AtSB2XBxAY1Jug/ghd gNI+hLLC07VGmBlZ0HFa5CkJsgbT6kuhUY+h8Zz6zvNxs8rzHj1MaNrvMrqKWp1ZpZ bQEM2rLUuAPfA== Date: Tue, 17 Mar 2026 19:59:05 +0100 From: Alejandro Colomar To: libc-alpha@sourceware.org, Joseph Myers , Paul Eggert Cc: Alejandro Colomar Subject: [RFC v1] libio/: Add [v]aprintf() Message-ID: X-Mailer: git-send-email 2.53.0 References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-10.0 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 --- Hi Paul, Joseph, Since nobody replied, I guess people are not strongly opposed to it, but they probably want to see a patch before spending time with this. Thus, I've written a patch (or a draft of a patch). This is the first time I add a function to glibc, and I find it quite difficult, so I'll need some help. I've added the most obvious pieces: the prototypes and the implementation. However, this doesn't work at all, so I guess I'm missing stuff. Would you mind helping me figure out what I'm missing (or what's wrong)? I tried building this simple test program, but I get linker errors: #include #include int main(void) { char *p; p = aprintf("foo %d", 42); if (p == NULL) exit(1); puts(p); } Have a lovely night! Alex libio/stdio.h | 8 ++++++++ libio/vaprintf.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 libio/vaprintf.c Range-diff against v0: -: -------- > 1: e5defcbd libio/: Add [v]aprintf() 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..0ba147a0 --- /dev/null +++ b/libio/vaprintf.c @@ -0,0 +1,53 @@ +/* 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 "libioP.h" +#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) + +char ** +__aprintf (const char *fmt, ...) +{ + char *p; + va_list ap; + + va_start(ap, fmt); + p = __vaprintf(fmt, ap); + va_end(ap); + + return p; +} +ldbl_weak_alias (__aprintf, aprintf)