termios.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <sys/cdefs.h>
  8. #include <sys/types.h>
  9. __BEGIN_DECLS
  10. #define NCCS 32
  11. typedef uint32_t tcflag_t;
  12. typedef uint8_t cc_t;
  13. typedef uint32_t speed_t;
  14. struct termios {
  15. tcflag_t c_iflag;
  16. tcflag_t c_oflag;
  17. tcflag_t c_cflag;
  18. tcflag_t c_lflag;
  19. cc_t c_cc[NCCS];
  20. speed_t c_ispeed;
  21. speed_t c_ospeed;
  22. };
  23. int tcgetattr(int fd, struct termios*);
  24. int tcsetattr(int fd, int optional_actions, const struct termios*);
  25. int tcflow(int fd, int action);
  26. int tcflush(int fd, int queue_selector);
  27. speed_t cfgetispeed(const struct termios*);
  28. speed_t cfgetospeed(const struct termios*);
  29. int cfsetispeed(struct termios*, speed_t);
  30. int cfsetospeed(struct termios*, speed_t);
  31. void cfmakeraw(struct termios*);
  32. /* c_cc characters */
  33. #define VINTR 0
  34. #define VQUIT 1
  35. #define VERASE 2
  36. #define VKILL 3
  37. #define VEOF 4
  38. #define VTIME 5
  39. #define VMIN 6
  40. #define VSWTC 7
  41. #define VSTART 8
  42. #define VSTOP 9
  43. #define VSUSP 10
  44. #define VEOL 11
  45. #define VREPRINT 12
  46. #define VDISCARD 13
  47. #define VWERASE 14
  48. #define VLNEXT 15
  49. #define VEOL2 16
  50. /* c_iflag bits */
  51. #define IGNBRK 0000001
  52. #define BRKINT 0000002
  53. #define IGNPAR 0000004
  54. #define PARMRK 0000010
  55. #define INPCK 0000020
  56. #define ISTRIP 0000040
  57. #define INLCR 0000100
  58. #define IGNCR 0000200
  59. #define ICRNL 0000400
  60. #define IUCLC 0001000
  61. #define IXON 0002000
  62. #define IXANY 0004000
  63. #define IXOFF 0010000
  64. #define IMAXBEL 0020000
  65. #define IUTF8 0040000
  66. /* c_oflag bits */
  67. #define OPOST 0000001
  68. #define OLCUC 0000002
  69. #define ONLCR 0000004
  70. #define OCRNL 0000010
  71. #define ONOCR 0000020
  72. #define ONLRET 0000040
  73. #define OFILL 0000100
  74. #define OFDEL 0000200
  75. #if defined __USE_MISC || defined __USE_XOPEN
  76. # define NLDLY 0000400
  77. # define NL0 0000000
  78. # define NL1 0000400
  79. # define CRDLY 0003000
  80. # define CR0 0000000
  81. # define CR1 0001000
  82. # define CR2 0002000
  83. # define CR3 0003000
  84. # define TABDLY 0014000
  85. # define TAB0 0000000
  86. # define TAB1 0004000
  87. # define TAB2 0010000
  88. # define TAB3 0014000
  89. # define BSDLY 0020000
  90. # define BS0 0000000
  91. # define BS1 0020000
  92. # define FFDLY 0100000
  93. # define FF0 0000000
  94. # define FF1 0100000
  95. #endif
  96. #define VTDLY 0040000
  97. #define VT0 0000000
  98. #define VT1 0040000
  99. #ifdef __USE_MISC
  100. # define XTABS 0014000
  101. #endif
  102. /* c_cflag bit meaning */
  103. #ifdef __USE_MISC
  104. # define CBAUD 0010017
  105. #endif
  106. #define B0 0000000 /* hang up */
  107. #define B50 0000001
  108. #define B75 0000002
  109. #define B110 0000003
  110. #define B134 0000004
  111. #define B150 0000005
  112. #define B200 0000006
  113. #define B300 0000007
  114. #define B600 0000010
  115. #define B1200 0000011
  116. #define B1800 0000012
  117. #define B2400 0000013
  118. #define B4800 0000014
  119. #define B9600 0000015
  120. #define B19200 0000016
  121. #define B38400 0000017
  122. #ifdef __USE_MISC
  123. # define EXTA B19200
  124. # define EXTB B38400
  125. #endif
  126. #define CSIZE 0000060
  127. #define CS5 0000000
  128. #define CS6 0000020
  129. #define CS7 0000040
  130. #define CS8 0000060
  131. #define CSTOPB 0000100
  132. #define CREAD 0000200
  133. #define PARENB 0000400
  134. #define PARODD 0001000
  135. #define HUPCL 0002000
  136. #define CLOCAL 0004000
  137. #ifdef __USE_MISC
  138. # define CBAUDEX 0010000
  139. #endif
  140. #define B57600 0010001
  141. #define B115200 0010002
  142. #define B230400 0010003
  143. #define B460800 0010004
  144. #define B500000 0010005
  145. #define B576000 0010006
  146. #define B921600 0010007
  147. #define B1000000 0010010
  148. #define B1152000 0010011
  149. #define B1500000 0010012
  150. #define B2000000 0010013
  151. #define B2500000 0010014
  152. #define B3000000 0010015
  153. #define B3500000 0010016
  154. #define B4000000 0010017
  155. #define __MAX_BAUD B4000000
  156. #ifdef __USE_MISC
  157. # define CIBAUD 002003600000 /* input baud rate (not used) */
  158. # define CMSPAR 010000000000 /* mark or space (stick) parity */
  159. # define CRTSCTS 020000000000 /* flow control */
  160. #endif
  161. /* c_lflag bits */
  162. #define ISIG 0000001
  163. #define ICANON 0000002
  164. #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
  165. # define XCASE 0000004
  166. #endif
  167. #define ECHO 0000010
  168. #define ECHOE 0000020
  169. #define ECHOK 0000040
  170. #define ECHONL 0000100
  171. #define NOFLSH 0000200
  172. #define TOSTOP 0000400
  173. #ifdef __USE_MISC
  174. # define ECHOCTL 0001000
  175. # define ECHOPRT 0002000
  176. # define ECHOKE 0004000
  177. # define FLUSHO 0010000
  178. # define PENDIN 0040000
  179. #endif
  180. #define IEXTEN 0100000
  181. #ifdef __USE_MISC
  182. # define EXTPROC 0200000
  183. #endif
  184. /* tcflow() and TCXONC use these */
  185. #define TCOOFF 0
  186. #define TCOON 1
  187. #define TCIOFF 2
  188. #define TCION 3
  189. /* tcflush() and TCFLSH use these */
  190. #define TCIFLUSH 0
  191. #define TCOFLUSH 1
  192. #define TCIOFLUSH 2
  193. /* tcsetattr uses these */
  194. #define TCSANOW 0
  195. #define TCSADRAIN 1
  196. #define TCSAFLUSH 2
  197. __END_DECLS