OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [sysdeps/] [kernel_version.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* Copyright (C) 1996 Free Software Foundation, Inc.
2
This file is part of the GNU C Library.
3
 
4
The GNU C Library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public License as
6
published by the Free Software Foundation; either version 2 of the
7
License, or (at your option) any later version.
8
 
9
The GNU C Library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
Library General Public License for more details.
13
 
14
You should have received a copy of the GNU Library General Public
15
License along with the GNU C Library; see the file COPYING.LIB.  If
16
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17
Cambridge, MA 02139, USA.  */
18
 
19
#include <ansidecl.h>
20
#include <string.h>
21
#include <sys/utsname.h>
22
#include <sys/param.h>
23
 
24
static int __linux_kernel_version = -1;
25
 
26
static inline int
27
asc2int (const char *s)
28
{
29
  int result = 0;
30
 
31
  for (; *s >= '0' && *s <= '9'; s++)
32
  {
33
    result = result * 10 + (*s - '0');
34
  }
35
 
36
  return result;
37
}
38
 
39
static int
40
set_linux_kernel_version (void)
41
{
42
  struct utsname uts;
43
  char *version = NULL, *patchlevel = NULL, *sublevel = NULL;
44
 
45
  if (uname (&uts))
46
  {
47
    __linux_kernel_version = 0;
48
    return __linux_kernel_version;
49
  }
50
 
51
  version = uts.release;
52
  if (version != NULL)
53
  {
54
    patchlevel = strchr (version, '.');
55
    if (patchlevel != NULL)
56
    {
57
      *patchlevel = '\0';
58
      patchlevel++;
59
      sublevel = strchr (patchlevel, '.');
60
      if (sublevel != NULL)
61
      {
62
        *sublevel = '\0';
63
        sublevel++;
64
      }
65
    }
66
 
67
    __linux_kernel_version =
68
        GET_LINUX_KERNEL_VERSION (asc2int (version));
69
    if (patchlevel != NULL)
70
    {
71
      __linux_kernel_version |=
72
        GET_LINUX_KERNEL_PATCHLEVEL (asc2int (patchlevel));
73
    }
74
    if (sublevel != NULL)
75
    {
76
      __linux_kernel_version |=
77
        GET_LINUX_KERNEL_SUBLEVEL (asc2int (sublevel));
78
    }
79
  }
80
  else
81
  {
82
    __linux_kernel_version = 0;
83
  }
84
 
85
  return __linux_kernel_version;
86
}
87
 
88
int
89
__get_linux_kernel_version (void)
90
{
91
  if (__linux_kernel_version != -1)
92
    return __linux_kernel_version;
93
 
94
  return set_linux_kernel_version ();
95
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.