aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/cfsetspeed.c
blob: 8ce46f8d4fa4d250b1e7d310f3dece9d5fb1848e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* cfsetspeed(), Linux version.
   Copyright (C) 1991-2025 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <https://www.gnu.org/licenses/>.  */

#include <termios_internals.h>

/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED.  */
int
__cfsetspeed (struct termios *termios_p, speed_t speed)
{
  tcflag_t cbaud = ___speed_to_cbaud (speed);

  termios_p->c_ospeed = speed;
  termios_p->c_ispeed = speed;
  termios_p->c_cflag &= ~(CBAUD | CIBAUD);
  termios_p->c_cflag |= cbaud | (cbaud << IBSHIFT);

  return 0;
}
libc_hidden_def (__cfsetspeed)
versioned_symbol (libc, __cfsetspeed, cfsetspeed, GLIBC_2_42);

#if _TERMIOS_OLD_COMPAT

int
attribute_compat_text_section
__old_cfsetspeed (old_termios_t *termios_p, speed_t speed)
{
  speed_t real_speed = ___cbaud_to_speed (speed, -1);
  if (real_speed == (speed_t)-1)
    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);

#if !_HAVE_STRUCT_OLD_TERMIOS
  /* Otherwise these fields don't exist in old_termios_t */
  termios_p->c_ospeed = real_speed;
  termios_p->c_ispeed = real_speed;
#endif
  termios_p->c_cflag &= ~(CBAUD | CIBAUD);
  termios_p->c_cflag |= speed | (speed << IBSHIFT);

  return 0;
}
compat_symbol (libc, __old_cfsetspeed, cfsetspeed, GLIBC_2_0);

#endif /* _TERMIOS_OLD_COMPAT */