source:
MondoRescue/branches/3.3/mindi-busybox/libbb/kernel_version.c@
3770
| Last change on this file since 3770 was 3621, checked in by , 9 years ago | |
|---|---|
| File size: 818 bytes | |
| Rev | Line | |
|---|---|---|
| [821] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | |
| 3 | * Utility routines. | |
| 4 | * | |
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | |
| 6 | * | |
| [2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
| [821] | 8 | */ |
| 9 | ||
| 10 | #include "libbb.h" | |
| [2725] | 11 | /* After libbb.h, since it needs sys/types.h on some systems */ |
| 12 | #include <sys/utsname.h> /* for uname(2) */ | |
| [821] | 13 | |
| [2725] | 14 | |
| [821] | 15 | /* Returns current kernel version encoded as major*65536 + minor*256 + patch, |
| 16 | * so, for example, to check if the kernel is greater than 2.2.11: | |
| 17 | * | |
| 18 | * if (get_linux_version_code() > KERNEL_VERSION(2,2,11)) { <stuff> } | |
| 19 | */ | |
| [2725] | 20 | int FAST_FUNC get_linux_version_code(void) |
| [821] | 21 | { |
| 22 | struct utsname name; | |
| [3621] | 23 | char *t; |
| [821] | 24 | int i, r; |
| 25 | ||
| [3232] | 26 | uname(&name); /* never fails */ |
| [3621] | 27 | t = name.release; |
| [821] | 28 | r = 0; |
| [1765] | 29 | for (i = 0; i < 3; i++) { |
| [3621] | 30 | t = strtok(t, "."); |
| [3232] | 31 | r = r * 256 + (t ? atoi(t) : 0); |
| [3621] | 32 | t = NULL; |
| [821] | 33 | } |
| 34 | return r; | |
| 35 | } |
Note:
See TracBrowser
for help on using the repository browser.
