cfsetspeed.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <termios.h>
  16. #include <errno.h>
  17. #include <stddef.h>
  18. #ifdef __USE_BSD
  19. struct speed_struct
  20. {
  21. speed_t value;
  22. speed_t internal;
  23. };
  24. static const struct speed_struct speeds[] =
  25. {
  26. #ifdef B0
  27. { 0, B0 },
  28. #endif
  29. #ifdef B50
  30. { 50, B50 },
  31. #endif
  32. #ifdef B75
  33. { 75, B75 },
  34. #endif
  35. #ifdef B110
  36. { 110, B110 },
  37. #endif
  38. #ifdef B134
  39. { 134, B134 },
  40. #endif
  41. #ifdef B150
  42. { 150, B150 },
  43. #endif
  44. #ifdef B200
  45. { 200, B200 },
  46. #endif
  47. #ifdef B300
  48. { 300, B300 },
  49. #endif
  50. #ifdef B600
  51. { 600, B600 },
  52. #endif
  53. #ifdef B1200
  54. { 1200, B1200 },
  55. #endif
  56. #ifdef B1200
  57. { 1200, B1200 },
  58. #endif
  59. #ifdef B1800
  60. { 1800, B1800 },
  61. #endif
  62. #ifdef B2400
  63. { 2400, B2400 },
  64. #endif
  65. #ifdef B4800
  66. { 4800, B4800 },
  67. #endif
  68. #ifdef B9600
  69. { 9600, B9600 },
  70. #endif
  71. #ifdef B19200
  72. { 19200, B19200 },
  73. #endif
  74. #ifdef B38400
  75. { 38400, B38400 },
  76. #endif
  77. #ifdef B57600
  78. { 57600, B57600 },
  79. #endif
  80. #ifdef B76800
  81. { 76800, B76800 },
  82. #endif
  83. #ifdef B115200
  84. { 115200, B115200 },
  85. #endif
  86. #ifdef B153600
  87. { 153600, B153600 },
  88. #endif
  89. #ifdef B230400
  90. { 230400, B230400 },
  91. #endif
  92. #ifdef B307200
  93. { 307200, B307200 },
  94. #endif
  95. #ifdef B460800
  96. { 460800, B460800 },
  97. #endif
  98. #ifdef B500000
  99. { 500000, B500000 },
  100. #endif
  101. #ifdef B576000
  102. { 576000, B576000 },
  103. #endif
  104. #ifdef B614400
  105. { 614400, B614400 },
  106. #endif
  107. #ifdef B921600
  108. { 921600, B921600 },
  109. #endif
  110. #ifdef B1000000
  111. { 1000000, B1000000 },
  112. #endif
  113. #ifdef B1152000
  114. { 1152000, B1152000 },
  115. #endif
  116. #ifdef B1500000
  117. { 1500000, B1500000 },
  118. #endif
  119. #ifdef B1843200
  120. { 1843200, B1843200 },
  121. #endif
  122. #ifdef B2000000
  123. { 2000000, B2000000 },
  124. #endif
  125. #ifdef B2500000
  126. { 2500000, B2500000 },
  127. #endif
  128. #ifdef B3000000
  129. { 3000000, B3000000 },
  130. #endif
  131. #ifdef B3500000
  132. { 3500000, B3500000 },
  133. #endif
  134. #ifdef B4000000
  135. { 4000000, B4000000 },
  136. #endif
  137. #ifdef B6250000
  138. { 6250000, B6250000 },
  139. #endif
  140. #ifdef B12500000
  141. { 12500000, B12500000 },
  142. #endif
  143. };
  144. /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
  145. int cfsetspeed (struct termios *termios_p, speed_t speed)
  146. {
  147. size_t cnt;
  148. for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
  149. if (speed == speeds[cnt].internal)
  150. {
  151. cfsetispeed (termios_p, speed);
  152. cfsetospeed (termios_p, speed);
  153. return 0;
  154. }
  155. else if (speed == speeds[cnt].value)
  156. {
  157. cfsetispeed (termios_p, speeds[cnt].internal);
  158. cfsetospeed (termios_p, speeds[cnt].internal);
  159. return 0;
  160. }
  161. __set_errno (EINVAL);
  162. return -1;
  163. }
  164. #endif