1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Small refactoring in term.c for bsd improvements

Introduced `#define HAS_CUSTOM_BAUD` for platforms which have appropriate implementation.

Moving that `#if defined(__linux__) && defined(USE_CUSTOM_BAUD)` ... stuff out of `term.c`and put it to `termios2.h` / `custbaud_bsd.h` headers.
Moving that platform specific `#ifdefs` to the platform specific headers helps removing duplicate complex `#ifdef` constructs.
The both platform specific headers then do `#define HAS_CUSTOM_BAUD` to signal that custom baudrate support is implemented for the target platform.
I'd tested all above mentioned platforms with both USE_CUSTOM_BAUD unset and set to check if that refactoring don't raises unexpected issues.
This commit is contained in:
Joe Merten
2018-01-15 19:47:46 +01:00
parent ab140a283b
commit f9e0b4c8a2
6 changed files with 38 additions and 30 deletions

18
term.c
View File

@ -60,15 +60,11 @@
#include <sys/ioctl.h>
#endif
#if defined(__linux__) && defined(USE_CUSTOM_BAUD)
/* only works for linux, recent kernels */
#include "termios2.h"
#endif
#if (defined (__FreeBSD__) || defined(__APPLE__)) && defined(USE_CUSTOM_BAUD)
/* only for FreeBSD and macOS (Tiger and above) */
/* only for some BSD and macOS (Tiger and above) */
#include "custbaud_bsd.h"
#endif
/* Time to wait for UART to clear after a drain (in usec). */
#define DRAIN_DELAY 200000
@ -309,7 +305,7 @@ Bspeed(speed_t code)
int
term_baud_ok(int baud)
{
#ifndef USE_CUSTOM_BAUD
#ifndef HAS_CUSTOM_BAUD
return (Bcode(baud) != BNONE) ? 1 : 0;
#else
return (baud >= 0);
@ -801,7 +797,7 @@ term_set_baudrate (int fd, int baudrate)
}
cfsetispeed(&tio, B0);
} else {
#ifdef USE_CUSTOM_BAUD
#ifdef HAS_CUSTOM_BAUD
r = cfsetospeed_custom(&tio, baudrate);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
@ -809,11 +805,11 @@ term_set_baudrate (int fd, int baudrate)
break;
}
cfsetispeed(&tio, B0);
#else /* ! defined USE_CUSTOM_BAUD */
#else /* ! defined HAS_CUSTOM_BAUD */
term_errno = TERM_EBAUD;
rval = -1;
break;
#endif /* of USE_CUSTOM_BAUD */
#endif /* of HAS_CUSTOM_BAUD */
}
term.nexttermios[i] = tio;
@ -840,7 +836,7 @@ term_get_baudrate (int fd, int *ispeed)
if ( ispeed ) {
code = cfgetispeed(&term.currtermios[i]);
*ispeed = Bspeed(code);
#ifdef USE_CUSTOM_BAUD
#ifdef HAS_CUSTOM_BAUD
if ( *ispeed < 0 ) {
*ispeed = cfgetispeed_custom(&term.currtermios[i]);
}
@ -849,7 +845,7 @@ term_get_baudrate (int fd, int *ispeed)
code = cfgetospeed(&term.currtermios[i]);
ospeed = Bspeed(code);
if ( ospeed < 0 ) {
#ifdef USE_CUSTOM_BAUD
#ifdef HAS_CUSTOM_BAUD
ospeed = cfgetospeed_custom(&term.currtermios[i]);
if ( ospeed < 0 ) {
term_errno = TERM_EGETSPEED;