summaryrefslogtreecommitdiff
path: root/lib/linux_version.c
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-11-02 20:15:39 +0400
committerIgor Pashev <pashev.igor@gmail.com>2012-11-02 20:15:39 +0400
commitb13154de3eca5ba28fbb4854d916cd0be5febeed (patch)
tree30f2e9e89ab71a2df837076ac68c3ba770230294 /lib/linux_version.c
downloadutil-linux-b13154de3eca5ba28fbb4854d916cd0be5febeed.tar.gz
Imported Upstream version 2.22upstream/2.22upstream
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..2bcc2cc
--- /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 = 0;
+ int minor = 0;
+ int teeny = 0;
+ int n;
+
+ if (kver != -1)
+ return kver;
+ if (uname (&uts))
+ return kver = 0;
+
+ n = sscanf(uts.release, "%d.%d.%d", &major, &minor, &teeny);
+ if (n < 1 || n > 3)
+ return kver = 0;
+
+ return kver = KERNEL_VERSION(major, minor, teeny);
+}