From: "Filipe Laíns" <lains@riseup.net>
To: musl@lists.openwall.com
Cc: "Filipe Laíns" <lains@riseup.net>
Subject: [musl] [PATCH] confstr: add support for _CS_GNU_LIBC_VERSION
Date: Fri, 31 Jan 2025 01:27:37 +0000 [thread overview]
Message-ID: <20250131012755.342042-1-lains@riseup.net> (raw)
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 <lains@riseup.net>
---
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 <unistd.h>
#include <stdio.h>
#include <errno.h>
+#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
next reply other threads:[~2025-01-31 1:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-31 1:27 Filipe Laíns [this message]
2025-02-09 14:46 ` Rich Felker
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=20250131012755.342042-1-lains@riseup.net \
--to=lains@riseup.net \
--cc=musl@lists.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).