aboutsummaryrefslogtreecommitdiffstats
path: root/check_kernel_version.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-12-10 20:54:46 +0100
committerMattias Andrée <maandree@kth.se>2021-12-10 20:54:46 +0100
commit823808c2c1cdfa244a6af1491d57192b79af8818 (patch)
treeb79c5a43998ebf1e7fe6367b82d3a6ce81831162 /check_kernel_version.c
parentrecv: fix types in check (diff)
downloadliberror-libc-823808c2c1cdfa244a6af1491d57192b79af8818.tar.gz
liberror-libc-823808c2c1cdfa244a6af1491d57192b79af8818.tar.bz2
liberror-libc-823808c2c1cdfa244a6af1491d57192b79af8818.tar.xz
Add lseek
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'check_kernel_version.c')
-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
+}