From 5d2c98e1df151739342f1d59a45ca316c2f85068 Mon Sep 17 00:00:00 2001 From: Stefan Krah Date: Tue, 6 Nov 2007 02:40:13 +0100 Subject: [PATCH] lib: add linux_version.{c,h} Signed-off-by: Stefan Krah Signed-off-by: Karel Zak --- configure.ac | 3 ++- include/Makefile.am | 3 ++- include/linux_version.h | 14 ++++++++++++++ lib/linux_version.c | 25 +++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 include/linux_version.h create mode 100644 lib/linux_version.c diff --git a/configure.ac b/configure.ac index 7005b5ce..1ea72c6b 100644 --- a/configure.ac +++ b/configure.ac @@ -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])]) diff --git a/include/Makefile.am b/include/Makefile.am index e45ce398..275661de 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 00000000..a6a1e99c --- /dev/null +++ b/include/linux_version.h @@ -0,0 +1,14 @@ +#ifndef LINUX_VERSION_H +#define LINUX_VERSION_H + +#ifdef HAVE_LINUX_VERSION_H +# include +#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 index 00000000..f9fbd8df --- /dev/null +++ b/lib/linux_version.c @@ -0,0 +1,25 @@ +#include +#include + +#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; +} -- 2.39.5