From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 633D824C6A for ; Fri, 31 Jan 2025 02:34:06 +0100 (CET) Received: (qmail 16135 invoked by uid 550); 31 Jan 2025 01:34:01 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com x-ms-reactions: disallow Received: (qmail 9658 invoked from network); 31 Jan 2025 01:28:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1738286901; bh=lchUSsp09frzjswl23LhxiMdhNKOcuQahuBQs8m2USU=; h=From:To:Cc:Subject:Date:From; b=VU8iLD00ETygmIQkb6FRHUUQ2d8lIs24TeUI868wDJ+D7qTwsa6spYhbWFZStWCmB B2gV9/30hP+h4UyTePwkLFGTMlS24s7TuUPY/luewjY97nD+HftrRh7Pud6FUwivin dtYOw/e55jYV+eFq7aCWADn6ZCojM4+6ApkWwnMM= X-Riseup-User-ID: 48BA5F1EDF93C592DE1067BEDDE3C8A2C6EAAF656FC85B8AEF25728C97A0C51C From: =?UTF-8?q?Filipe=20La=C3=ADns?= To: musl@lists.openwall.com Cc: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 31 Jan 2025 01:27:37 +0000 Message-ID: <20250131012755.342042-1-lains@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] confstr: add support for _CS_GNU_LIBC_VERSION This provides a way to detect at runtime if musl is the libc implementation, and to check its version. This functionality is useful when introspecting the system, to determine binary compatibility of on packaging applications. An example use-case can be demonstrated by Python PEP 656 [1], whose implementation currently require spawning a new process and parsing the output of ld.so to detect the musl version. [1] https://peps.python.org/pep-0656/ Signed-off-by: Filipe LaĆ­ns --- WHATSNEW | 1 + src/conf/confstr.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/WHATSNEW b/WHATSNEW index 7bd90728..e7e50d2f 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -2417,6 +2417,7 @@ compatibility: - string.h no longer provides (C23-incompat) non-prototype decl of basename - fstatat statx backend now matches stat syscall non-automounting behavior - mntent interfaces now handle escaped whitespace in paths/options +- confstr now supports _CS_GNU_LIBC_VERSION standards updates: - printf %lc of nul wchar now produces output diff --git a/src/conf/confstr.c b/src/conf/confstr.c index 3d417284..a9ac87f4 100644 --- a/src/conf/confstr.c +++ b/src/conf/confstr.c @@ -1,12 +1,15 @@ #include #include #include +#include "version.h" size_t confstr(int name, char *buf, size_t len) { const char *s = ""; if (!name) { s = "/bin:/usr/bin"; + } else if (name == _CS_GNU_LIBC_VERSION) { + s = "musl " VERSION; } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>35U) { errno = EINVAL; return 0; -- 2.48.1