summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko2016-09-01 11:44:13 +0200
committerDenys Vlasenko2016-09-01 11:44:13 +0200
commit76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9 (patch)
tree9930441ae330aeebb4800b85cad88dc55ffcbebc /libbb
parentef15970d7ec904eb33ab572abc5de1f51b7e1cfa (diff)
downloadbusybox-76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9.zip
busybox-76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9.tar.gz
libbb/speed_table.c: survive B115200 and B230400 not fitting into 16 bits
Seen on OSX. While at it, expand baud table with B500000..B4000000 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/speed_table.c66
1 files changed, 55 insertions, 11 deletions
diff --git a/libbb/speed_table.c b/libbb/speed_table.c
index 174d531..3870d4f 100644
--- a/libbb/speed_table.c
+++ b/libbb/speed_table.c
@@ -10,7 +10,16 @@
#include "libbb.h"
struct speed_map {
-#if defined __FreeBSD__
+#if defined __FreeBSD__ \
+ || (defined B115200 && B115200 > 0xffff) \
+ || (defined B230400 && B230400 > 0xffff) \
+ || (defined B460800 && B460800 > 0xffff) \
+ || (defined B921600 && B921600 > 0xffff) \
+ || (defined B1152000 && B1152000 > 0xffff) \
+ || (defined B1000000 && B1000000 > 0xffff) \
+ || (defined B2000000 && B2000000 > 0xffff) \
+ || (defined B3000000 && B3000000 > 0xffff) \
+ || (defined B4000000 && B4000000 > 0xffff)
/* On FreeBSD, B<num> constants don't fit into a short */
unsigned speed;
#else
@@ -19,6 +28,7 @@ struct speed_map {
unsigned short value;
};
+/* On Linux, Bxx constants are 0..15 (up to B38400) and 0x1001..0x100f */
static const struct speed_map speeds[] = {
{B0, 0},
{B50, 50},
@@ -37,28 +47,62 @@ static const struct speed_map speeds[] = {
#ifdef B19200
{B19200, 19200},
#elif defined(EXTA)
- {EXTA, 19200},
+ {EXTA, 19200},
#endif
+/* 19200 = 0x4b00 */
+/* 38400 = 0x9600, this value would use bit#15 is not "/200" encoded: */
#ifdef B38400
- {B38400, 38400/256 + 0x8000U},
+ {B38400, 38400/200 + 0x8000u},
#elif defined(EXTB)
- {EXTB, 38400/256 + 0x8000U},
+ {EXTB, 38400/200 + 0x8000u},
#endif
#ifdef B57600
- {B57600, 57600/256 + 0x8000U},
+ {B57600, 57600/200 + 0x8000u},
#endif
#ifdef B115200
- {B115200, 115200/256 + 0x8000U},
+ {B115200, 115200/200 + 0x8000u},
#endif
#ifdef B230400
- {B230400, 230400/256 + 0x8000U},
+ {B230400, 230400/200 + 0x8000u},
#endif
#ifdef B460800
- {B460800, 460800/256 + 0x8000U},
+ {B460800, 460800/200 + 0x8000u},
+#endif
+#ifdef B576000
+ {B576000, 576000/200 + 0x8000u},
#endif
#ifdef B921600
- {B921600, 921600/256 + 0x8000U},
+ {B921600, 921600/200 + 0x8000u},
+#endif
+#ifdef B1152000
+ {B1152000, 1152000/200 + 0x8000u},
+#endif
+
+#ifdef B500000
+ {B500000, 500000/200 + 0x8000u},
+#endif
+#ifdef B1000000
+ {B1000000, 1000000/200 + 0x8000u},
+#endif
+#ifdef B1500000
+ {B1500000, 1500000/200 + 0x8000u},
+#endif
+#ifdef B2000000
+ {B2000000, 2000000/200 + 0x8000u},
+#endif
+#ifdef B2500000
+ {B2500000, 2500000/200 + 0x8000u},
+#endif
+#ifdef B3000000
+ {B3000000, 3000000/200 + 0x8000u},
+#endif
+#ifdef B3500000
+ {B3500000, 3500000/200 + 0x8000u},
+#endif
+#ifdef B4000000
+ {B4000000, 4000000/200 + 0x8000u},
#endif
+/* 4000000/200 = 0x4e20, bit#15 still does not interfere with the value */
};
enum { NUM_SPEEDS = ARRAY_SIZE(speeds) };
@@ -69,8 +113,8 @@ unsigned FAST_FUNC tty_baud_to_value(speed_t speed)
do {
if (speed == speeds[i].speed) {
- if (speeds[i].value & 0x8000U) {
- return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256;
+ if (speeds[i].value & 0x8000u) {
+ return ((unsigned long) (speeds[i].value) & 0x7fffU) * 200;
}
return speeds[i].value;
}