source: MondoRescue/branches/2.2.5/mindi-busybox/libbb/kernel_version.c

Last change on this file was 1765, checked in by Bruno Cornec, 16 years ago

Update to busybox 1.7.2

File size: 793 bytes
Line 
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 tarball for details.
8 */
9
10#include <sys/utsname.h> /* for uname(2) */
11
12#include "libbb.h"
13
14/* Returns current kernel version encoded as major*65536 + minor*256 + patch,
15 * so, for example, to check if the kernel is greater than 2.2.11:
16 *
17 * if (get_linux_version_code() > KERNEL_VERSION(2,2,11)) { <stuff> }
18 */
19int get_linux_version_code(void)
20{
21 struct utsname name;
22 char *s;
23 int i, r;
24
25 if (uname(&name) == -1) {
26 bb_perror_msg("cannot get system information");
27 return 0;
28 }
29
30 s = name.release;
31 r = 0;
32 for (i = 0; i < 3; i++) {
33 r = r * 256 + atoi(strtok(s, "."));
34 s = NULL;
35 }
36 return r;
37}
Note: See TracBrowser for help on using the repository browser.