1From 9664809da36bd7bada3e44f50cfc042539fb61ee Mon Sep 17 00:00:00 2001
2From: Paul Eggleton <paul.eggleton@linux.intel.com>
3Date: Sun, 14 Jul 2019 19:13:21 -0700
4Subject: [PATCH] Fix building with musl
5
6Upstream-status: Pending
7
8Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
9---
10 termios2.c | 27 +++++++++++++++++++++++++++
11 termios2.h |  5 +++++
12 2 files changed, 32 insertions(+)
13
14diff --git a/termios2.c b/termios2.c
15index 97c3be0..88ff6fc 100644
16--- a/termios2.c
17+++ b/termios2.c
18@@ -37,6 +37,7 @@
19 #include <errno.h>
20 #include <termios.h>
21 #include <sys/ioctl.h>
22+#include <asm/ioctls.h>
23
24 /* Contains the definition of the termios2 structure and some related
25    constants that we should normally include from system
26@@ -53,6 +54,10 @@
27 */
28 #define IBAUD0 020000000000
29
30+#if !defined(__GLIBC__)
31+#define __MAX_BAUD B4000000
32+#endif
33+
34 int
35 tc2setattr(int fd, int optional_actions, const struct termios *tios)
36 {
37@@ -79,8 +84,13 @@ tc2setattr(int fd, int optional_actions, const struct termios *tios)
38     t2.c_cflag = tios->c_cflag;
39     t2.c_lflag = tios->c_lflag;
40     t2.c_line = tios->c_line;
41+#if !defined(__GLIBC__)
42+    t2.c_ispeed = tios->__c_ispeed;
43+    t2.c_ospeed = tios->__c_ospeed;
44+#else
45     t2.c_ispeed = tios->c_ispeed;
46     t2.c_ospeed = tios->c_ospeed;
47+#endif
48     memcpy(&t2.c_cc[0], &tios->c_cc[0], K_NCCS * sizeof (cc_t));
49
50     return ioctl(fd, cmd, &t2);
51@@ -101,8 +111,13 @@ tc2getattr(int fd, struct termios *tios)
52     tios->c_cflag = t2.c_cflag;
53     tios->c_lflag = t2.c_lflag;
54     tios->c_line = t2.c_line;
55+#if !defined(__GLIBC__)
56+    tios->__c_ispeed = t2.c_ispeed;
57+    tios->__c_ospeed = t2.c_ospeed;
58+#else
59     tios->c_ispeed = t2.c_ispeed;
60     tios->c_ospeed = t2.c_ospeed;
61+#endif
62     memcpy(&tios->c_cc[0], &t2.c_cc[0], K_NCCS * sizeof (cc_t));
63
64     for (i = K_NCCS; i < NCCS; i++)
65@@ -131,7 +146,11 @@ cf2setispeed(struct termios *tios, speed_t speed)
66         errno = EINVAL;
67         return -1;
68     }
69+#if !defined(__GLIBC__)
70+    tios->__c_ispeed = speed;
71+#else
72     tios->c_ispeed = speed;
73+#endif
74     tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
75     tios->c_cflag |= (speed << IBSHIFT);
76
77@@ -156,7 +175,11 @@ cf2setospeed_custom(struct termios *tios, int speed)
78     }
79     tios->c_cflag &= ~(CBAUD | CBAUDEX);
80     tios->c_cflag |= BOTHER;
81+#if !defined(__GLIBC__)
82+    tios->__c_ospeed = speed;
83+#else
84     tios->c_ospeed = speed;
85+#endif
86
87     return 0;
88 }
89@@ -177,7 +200,11 @@ cf2setispeed_custom(struct termios *tios, int speed)
90     } else {
91         tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
92         tios->c_cflag |= (BOTHER << IBSHIFT);
93+#if !defined(__GLIBC__)
94+        tios->__c_ispeed = speed;
95+#else
96         tios->c_ispeed = speed;
97+#endif
98     }
99
100     return 0;
101diff --git a/termios2.h b/termios2.h
102index e13b0e3..63dd0ce 100644
103--- a/termios2.h
104+++ b/termios2.h
105@@ -37,8 +37,13 @@
106 /* And define these new ones */
107 #define cfsetospeed_custom cf2setospeed_custom
108 #define cfsetispeed_custom cf2setispeed_custom
109+#if defined(__linux__) && !defined(__GLIBC__)
110+#define cfgetospeed_custom(tiop) ((tiop)->__c_ospeed)
111+#define cfgetispeed_custom(tiop) ((tiop)->__c_ispeed)
112+#else
113 #define cfgetospeed_custom(tiop) ((tiop)->c_ospeed)
114 #define cfgetispeed_custom(tiop) ((tiop)->c_ispeed)
115+#endif
116
117 /* Replacements for the standard tcsetattr(3), tcgetattr(3)
118  * functions. Same user interface, but these use the new termios2
119