cfsetspeed.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* Copyright (C) 1992,93,96,97,98,2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <termios.h>
  15. #include <errno.h>
  16. #include <stddef.h>
  17. #ifdef __USE_BSD
  18. struct speed_struct
  19. {
  20. speed_t value;
  21. speed_t internal;
  22. };
  23. static const struct speed_struct speeds[] =
  24. {
  25. #ifdef B0
  26. { 0, B0 },
  27. #endif
  28. #ifdef B50
  29. { 50, B50 },
  30. #endif
  31. #ifdef B75
  32. { 75, B75 },
  33. #endif
  34. #ifdef B110
  35. { 110, B110 },
  36. #endif
  37. #ifdef B134
  38. { 134, B134 },
  39. #endif
  40. #ifdef B150
  41. { 150, B150 },
  42. #endif
  43. #ifdef B200
  44. { 200, B200 },
  45. #endif
  46. #ifdef B300
  47. { 300, B300 },
  48. #endif
  49. #ifdef B600
  50. { 600, B600 },
  51. #endif
  52. #ifdef B1200
  53. { 1200, B1200 },
  54. #endif
  55. #ifdef B1200
  56. { 1200, B1200 },
  57. #endif
  58. #ifdef B1800
  59. { 1800, B1800 },
  60. #endif
  61. #ifdef B2400
  62. { 2400, B2400 },
  63. #endif
  64. #ifdef B4800
  65. { 4800, B4800 },
  66. #endif
  67. #ifdef B9600
  68. { 9600, B9600 },
  69. #endif
  70. #ifdef B19200
  71. { 19200, B19200 },
  72. #endif
  73. #ifdef B38400
  74. { 38400, B38400 },
  75. #endif
  76. #ifdef B57600
  77. { 57600, B57600 },
  78. #endif
  79. #ifdef B76800
  80. { 76800, B76800 },
  81. #endif
  82. #ifdef B115200
  83. { 115200, B115200 },
  84. #endif
  85. #ifdef B153600
  86. { 153600, B153600 },
  87. #endif
  88. #ifdef B230400
  89. { 230400, B230400 },
  90. #endif
  91. #ifdef B307200
  92. { 307200, B307200 },
  93. #endif
  94. #ifdef B460800
  95. { 460800, B460800 },
  96. #endif
  97. #ifdef B500000
  98. { 500000, B500000 },
  99. #endif
  100. #ifdef B576000
  101. { 576000, B576000 },
  102. #endif
  103. #ifdef B614400
  104. { 614400, B614400 },
  105. #endif
  106. #ifdef B921600
  107. { 921600, B921600 },
  108. #endif
  109. #ifdef B1000000
  110. { 1000000, B1000000 },
  111. #endif
  112. #ifdef B1152000
  113. { 1152000, B1152000 },
  114. #endif
  115. #ifdef B1500000
  116. { 1500000, B1500000 },
  117. #endif
  118. #ifdef B1843200
  119. { 1843200, B1843200 },
  120. #endif
  121. #ifdef B2000000
  122. { 2000000, B2000000 },
  123. #endif
  124. #ifdef B2500000
  125. { 2500000, B2500000 },
  126. #endif
  127. #ifdef B3000000
  128. { 3000000, B3000000 },
  129. #endif
  130. #ifdef B3500000
  131. { 3500000, B3500000 },
  132. #endif
  133. #ifdef B4000000
  134. { 4000000, B4000000 },
  135. #endif
  136. #ifdef B6250000
  137. { 6250000, B6250000 },
  138. #endif
  139. #ifdef B12500000
  140. { 12500000, B12500000 },
  141. #endif
  142. };
  143. /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
  144. int cfsetspeed (struct termios *termios_p, speed_t speed)
  145. {
  146. size_t cnt;
  147. for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
  148. if (speed == speeds[cnt].internal)
  149. {
  150. cfsetispeed (termios_p, speed);
  151. cfsetospeed (termios_p, speed);
  152. return 0;
  153. }
  154. else if (speed == speeds[cnt].value)
  155. {
  156. cfsetispeed (termios_p, speeds[cnt].internal);
  157. cfsetospeed (termios_p, speeds[cnt].internal);
  158. return 0;
  159. }
  160. __set_errno (EINVAL);
  161. return -1;
  162. }
  163. #endif