kernel: split patches folder up into backport, pending and hack folders
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 271-uapi-libc-compat.h-do-not-rely-on-__GLIBC__.patch
1 From: David Heidelberger <david.heidelberger@ixit.cz>
2 Subject: uapi/libc-compat.h: do not rely on __GLIBC__
3
4 Musl provides the same structs as glibc, but does not provide a define to
5 allow its detection. Since the absence of __GLIBC__ also can mean that it
6 is included from the kernel, change the __GLIBC__ detection to
7 !__KERNEL__, which should always be true when included from userspace.
8
9 Signed-off-by: John Spencer <maillist-linux@barfooze.de>
10 Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
11 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
12 ---
13  include/uapi/linux/libc-compat.h | 18 +++++++++---------
14  1 file changed, 9 insertions(+), 9 deletions(-)
15
16 --- a/include/uapi/linux/libc-compat.h
17 +++ b/include/uapi/linux/libc-compat.h
18 @@ -48,13 +48,13 @@
19  #ifndef _UAPI_LIBC_COMPAT_H
20  #define _UAPI_LIBC_COMPAT_H
21  
22 -/* We have included glibc headers... */
23 -#if defined(__GLIBC__)
24 +/* We have included libc headers... */
25 +#if !defined(__KERNEL__)
26  
27 -/* Coordinate with glibc net/if.h header. */
28 -#if defined(_NET_IF_H) && defined(__USE_MISC)
29 +/* Coordinate with libc net/if.h header. */
30 +#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))
31  
32 -/* GLIBC headers included first so don't define anything
33 +/* LIBC headers included first so don't define anything
34   * that would already be defined. */
35  
36  #define __UAPI_DEF_IF_IFCONF 0
37 @@ -65,7 +65,11 @@
38  #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
39  /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
40  #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
41 +#ifdef __GLIBC__
42  #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
43 +#else
44 +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0
45 +#endif
46  #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
47  
48  #else /* _NET_IF_H */
49 @@ -85,10 +89,10 @@
50  
51  #endif /* _NET_IF_H */
52  
53 -/* Coordinate with glibc netinet/in.h header. */
54 +/* Coordinate with libc netinet/in.h header. */
55  #if defined(_NETINET_IN_H)
56  
57 -/* GLIBC headers included first so don't define anything
58 +/* LIBC headers included first so don't define anything
59   * that would already be defined. */
60  #define __UAPI_DEF_IN_ADDR             0
61  #define __UAPI_DEF_IN_IPPROTO          0
62 @@ -102,7 +106,7 @@
63   * if the glibc code didn't define them. This guard matches
64   * the guard in glibc/inet/netinet/in.h which defines the
65   * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
66 -#if defined(__USE_MISC) || defined (__USE_GNU)
67 +#if !defined(__GLIBC__) || defined(__USE_MISC) || defined (__USE_GNU)
68  #define __UAPI_DEF_IN6_ADDR_ALT                0
69  #else
70  #define __UAPI_DEF_IN6_ADDR_ALT                1
71 @@ -117,7 +121,7 @@
72  #else
73  
74  /* Linux headers included first, and we must define everything
75 - * we need. The expectation is that glibc will check the
76 + * we need. The expectation is that the libc will check the
77   * __UAPI_DEF_* defines and adjust appropriately. */
78  #define __UAPI_DEF_IN_ADDR             1
79  #define __UAPI_DEF_IN_IPPROTO          1
80 @@ -127,7 +131,7 @@
81  #define __UAPI_DEF_IN_CLASS            1
82  
83  #define __UAPI_DEF_IN6_ADDR            1
84 -/* We unconditionally define the in6_addr macros and glibc must
85 +/* We unconditionally define the in6_addr macros and the libc must
86   * coordinate. */
87  #define __UAPI_DEF_IN6_ADDR_ALT                1
88  #define __UAPI_DEF_SOCKADDR_IN6                1
89 @@ -168,7 +172,7 @@
90  /* If we did not see any headers from any supported C libraries,
91   * or we are being included in the kernel, then define everything
92   * that we need. */
93 -#else /* !defined(__GLIBC__) */
94 +#else /* defined(__KERNEL__) */
95  
96  /* Definitions for if.h */
97  #define __UAPI_DEF_IF_IFCONF 1
98 @@ -208,6 +212,6 @@
99  /* Definitions for xattr.h */
100  #define __UAPI_DEF_XATTR               1
101  
102 -#endif /* __GLIBC__ */
103 +#endif /* __KERNEL__ */
104  
105  #endif /* _UAPI_LIBC_COMPAT_H */