mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] confstr: add support for _CS_GNU_LIBC_VERSION
@ 2025-01-31  1:27 Filipe Laíns
  0 siblings, 0 replies; only message in thread
From: Filipe Laíns @ 2025-01-31  1:27 UTC (permalink / raw)
  To: musl; +Cc: Filipe Laíns

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-31  1:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-31  1:27 [musl] [PATCH] confstr: add support for _CS_GNU_LIBC_VERSION Filipe Laíns

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).