blob: 8b9c4ec2065f2b360497c30f2f1cdb4aa4fcef7a [file] [log] [blame]
Eric Andersenaad1a882001-03-16 22:47:14 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersenaad1a882001-03-16 22:47:14 +00006 *
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenaad1a882001-03-16 22:47:14 +00008 */
9
Eric Andersenaad1a882001-03-16 22:47:14 +000010#include <sys/utsname.h> /* for uname(2) */
11
12#include "libbb.h"
13
Bernhard Reutner-Fischere2e56c72006-05-19 11:54:02 +000014/* Returns current kernel version encoded as major*65536 + minor*256 + patch,
Eric Andersenaad1a882001-03-16 22:47:14 +000015 * so, for example, to check if the kernel is greater than 2.2.11:
Bernhard Reutner-Fischere2e56c72006-05-19 11:54:02 +000016 *
17 * if (get_linux_version_code() > KERNEL_VERSION(2,2,11)) { <stuff> }
Eric Andersenaad1a882001-03-16 22:47:14 +000018 */
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000019int FAST_FUNC get_linux_version_code(void)
Eric Andersenaad1a882001-03-16 22:47:14 +000020{
21 struct utsname name;
22 char *s;
23 int i, r;
24
25 if (uname(&name) == -1) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000026 bb_perror_msg("cannot get system information");
Denis Vlasenkocf704332006-10-27 15:12:50 +000027 return 0;
Eric Andersenaad1a882001-03-16 22:47:14 +000028 }
29
30 s = name.release;
31 r = 0;
Denis Vlasenkocf704332006-10-27 15:12:50 +000032 for (i = 0; i < 3; i++) {
Eric Andersenaad1a882001-03-16 22:47:14 +000033 r = r * 256 + atoi(strtok(s, "."));
34 s = NULL;
35 }
36 return r;
37}