![]() |
|
Message-ID: <20250131012755.342042-1-lains@riseup.net> Date: Fri, 31 Jan 2025 01:27:37 +0000 From: Filipe Laíns <lains@...eup.net> To: musl@...ts.openwall.com Cc: Filipe Laíns <lains@...eup.net> Subject: [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 <lains@...eup.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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.