1 /* vi: set sw=4 ts=4: */
2 /*
3 * Utility routines.
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9 #include "libbb.h"
10 /* After libbb.h, since it needs sys/types.h on some systems */
11 #include <sys/utsname.h> /* for uname(2) */
12
13 /* Returns current kernel version encoded as major*65536 + minor*256 + patch,
14 * so, for example, to check if the kernel is greater than 2.2.11:
15 *
16 * if (get_linux_version_code() > KERNEL_VERSION(2,2,11)) { <stuff> }
17 */
get_linux_version_code(void)18 int FAST_FUNC get_linux_version_code(void)
19 {
20 struct utsname name;
21 char *t;
22 int r;
23
24 uname(&name); /* never fails */
25 t = name.release - 1;
26 r = 1;
27 do {
28 r <<= 8;
29 if (t) {
30 r += atoi(++t);
31 t = strchr(t, '.');
32 }
33 } while (r < 0x1000000);
34 return r - 0x1000000;
35 }
36