perf: fix strerror_r override detection, apparently part of tools/ relies on non...
[openwrt/openwrt.git] / package / devel / perf / musl-compat.h
1 #ifndef __PERF_MUSL_COMPAT_H
2 #define __PERF_MUSL_COMPAT_H
3
4 #ifndef __ASSEMBLER__
5
6 #include <sys/ioctl.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <syscall.h>
10 #include <sched.h>
11
12 #undef _IOWR
13 #undef _IOR
14 #undef _IOW
15 #undef _IOC
16 #undef _IO
17
18 #define _SC_LEVEL1_DCACHE_LINESIZE -1
19
20 static inline long sysconf_wrap(int name)
21 {
22 FILE *f;
23 int val;
24
25 switch (name) {
26 case _SC_LEVEL1_DCACHE_LINESIZE:
27 f = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r");
28 if (!f)
29 return 0;
30
31 if (fscanf(f, "%d", &val) != 1)
32 return 0;
33
34 fclose(f);
35 return val;
36 default:
37 return sysconf(name);
38 }
39 }
40
41 #define sysconf(_n) sysconf_wrap(_n)
42
43 static inline int compat_sched_getcpu(void)
44 {
45 #ifdef __NR_getcpu
46 unsigned int val;
47
48 if (syscall(__NR_getcpu, &val))
49 return -1;
50
51 return val;
52 #else
53 return -1;
54 #endif
55 }
56
57 #define sched_getcpu compat_sched_getcpu
58
59 #endif
60 #endif