mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-22 00:48:53 +02:00
gutils: Use uname to report OS info when there is no os-release file
There are a lot of Unix-like systems which have not implemented the os-release spec. On such system, we can use POSIX uname function as a fallback to get basic information of the system.
This commit is contained in:
committed by
Philip Withnall
parent
00abf67e2c
commit
d219b3553c
@@ -29,6 +29,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef G_OS_UNIX
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
#ifdef G_OS_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
@@ -522,6 +525,9 @@ test_os_info (void)
|
||||
{
|
||||
gchar *name;
|
||||
gchar *contents = NULL;
|
||||
#ifdef G_OS_UNIX
|
||||
struct utsname info;
|
||||
#endif
|
||||
|
||||
/* Whether this is implemented or not, it must not crash */
|
||||
name = g_get_os_info (G_OS_INFO_KEY_NAME);
|
||||
@@ -534,7 +540,8 @@ test_os_info (void)
|
||||
g_assert_nonnull (name);
|
||||
#elif defined (G_OS_UNIX)
|
||||
if (g_file_get_contents ("/etc/os-release", &contents, NULL, NULL) ||
|
||||
g_file_get_contents ("/usr/lib/os-release", &contents, NULL, NULL))
|
||||
g_file_get_contents ("/usr/lib/os-release", &contents, NULL, NULL) ||
|
||||
uname (&info) == 0)
|
||||
g_assert_nonnull (name);
|
||||
else
|
||||
g_test_skip ("os-release(5) API not implemented on this platform");
|
||||
|
Reference in New Issue
Block a user