summaryrefslogtreecommitdiff
path: root/lib/linux_version.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/linux_version.c')
-rw-r--r--lib/linux_version.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/linux_version.c b/lib/linux_version.c
new file mode 100644
index 0000000..f9fbd8d
--- /dev/null
+++ b/lib/linux_version.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <sys/utsname.h>
+
+#include "linux_version.h"
+
+int
+get_linux_version (void)
+{
+ static int kver = -1;
+ struct utsname uts;
+ int major;
+ int minor;
+ int teeny;
+
+ if (kver != -1)
+ return kver;
+ if (uname (&uts))
+ kver = 0;
+ else if (sscanf (uts.release, "%d.%d.%d", &major, &minor, &teeny) != 3)
+ kver = 0;
+ else
+ kver = KERNEL_VERSION (major, minor, teeny);
+
+ return kver;
+}