1 /* vi: set sw=4 ts=4: */
3 * Copyright (C) 1999,2000 by Lineo, inc. Written by Erik Andersen
4 * <andersen@lineo.com>, <andersee@debian.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Library General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
16 * You should have received a copy of the GNU Library General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/utsname.h>
26 static int __linux_kernel_version = -1;
28 /* Returns kernel version encoded as major*65536 + minor*256 + patch,
29 * so, for example, to check if the kernel is greater than 2.2.11:
30 * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
32 static int find_kernel_revision(void)
35 int major = 0, minor = 0, patch = 0;
37 if (uname(&name) == -1) {
40 sscanf(name.version, "%d.%d.%d", &major, &minor, &patch);
41 return major * 65536 + minor * 256 + patch;
46 __get_linux_kernel_version (void)
48 if (__linux_kernel_version != -1)
49 return __linux_kernel_version;
51 return find_kernel_revision ();