GLib 2.63.1 has been released. The final new API to mention in this mini-series of blog posts about what’s in 2.63.1 is
g_get_os_info() is a way to get identifying information about the OS. On Linux, this is gathered from
/etc/os-release. On other OSs, it’s gathered using platform-specific APIs (on other Unixes, this means falling back to
To use it, pass it a key, like
G_OS_INFO_KEY_PRETTY_NAME, and it’ll return a newly-allocated string with the corresponding value for the current OS, or
NULL if there was none. Different OSs support different sets of keys, and the amount of support and set of keys may change over time.
g_autofree gchar *os_name = g_get_os_info (G_OS_INFO_KEY_PRETTY_NAME); g_print ("OS: %s\n", os_name); /* Prints “OS: Fedora 30 (Workstation Edition)” for me */