root / tests / cris / check_glibc_kernelversion.c @ f97572e5
History | View | Annotate | Download (6 kB)
1 | dd43edf4 | ths | /*
|
---|---|---|---|
2 | dd43edf4 | ths | * Check the lz insn.
|
3 | dd43edf4 | ths | */
|
4 | dd43edf4 | ths | |
5 | dd43edf4 | ths | #include <stdio.h> |
6 | dd43edf4 | ths | #include <stdlib.h> |
7 | dd43edf4 | ths | #include <stdint.h> |
8 | dd43edf4 | ths | #include "sys.h" |
9 | dd43edf4 | ths | |
10 | dd43edf4 | ths | #define __LINUX_KERNEL_VERSION 131584 |
11 | dd43edf4 | ths | |
12 | dd43edf4 | ths | #define DL_SYSDEP_OSCHECK(FATAL) \
|
13 | dd43edf4 | ths | do { \
|
14 | dd43edf4 | ths | /* Test whether the kernel is new enough. This test is only \
|
15 | dd43edf4 | ths | performed if the library is not compiled to run on all \
|
16 | dd43edf4 | ths | kernels. */ \
|
17 | dd43edf4 | ths | if (__LINUX_KERNEL_VERSION > 0) \ |
18 | dd43edf4 | ths | { \ |
19 | dd43edf4 | ths | char bufmem[64]; \ |
20 | dd43edf4 | ths | char *buf = bufmem; \
|
21 | dd43edf4 | ths | unsigned int version; \ |
22 | dd43edf4 | ths | int parts; \
|
23 | dd43edf4 | ths | char *cp; \
|
24 | dd43edf4 | ths | struct utsname uts; \
|
25 | dd43edf4 | ths | \ |
26 | dd43edf4 | ths | /* Try the uname syscall */ \
|
27 | dd43edf4 | ths | if (__uname (&uts)) \
|
28 | dd43edf4 | ths | { \ |
29 | dd43edf4 | ths | /* This was not successful. Now try reading the /proc \
|
30 | dd43edf4 | ths | filesystem. */ \
|
31 | dd43edf4 | ths | ssize_t reslen; \ |
32 | dd43edf4 | ths | int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY); \ |
33 | dd43edf4 | ths | if (fd == -1 \ |
34 | dd43edf4 | ths | || (reslen = __read (fd, bufmem, sizeof (bufmem))) <= 0) \ |
35 | dd43edf4 | ths | /* This also didn't work. We give up since we cannot \
|
36 | dd43edf4 | ths | make sure the library can actually work. */ \
|
37 | dd43edf4 | ths | FATAL ("FATAL: cannot determine library version\n"); \
|
38 | dd43edf4 | ths | __close (fd); \ |
39 | dd43edf4 | ths | buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0'; \ |
40 | dd43edf4 | ths | } \ |
41 | dd43edf4 | ths | else \
|
42 | dd43edf4 | ths | buf = uts.release; \ |
43 | dd43edf4 | ths | \ |
44 | dd43edf4 | ths | /* Now convert it into a number. The string consists of at most \
|
45 | dd43edf4 | ths | three parts. */ \
|
46 | dd43edf4 | ths | version = 0; \
|
47 | dd43edf4 | ths | parts = 0; \
|
48 | dd43edf4 | ths | cp = buf; \ |
49 | dd43edf4 | ths | while ((*cp >= '0') && (*cp <= '9')) \ |
50 | dd43edf4 | ths | { \ |
51 | dd43edf4 | ths | unsigned int here = *cp++ - '0'; \ |
52 | dd43edf4 | ths | \ |
53 | dd43edf4 | ths | while ((*cp >= '0') && (*cp <= '9')) \ |
54 | dd43edf4 | ths | { \ |
55 | dd43edf4 | ths | here *= 10; \
|
56 | dd43edf4 | ths | here += *cp++ - '0'; \
|
57 | dd43edf4 | ths | } \ |
58 | dd43edf4 | ths | \ |
59 | dd43edf4 | ths | ++parts; \ |
60 | dd43edf4 | ths | version <<= 8; \
|
61 | dd43edf4 | ths | version |= here; \ |
62 | dd43edf4 | ths | \ |
63 | dd43edf4 | ths | if (*cp++ != '.') \ |
64 | dd43edf4 | ths | /* Another part following? */ \
|
65 | dd43edf4 | ths | break; \
|
66 | dd43edf4 | ths | } \ |
67 | dd43edf4 | ths | \ |
68 | dd43edf4 | ths | if (parts < 3) \ |
69 | dd43edf4 | ths | version <<= 8 * (3 - parts); \ |
70 | dd43edf4 | ths | \ |
71 | dd43edf4 | ths | /* Now we can test with the required version. */ \
|
72 | dd43edf4 | ths | if (version < __LINUX_KERNEL_VERSION) \
|
73 | dd43edf4 | ths | /* Not sufficent. */ \
|
74 | dd43edf4 | ths | FATAL ("FATAL: kernel too old\n"); \
|
75 | dd43edf4 | ths | \ |
76 | dd43edf4 | ths | _dl_osversion = version; \ |
77 | dd43edf4 | ths | } \ |
78 | dd43edf4 | ths | } while (0) |
79 | dd43edf4 | ths | |
80 | dd43edf4 | ths | int main(void) |
81 | dd43edf4 | ths | { |
82 | dd43edf4 | ths | char bufmem[64] = "2.6.22"; |
83 | dd43edf4 | ths | char *buf = bufmem;
|
84 | dd43edf4 | ths | unsigned int version; |
85 | dd43edf4 | ths | int parts;
|
86 | dd43edf4 | ths | char *cp;
|
87 | dd43edf4 | ths | |
88 | dd43edf4 | ths | version = 0;
|
89 | dd43edf4 | ths | parts = 0;
|
90 | dd43edf4 | ths | cp = buf; |
91 | dd43edf4 | ths | while ((*cp >= '0') && (*cp <= '9')) |
92 | dd43edf4 | ths | { |
93 | dd43edf4 | ths | unsigned int here = *cp++ - '0'; |
94 | dd43edf4 | ths | |
95 | dd43edf4 | ths | while ((*cp >= '0') && (*cp <= '9')) |
96 | dd43edf4 | ths | { |
97 | dd43edf4 | ths | here *= 10;
|
98 | dd43edf4 | ths | here += *cp++ - '0';
|
99 | dd43edf4 | ths | } |
100 | dd43edf4 | ths | |
101 | dd43edf4 | ths | ++parts; |
102 | dd43edf4 | ths | version <<= 8;
|
103 | dd43edf4 | ths | version |= here; |
104 | dd43edf4 | ths | |
105 | dd43edf4 | ths | if (*cp++ != '.') |
106 | dd43edf4 | ths | /* Another part following? */
|
107 | dd43edf4 | ths | break;
|
108 | dd43edf4 | ths | } |
109 | dd43edf4 | ths | |
110 | dd43edf4 | ths | if (parts < 3) |
111 | dd43edf4 | ths | version <<= 8 * (3 - parts); |
112 | dd43edf4 | ths | if (version < __LINUX_KERNEL_VERSION)
|
113 | dd43edf4 | ths | err(); |
114 | dd43edf4 | ths | pass(); |
115 | dd43edf4 | ths | exit(0);
|
116 | dd43edf4 | ths | } |