6 #include <linux/termios.h>
10 * HACK: declare the ioctl function by hand...
12 * We cannot include <sys/ioctl.h> as it will eventually include
13 * <termios.h>, which will conflict with <linux/temios.h>. As we
14 * really need the latter one AND the ioctl, just declare it by hand
15 * here so that we get to use it...
17 int ioctl(int d, int request, ...);
20 * Open a serial device and adjust the baud rate to give (arbitrary)
21 * baud rate. The actual baud rate is stored back to the @baud
22 * variable. This might differ from the requested one as the
23 * underlying hardware may not support all possible baud
26 * Returns the file descriptor that was opened.
28 int open_at_baud(const char *device, int *baud)
33 fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
36 fprintf(stderr, "error opening %s: %m", device);
40 if (ioctl(fd, TCGETS2, &tios)) {
45 tios.c_cflag &= ~CBAUD;
46 tios.c_cflag |= BOTHER;
47 tios.c_ispeed = *baud;
48 tios.c_ospeed = *baud;
50 if (ioctl(fd, TCSETS2, &tios)) {
55 if (ioctl(fd, TCGETS2, &tios)) {
60 *baud = tios.c_ospeed;