1
2
3
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <stdint.h>
8#include "sys.h"
9
10#define __LINUX_KERNEL_VERSION 131584
11
12#define DL_SYSDEP_OSCHECK(FATAL) \
13 do { \
14
15
16 \
17 if (__LINUX_KERNEL_VERSION > 0) \
18 { \
19 char bufmem[64]; \
20 char *buf = bufmem; \
21 unsigned int version; \
22 int parts; \
23 char *cp; \
24 struct utsname uts; \
25 \
26 \
27 if (__uname (&uts)) \
28 { \
29
30 \
31 ssize_t reslen; \
32 int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY); \
33 if (fd == -1 \
34 || (reslen = __read (fd, bufmem, sizeof (bufmem))) <= 0) \
35
36 \
37 FATAL ("FATAL: cannot determine library version\n"); \
38 __close (fd); \
39 buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0'; \
40 } \
41 else \
42 buf = uts.release; \
43 \
44
45 \
46 version = 0; \
47 parts = 0; \
48 cp = buf; \
49 while ((*cp >= '0') && (*cp <= '9')) \
50 { \
51 unsigned int here = *cp++ - '0'; \
52 \
53 while ((*cp >= '0') && (*cp <= '9')) \
54 { \
55 here *= 10; \
56 here += *cp++ - '0'; \
57 } \
58 \
59 ++parts; \
60 version <<= 8; \
61 version |= here; \
62 \
63 if (*cp++ != '.') \
64 \
65 break; \
66 } \
67 \
68 if (parts < 3) \
69 version <<= 8 * (3 - parts); \
70 \
71 \
72 if (version < __LINUX_KERNEL_VERSION) \
73 \
74 FATAL ("FATAL: kernel too old\n"); \
75 \
76 _dl_osversion = version; \
77 } \
78 } while (0)
79
80int main(void)
81{
82 char bufmem[64] = "2.6.22";
83 char *buf = bufmem;
84 unsigned int version;
85 int parts;
86 char *cp;
87
88 version = 0;
89 parts = 0;
90 cp = buf;
91 while ((*cp >= '0') && (*cp <= '9'))
92 {
93 unsigned int here = *cp++ - '0';
94
95 while ((*cp >= '0') && (*cp <= '9'))
96 {
97 here *= 10;
98 here += *cp++ - '0';
99 }
100
101 ++parts;
102 version <<= 8;
103 version |= here;
104
105 if (*cp++ != '.')
106
107 break;
108 }
109
110 if (parts < 3)
111 version <<= 8 * (3 - parts);
112 if (version < __LINUX_KERNEL_VERSION)
113 err();
114 pass();
115 exit(0);
116}
117