Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / termios / linux / cfsetospeed.cpp
blobd21f629cb74b6eb31d9e3e0bdca127d309c0ddb5
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 //===----------------------------------------------------------------------===//
9 #include "src/termios/cfsetospeed.h"
10 #include "src/errno/libc_errno.h"
12 #include "src/__support/common.h"
14 #include <termios.h>
16 namespace LIBC_NAMESPACE {
18 LLVM_LIBC_FUNCTION(int, cfsetospeed, (struct termios * t, speed_t speed)) {
19 constexpr speed_t NOT_SPEED_MASK = ~speed_t(CBAUD);
20 // A speed value is valid only if it is equal to one of the B<NN+> values.
21 if (t == nullptr || ((speed & NOT_SPEED_MASK) != 0)) {
22 libc_errno = EINVAL;
23 return -1;
26 t->c_cflag = (t->c_cflag & NOT_SPEED_MASK) | speed;
27 t->c_ospeed = speed;
28 return 0;
31 } // namespace LIBC_NAMESPACE