1 | //===-- Linux implementation of cfsetospeed -------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/termios/cfsetospeed.h" |
10 | #include "src/__support/libc_errno.h" |
11 | #include "src/__support/macros/config.h" |
12 | |
13 | #include "src/__support/common.h" |
14 | |
15 | #include <termios.h> |
16 | |
17 | namespace LIBC_NAMESPACE_DECL { |
18 | |
19 | LLVM_LIBC_FUNCTION(int, cfsetospeed, (struct termios * t, speed_t speed)) { |
20 | constexpr speed_t NOT_SPEED_MASK = ~speed_t(CBAUD); |
21 | // A speed value is valid only if it is equal to one of the B<NN+> values. |
22 | if (t == nullptr || ((speed & NOT_SPEED_MASK) != 0)) { |
23 | libc_errno = EINVAL; |
24 | return -1; |
25 | } |
26 | |
27 | t->c_cflag = (t->c_cflag & NOT_SPEED_MASK) | speed; |
28 | t->c_ospeed = speed; |
29 | return 0; |
30 | } |
31 | |
32 | } // namespace LIBC_NAMESPACE_DECL |
33 | |