aboutsummaryrefslogtreecommitdiffstats
path: root/check_kernel_version.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--check_kernel_version.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/check_kernel_version.c b/check_kernel_version.c
new file mode 100644
index 0000000..ef5dd88
--- /dev/null
+++ b/check_kernel_version.c
@@ -0,0 +1,45 @@
+/* See LICENSE file for copyright and license details. */
+#include "internal.h"
+
+
+int
+liberror_libc_check_kernel_version(long int major, long int minor, long int patch)
+{
+#if defined(__linux__)
+
+ struct utsname name;
+ long int kmajor;
+ long int kminor;
+ long int kpatch;
+ char *p;
+ int r;
+
+ r = uname(&name);
+ if (r < 0)
+ return -1;
+
+ errno = 0;
+ p = name.release;
+ if (!isdigit(*p))
+ return -1;
+ kmajor = strtol(p, &p, 10);
+ if (kmajor < 0 || errno || *p != '.')
+ return -1;
+ kminor = strtol(&p[1], &p, 10);
+ if (kminor < 0 || errno)
+ return -1;
+ if (*p != '.') {
+ kpatch = 0;
+ } else {
+ kpatch = strtol(&p[1], &p, 10);
+ if (kpatch < 0 || errno)
+ return -1;
+ }
+
+ return kmajor != major ? kmajor > major :
+ kminor != minor ? kminor > minor : kpatch >= patch;
+
+#else
+# error Unsupported kernel
+#endif
+}