@@ -47,4 +47,226 @@ extern fn CInt sysctl(CInt *name, CUInt namelen, void *oldp, usz *oldlenp, void
4747
4848const SCHED_OTHER = 1 ;
4949const SCHED_FIFO = 4 ;
50- const SCHED_RR = 2 ;
50+ const SCHED_RR = 2 ;
51+
52+ module libc ::termios @if (env ::LIBC &&& env ::DARWIN );
53+
54+ bitstruct Tc_iflags : CULong
55+ {
56+ bool ignbrk : 0 ;
57+ bool brkint : 1 ;
58+ bool ignpar : 2 ;
59+ bool parmrk : 3 ;
60+ bool inpck : 4 ;
61+ bool istrip : 5 ;
62+ bool inlcr : 6 ;
63+ bool igncr : 7 ;
64+ bool icrnl : 8 ;
65+ bool ixon : 9 ;
66+ bool ixoff : 10 ;
67+ bool ixany : 11 ;
68+ bool imaxbel : 13 ;
69+ bool iutf8 : 14 ;
70+ }
71+
72+ bitstruct Tc_oflags : CULong
73+ {
74+ bool opost : 0 ;
75+ bool onlcr : 1 ;
76+ bool oxtabs : 2 ;
77+ bool onoeot : 3 ;
78+ bool ocrnl : 4 ;
79+ bool onocr : 5 ;
80+ bool onlret : 6 ;
81+ bool ofill : 7 ;
82+ T_nldly nldly : 8 .. 9 ;
83+ T_tabdly tabdly : 10 .. 11 ;
84+ T_crdly crdly : 12 .. 13 ;
85+ T_ffdly ffdly : 14 .. 14 ;
86+ T_bsdly bsdly : 15 .. 15 ;
87+ T_vtdly vtdly : 16 .. 16 ;
88+ bool ofdel : 17 ;
89+ }
90+
91+ bitstruct Tc_cflags : CULong
92+ {
93+ bool cignore : 0 ;
94+ T_csize csize : 8 .. 9 ;
95+ bool cstopb : 10 ;
96+ bool cread : 11 ;
97+ bool parenb : 12 ;
98+ bool parodd : 13 ;
99+ bool hupcl : 14 ;
100+ bool clocal : 15 ;
101+ bool ccts_oflow : 16 ;
102+ bool crts_iflow : 17 ;
103+ bool cdtr_iflow : 18 ;
104+ bool cdsr_oflow : 19 ;
105+ bool ccar_oflow : 20 ;
106+ }
107+
108+ bitstruct Tc_lflags : CULong
109+ {
110+ bool echoke : 0 ;
111+ bool echoe : 1 ;
112+ bool echok : 2 ;
113+ bool echo : 3 ;
114+ bool echonl : 4 ;
115+ bool echoprt : 5 ;
116+ bool echoctl : 6 ;
117+ bool isig : 7 ;
118+ bool icanon : 8 ;
119+ bool altwerase : 9 ;
120+ bool iexten : 10 ;
121+ bool extproc : 11 ;
122+ bool tostop : 22 ;
123+ bool flusho : 23 ;
124+ bool nokerninfo : 25 ;
125+ bool pendin : 29 ;
126+ bool noflsh : 31 ;
127+ }
128+
129+ constdef T_nldly : char
130+ {
131+ NL0 = 0b00 ,
132+ NL1 = 0b01 ,
133+ NL2 = 0b10 ,
134+ NL3 = 0b11 ,
135+ }
136+
137+ constdef T_crdly : char
138+ {
139+ CR0 = 0b00 ,
140+ CR1 = 0b01 ,
141+ CR2 = 0b10 ,
142+ CR3 = 0b11 ,
143+ }
144+
145+ constdef T_tabdly : char
146+ {
147+ // Darwin's TAB3 is the OXTABS bit, exposed as Tc_oflags.oxtabs.
148+ TAB0 = 0b00 ,
149+ TAB1 = 0b01 ,
150+ TAB2 = 0b10 ,
151+ }
152+
153+ constdef T_bsdly : char
154+ {
155+ BS0 = 0b0 ,
156+ BS1 = 0b1 ,
157+ }
158+
159+ constdef T_ffdly : char
160+ {
161+ FF0 = 0b0 ,
162+ FF1 = 0b1 ,
163+ }
164+
165+ constdef T_vtdly : char
166+ {
167+ VT0 = 0b0 ,
168+ VT1 = 0b1 ,
169+ }
170+
171+ constdef T_csize : char
172+ {
173+ CS5 = 0b00 ,
174+ CS6 = 0b01 ,
175+ CS7 = 0b10 ,
176+ CS8 = 0b11 ,
177+ }
178+
179+ constdef Speed : CULong
180+ {
181+ B0 = 0 ,
182+ B50 = 50 ,
183+ B75 = 75 ,
184+ B110 = 110 ,
185+ B134 = 134 ,
186+ B150 = 150 ,
187+ B200 = 200 ,
188+ B300 = 300 ,
189+ B600 = 600 ,
190+ B1200 = 1200 ,
191+ B1800 = 1800 ,
192+ B2400 = 2400 ,
193+ B4800 = 4800 ,
194+ B9600 = 9600 ,
195+ B19200 = 19200 ,
196+ B38400 = 38400 ,
197+ B7200 = 7200 ,
198+ B14400 = 14400 ,
199+ B28800 = 28800 ,
200+ B57600 = 57600 ,
201+ B76800 = 76800 ,
202+ B115200 = 115200 ,
203+ B230400 = 230400 ,
204+ EXTA = B19200 ,
205+ EXTB = B38400 ,
206+ }
207+
208+ constdef Control_Char : inline CInt
209+ {
210+ VEOF = 0 ,
211+ VEOL = 1 ,
212+ VEOL2 = 2 ,
213+ VERASE = 3 ,
214+ VWERASE = 4 ,
215+ VKILL = 5 ,
216+ VREPRINT = 6 ,
217+ VINTR = 8 ,
218+ VQUIT = 9 ,
219+ VSUSP = 10 ,
220+ VDSUSP = 11 ,
221+ VSTART = 12 ,
222+ VSTOP = 13 ,
223+ VLNEXT = 14 ,
224+ VDISCARD = 15 ,
225+ VMIN = 16 ,
226+ VTIME = 17 ,
227+ VSTATUS = 18 ,
228+ }
229+
230+ constdef Tcactions : CInt
231+ {
232+ TCSANOW = 0 ,
233+ TCSADRAIN = 1 ,
234+ TCSAFLUSH = 2 ,
235+ TCSASOFT = 0x10 ,
236+ TCIFLUSH = 1 ,
237+ TCOFLUSH = 2 ,
238+ TCIOFLUSH = 3 ,
239+ TCOOFF = 1 ,
240+ TCOON = 2 ,
241+ TCIOFF = 3 ,
242+ TCION = 4 ,
243+ }
244+
245+ extern fn CInt tcgetattr (Fd fd , Termios * self );
246+ extern fn CInt tcsetattr (Fd fd , Tcactions optional_actions , Termios * self );
247+ extern fn CInt tcsendbreak (Fd fd , CInt duration );
248+ extern fn CInt tcdrain (Fd fd );
249+ extern fn CInt tcflush (Fd fd , CInt queue_selector );
250+ extern fn CInt tcflow (Fd fd , CInt action );
251+ extern fn Speed cfgetospeed (Termios * self );
252+ extern fn Speed cfgetispeed (Termios * self );
253+ extern fn CInt cfsetospeed (Termios * self , Speed speed );
254+ extern fn CInt cfsetispeed (Termios * self , Speed speed );
255+ extern fn void cfmakeraw (Termios * self );
256+ extern fn CInt cfsetspeed (Termios * self , Speed speed );
257+ extern fn Pid_t tcgetsid (Fd fd );
258+
259+ alias Cc = char ;
260+
261+ const CInt NCCS = 20 ;
262+
263+ struct Termios
264+ {
265+ Tc_iflags c_iflag ;
266+ Tc_oflags c_oflag ;
267+ Tc_cflags c_cflag ;
268+ Tc_lflags c_lflag ;
269+ Cc [NCCS ] c_cc ;
270+ Speed c_ispeed ;
271+ Speed c_ospeed ;
272+ }
0 commit comments