Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Utility routines. |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 6 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 10 | #include <sys/utsname.h> /* for uname(2) */ |
| 11 | |
| 12 | #include "libbb.h" |
| 13 | |
Bernhard Reutner-Fischer | e2e56c7 | 2006-05-19 11:54:02 +0000 | [diff] [blame] | 14 | /* Returns current kernel version encoded as major*65536 + minor*256 + patch, |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 15 | * so, for example, to check if the kernel is greater than 2.2.11: |
Bernhard Reutner-Fischer | e2e56c7 | 2006-05-19 11:54:02 +0000 | [diff] [blame] | 16 | * |
| 17 | * if (get_linux_version_code() > KERNEL_VERSION(2,2,11)) { <stuff> } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 18 | */ |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame^] | 19 | int FAST_FUNC get_linux_version_code(void) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 20 | { |
| 21 | struct utsname name; |
| 22 | char *s; |
| 23 | int i, r; |
| 24 | |
| 25 | if (uname(&name) == -1) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 26 | bb_perror_msg("cannot get system information"); |
Denis Vlasenko | cf70433 | 2006-10-27 15:12:50 +0000 | [diff] [blame] | 27 | return 0; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | s = name.release; |
| 31 | r = 0; |
Denis Vlasenko | cf70433 | 2006-10-27 15:12:50 +0000 | [diff] [blame] | 32 | for (i = 0; i < 3; i++) { |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 33 | r = r * 256 + atoi(strtok(s, ".")); |
| 34 | s = NULL; |
| 35 | } |
| 36 | return r; |
| 37 | } |