perf: fix build errors on x86 and other platforms
[openwrt/staging/wigyori.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 <string.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <syscall.h>
11 #include <sched.h>
12
13 #undef _IOWR
14 #undef _IOR
15 #undef _IOW
16 #undef _IOC
17 #undef _IO
18
19 /* Change XSI compliant version into GNU extension hackery */
20 static inline char *
21 gnu_strerror_r(int err, char *buf, size_t buflen)
22 {
23 if (strerror_r(err, buf, buflen))
24 return NULL;
25 return buf;
26 }
27 #define strerror_r gnu_strerror_r
28
29 #define _SC_LEVEL1_DCACHE_LINESIZE -1
30
31 static inline long sysconf_wrap(int name)
32 {
33 FILE *f;
34 int val;
35
36 switch (name) {
37 case _SC_LEVEL1_DCACHE_LINESIZE:
38 f = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r");
39 if (!f)
40 return 0;
41
42 if (fscanf(f, "%d", &val) != 1)
43 return 0;
44
45 fclose(f);
46 return val;
47 default:
48 return sysconf(name);
49 }
50 }
51
52 #define sysconf(_n) sysconf_wrap(_n)
53
54 static inline int compat_sched_getcpu(void)
55 {
56 #ifdef __NR_getcpu
57 unsigned int val;
58
59 if (syscall(__NR_getcpu, &val))
60 return -1;
61
62 return val;
63 #else
64 return -1;
65 #endif
66 }
67
68 #define sched_getcpu compat_sched_getcpu
69
70 #endif
71 #endif