Adsense code (2021-10-05)

Wednesday, February 19, 2014

Get GNU libc version at run-time using C

To get GNU libc version in C language at run-time, you can call gnu_get_libc_version() and gnu_get_libc_release().

- gnu_get_libc_version() returns string that identifies the glibc version available on the system.
- gnu_get_libc_release() returns string indicates the release status of the glibc version available on the system.

And, you can retrieve _CS_GNU_LIBC_VERSION with confstr().

Here is example, test_version.c:
#include <stdio.h>
#include <gnu/libc-version.h>
#include <stdlib.h>
#include <unistd.h>

main(){
    printf("GNU libc version: %s\n", gnu_get_libc_version());
    printf("GNU libc release: %s\n", gnu_get_libc_release());
    
    char *buf; size_t n;
    n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t)0);
    if ((buf = malloc(n)) == NULL) 
        abort();
    confstr(_CS_GNU_LIBC_VERSION, buf, n);

    printf("_CS_GNU_LIBC_VERSION: %s\n", buf );
    free( buf );
}

Get GNU libc version at run-time using C
Get GNU libc version at run-time using C