source: branches/2.2.2/mindi-busybox/libbb/kernel_version.c @ 1247

Last change on this file since 1247 was 821, checked in by Bruno Cornec, 14 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

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