aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Brown2021-07-12 09:24:12 -0400
committerKen Brown2021-07-13 09:02:45 -0400
commita41f585bf111b239601ca7d915994fed600852af (patch)
tree8e5791db4cbd0877e1cb18ce468114cfe6e7fb42 /src
parentd672d576ff6c3ac3c7ee1fa4db13c7e0a4974aa3 (diff)
downloademacs-a41f585bf111b239601ca7d915994fed600852af.tar.gz
emacs-a41f585bf111b239601ca7d915994fed600852af.zip
Fix portability issue with make-serial-process
* src/sysdep.c (struct speed_struct): New struct. (speeds): New static array of struct speed_struct. (convert_speed): New static function to convert a numerical baud rate (e.g., 9600) to a Bnnn constant defined in termios.h (e.g., B9600). (serial_configure): Use convert_speed to make the call to cfsetspeed compliant with its advertised API. (Bug#49524)
Diffstat (limited to 'src')
-rw-r--r--src/sysdep.c134
1 files changed, 133 insertions, 1 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index b8ec22d9dd9..8eaee224987 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2744,6 +2744,138 @@ cfsetspeed (struct termios *termios_p, speed_t vitesse)
2744} 2744}
2745#endif 2745#endif
2746 2746
2747/* The following is based on the glibc implementation of cfsetspeed. */
2748
2749struct speed_struct
2750{
2751 speed_t value;
2752 speed_t internal;
2753};
2754
2755static const struct speed_struct speeds[] =
2756 {
2757#ifdef B0
2758 { 0, B0 },
2759#endif
2760#ifdef B50
2761 { 50, B50 },
2762#endif
2763#ifdef B75
2764 { 75, B75 },
2765#endif
2766#ifdef B110
2767 { 110, B110 },
2768#endif
2769#ifdef B134
2770 { 134, B134 },
2771#endif
2772#ifdef B150
2773 { 150, B150 },
2774#endif
2775#ifdef B200
2776 { 200, B200 },
2777#endif
2778#ifdef B300
2779 { 300, B300 },
2780#endif
2781#ifdef B600
2782 { 600, B600 },
2783#endif
2784#ifdef B1200
2785 { 1200, B1200 },
2786#endif
2787#ifdef B1200
2788 { 1200, B1200 },
2789#endif
2790#ifdef B1800
2791 { 1800, B1800 },
2792#endif
2793#ifdef B2400
2794 { 2400, B2400 },
2795#endif
2796#ifdef B4800
2797 { 4800, B4800 },
2798#endif
2799#ifdef B9600
2800 { 9600, B9600 },
2801#endif
2802#ifdef B19200
2803 { 19200, B19200 },
2804#endif
2805#ifdef B38400
2806 { 38400, B38400 },
2807#endif
2808#ifdef B57600
2809 { 57600, B57600 },
2810#endif
2811#ifdef B76800
2812 { 76800, B76800 },
2813#endif
2814#ifdef B115200
2815 { 115200, B115200 },
2816#endif
2817#ifdef B153600
2818 { 153600, B153600 },
2819#endif
2820#ifdef B230400
2821 { 230400, B230400 },
2822#endif
2823#ifdef B307200
2824 { 307200, B307200 },
2825#endif
2826#ifdef B460800
2827 { 460800, B460800 },
2828#endif
2829#ifdef B500000
2830 { 500000, B500000 },
2831#endif
2832#ifdef B576000
2833 { 576000, B576000 },
2834#endif
2835#ifdef B921600
2836 { 921600, B921600 },
2837#endif
2838#ifdef B1000000
2839 { 1000000, B1000000 },
2840#endif
2841#ifdef B1152000
2842 { 1152000, B1152000 },
2843#endif
2844#ifdef B1500000
2845 { 1500000, B1500000 },
2846#endif
2847#ifdef B2000000
2848 { 2000000, B2000000 },
2849#endif
2850#ifdef B2500000
2851 { 2500000, B2500000 },
2852#endif
2853#ifdef B3000000
2854 { 3000000, B3000000 },
2855#endif
2856#ifdef B3500000
2857 { 3500000, B3500000 },
2858#endif
2859#ifdef B4000000
2860 { 4000000, B4000000 },
2861#endif
2862 };
2863
2864/* Convert a numerical speed (e.g., 9600) to a Bnnn constant (e.g.,
2865 B9600); see bug#49524. */
2866static speed_t
2867convert_speed (speed_t speed)
2868{
2869 for (size_t i = 0; i < sizeof speeds / sizeof speeds[0]; i++)
2870 {
2871 if (speed == speeds[i].internal)
2872 return speed;
2873 else if (speed == speeds[i].value)
2874 return speeds[i].internal;
2875 }
2876 return speed;
2877}
2878
2747/* For serial-process-configure */ 2879/* For serial-process-configure */
2748void 2880void
2749serial_configure (struct Lisp_Process *p, 2881serial_configure (struct Lisp_Process *p,
@@ -2775,7 +2907,7 @@ serial_configure (struct Lisp_Process *p,
2775 else 2907 else
2776 tem = Fplist_get (p->childp, QCspeed); 2908 tem = Fplist_get (p->childp, QCspeed);
2777 CHECK_FIXNUM (tem); 2909 CHECK_FIXNUM (tem);
2778 err = cfsetspeed (&attr, XFIXNUM (tem)); 2910 err = cfsetspeed (&attr, convert_speed (XFIXNUM (tem)));
2779 if (err != 0) 2911 if (err != 0)
2780 report_file_error ("Failed cfsetspeed", tem); 2912 report_file_error ("Failed cfsetspeed", tem);
2781 childp2 = Fplist_put (childp2, QCspeed, tem); 2913 childp2 = Fplist_put (childp2, QCspeed, tem);