blob: 3526412a0e1fc5078a3cecc317c5a64ff48314ea [file] [log] [blame]
plarsfea599e2003-02-27 16:53:21 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2003
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
vapier45a8ba02009-07-20 10:59:32 +000019
plarsfea599e2003-02-27 16:53:21 +000020/*
vapier45a8ba02009-07-20 10:59:32 +000021 *
plarsfea599e2003-02-27 16:53:21 +000022 * AUTHOR
23 * Paul Larson <plars@linuxtestproject.org>
24 *
25 * DESCRIPTION
26 * Compare a given kernel version against the current kernel version.
27 * If they are the same - return 0
28 * If the argument is > current kernel version - return positive int
29 * If the argument is < current kernel version - return negative int
30 *
31 */
32
33
robbiew88e7b182003-03-13 19:00:13 +000034#include <stdlib.h>
plarsfea599e2003-02-27 16:53:21 +000035#include <unistd.h>
36#include <string.h>
37#include <sys/utsname.h>
38
39void get_kver(int *k1, int *k2, int *k3)
40{
41 struct utsname uval;
42 char *kver;
43 char *r1, *r2, *r3;
robbiew784a3602005-10-03 18:05:52 +000044#if !defined(linux)
mridgee6508f82005-01-04 21:00:17 +000045 extern char *strsep(); /* shut up some compilers */
robbiew784a3602005-10-03 18:05:52 +000046#endif
mridgee6508f82005-01-04 21:00:17 +000047
plarsfea599e2003-02-27 16:53:21 +000048 uname(&uval);
49 kver = uval.release;
50 r1 = strsep(&kver, ".");
51 r2 = strsep(&kver, ".");
52 r3 = strsep(&kver, ".");
53
54 *k1 = atoi(r1);
55 *k2 = atoi(r2);
56 *k3 = atoi(r3);
57}
58
plars255c3522003-03-03 21:40:43 +000059int tst_kvercmp(int r1, int r2, int r3) {
plarsfea599e2003-02-27 16:53:21 +000060 int a1, a2, a3;
61 int testver, currver;
62
63 get_kver(&a1, &a2, &a3);
64 testver = (r1 << 16) + (r2 << 8) + r3;
65 currver = (a1 << 16) + (a2 << 8) + a3;
66
plars878713c2003-03-03 22:02:07 +000067 return currver - testver;
Chris Dearmanec6edca2012-10-17 19:54:01 -070068}