cfsetspeed.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. libc_hidden_proto(cfsetispeed)
  19. libc_hidden_proto(cfsetospeed)
  20. struct speed_struct
  21. {
  22. speed_t value;
  23. speed_t internal;
  24. };
  25. static const struct speed_struct speeds[] =
  26. {
  27. #ifdef B0
  28. { 0, B0 },
  29. #endif
  30. #ifdef B50
  31. { 50, B50 },
  32. #endif
  33. #ifdef B75
  34. { 75, B75 },
  35. #endif
  36. #ifdef B110
  37. { 110, B110 },
  38. #endif
  39. #ifdef B134
  40. { 134, B134 },
  41. #endif
  42. #ifdef B150
  43. { 150, B150 },
  44. #endif
  45. #ifdef B200
  46. { 200, B200 },
  47. #endif
  48. #ifdef B300
  49. { 300, B300 },
  50. #endif
  51. #ifdef B600
  52. { 600, B600 },
  53. #endif
  54. #ifdef B1200
  55. { 1200, B1200 },
  56. #endif
  57. #ifdef B1200
  58. { 1200, B1200 },
  59. #endif
  60. #ifdef B1800
  61. { 1800, B1800 },
  62. #endif
  63. #ifdef B2400
  64. { 2400, B2400 },
  65. #endif
  66. #ifdef B4800
  67. { 4800, B4800 },
  68. #endif
  69. #ifdef B9600
  70. { 9600, B9600 },
  71. #endif
  72. #ifdef B19200
  73. { 19200, B19200 },
  74. #endif
  75. #ifdef B38400
  76. { 38400, B38400 },
  77. #endif
  78. #ifdef B57600
  79. { 57600, B57600 },
  80. #endif
  81. #ifdef B76800
  82. { 76800, B76800 },
  83. #endif
  84. #ifdef B115200
  85. { 115200, B115200 },
  86. #endif
  87. #if 0 /* limited on uClibc, keep in sync w/ bits/termios.h */
  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 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 B2000000
  119. { 2000000, B2000000 },
  120. #endif
  121. #ifdef B2500000
  122. { 2500000, B2500000 },
  123. #endif
  124. #ifdef B3000000
  125. { 3000000, B3000000 },
  126. #endif
  127. #ifdef B3500000
  128. { 3500000, B3500000 },
  129. #endif
  130. #ifdef B4000000
  131. { 4000000, B4000000 },
  132. #endif
  133. #endif
  134. };
  135. /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
  136. int cfsetspeed (struct termios *termios_p, speed_t speed)
  137. {
  138. size_t cnt;
  139. for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
  140. if (speed == speeds[cnt].internal)
  141. {
  142. cfsetispeed (termios_p, speed);
  143. cfsetospeed (termios_p, speed);
  144. return 0;
  145. }
  146. else if (speed == speeds[cnt].value)
  147. {
  148. cfsetispeed (termios_p, speeds[cnt].internal);
  149. cfsetospeed (termios_p, speeds[cnt].internal);
  150. return 0;
  151. }
  152. __set_errno (EINVAL);
  153. return -1;
  154. }