]> err.no Git - util-linux/commitdiff
lib: add linux_version.{c,h}
authorStefan Krah <stefan@bytereef.org>
Tue, 6 Nov 2007 01:40:13 +0000 (02:40 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 6 Nov 2007 01:40:13 +0000 (02:40 +0100)
Signed-off-by: Stefan Krah <stefan@bytereef.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
include/Makefile.am
include/linux_version.h [new file with mode: 0644]
lib/linux_version.c [new file with mode: 0644]

index 7005b5ce715e212e98b32a1d1dcc4f3418b35b61..1ea72c6b965e4192f350ddaa38edf44a0f7182a1 100644 (file)
@@ -46,7 +46,8 @@ AC_CHECK_HEADERS(
        rpcsvc/nfs_prot.h \
        sys/io.h \
        pty.h \
-       err.h])
+       err.h \
+       linux/version.h])
 AC_CHECK_HEADERS([linux/raw.h],
                 [AM_CONDITIONAL([HAVE_RAW], [true])],
                 [AM_CONDITIONAL([HAVE_RAW], [false])])
index e45ce3982325c4c2ea9477f2cff71a5025b9e976..275661deea2656861a56cd11824e58f46d618677 100644 (file)
@@ -1,4 +1,5 @@
 include $(top_srcdir)/config/include-Makefile.am
 
 dist_noinst_HEADERS = carefulputc.h env.h linux_reboot.h md5.h \
-       nls.h pathnames.h setproctitle.h widechar.h xstrncpy.h
+       nls.h pathnames.h setproctitle.h widechar.h xstrncpy.h \
+       linux_version.h
diff --git a/include/linux_version.h b/include/linux_version.h
new file mode 100644 (file)
index 0000000..a6a1e99
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef LINUX_VERSION_H
+#define LINUX_VERSION_H
+
+#ifdef HAVE_LINUX_VERSION_H
+# include <linux/version.h>
+#endif
+
+#ifndef KERNEL_VERSION
+# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+#endif
+
+int get_linux_version(void);
+
+#endif /* LINUX_VERSION_H */
diff --git a/lib/linux_version.c b/lib/linux_version.c
new file mode 100644 (file)
index 0000000..f9fbd8d
--- /dev/null
@@ -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;
+}