cfsetspeed.c 3.3 KB

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