sdl: Fix termination in -no-shutdown mode
[qemu.git] / tests / cris / check_glibc_kernelversion.c
blobfcbc7b07f622198831bd3e908cfa90346ae7be8b
1 /*
2 * Check the lz insn.
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 #include "sys.h"
10 #define __LINUX_KERNEL_VERSION 131584
12 #define DL_SYSDEP_OSCHECK(FATAL) \
13 do { \
14 /* Test whether the kernel is new enough. This test is only \
15 performed if the library is not compiled to run on all \
16 kernels. */ \
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; \
26 /* Try the uname syscall */ \
27 if (__uname (&uts)) \
28 { \
29 /* This was not successful. Now try reading the /proc \
30 filesystem. */ \
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 /* This also didn't work. We give up since we cannot \
36 make sure the library can actually work. */ \
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; \
44 /* Now convert it into a number. The string consists of at most \
45 three parts. */ \
46 version = 0; \
47 parts = 0; \
48 cp = buf; \
49 while ((*cp >= '0') && (*cp <= '9')) \
50 { \
51 unsigned int here = *cp++ - '0'; \
53 while ((*cp >= '0') && (*cp <= '9')) \
54 { \
55 here *= 10; \
56 here += *cp++ - '0'; \
57 } \
59 ++parts; \
60 version <<= 8; \
61 version |= here; \
63 if (*cp++ != '.') \
64 /* Another part following? */ \
65 break; \
66 } \
68 if (parts < 3) \
69 version <<= 8 * (3 - parts); \
71 /* Now we can test with the required version. */ \
72 if (version < __LINUX_KERNEL_VERSION) \
73 /* Not sufficent. */ \
74 FATAL ("FATAL: kernel too old\n"); \
76 _dl_osversion = version; \
77 } \
78 } while (0)
80 int main(void)
82 char bufmem[64] = "2.6.22";
83 char *buf = bufmem;
84 unsigned int version;
85 int parts;
86 char *cp;
88 version = 0;
89 parts = 0;
90 cp = buf;
91 while ((*cp >= '0') && (*cp <= '9'))
93 unsigned int here = *cp++ - '0';
95 while ((*cp >= '0') && (*cp <= '9'))
97 here *= 10;
98 here += *cp++ - '0';
101 ++parts;
102 version <<= 8;
103 version |= here;
105 if (*cp++ != '.')
106 /* Another part following? */
107 break;
110 if (parts < 3)
111 version <<= 8 * (3 - parts);
112 if (version < __LINUX_KERNEL_VERSION)
113 err();
114 pass();
115 exit(0);