1/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <errno.h>
19#include <stddef.h>
20#include <termios.h>
21#include <unistd.h>
22
23#include "bsdtty.h"
24
25/* Suspend or restart transmission on FD. */
26int
27tcflow (int fd, int action)
28{
29 switch (action)
30 {
31 case TCOOFF:
32 return __ioctl (fd, TIOCSTOP, (void *) NULL);
33 case TCOON:
34 return __ioctl (fd, TIOCSTART, (void *) NULL);
35
36 case TCIOFF:
37 case TCION:
38 {
39 /* This just writes the START or STOP character with
40 `write'. Is there another way to do this? */
41 struct termios attr;
42 unsigned char c;
43 if (__tcgetattr (fd, &attr) < 0)
44 return -1;
45 c = attr.c_cc[action == TCIOFF ? VSTOP : VSTART];
46 if (c != _POSIX_VDISABLE && write (fd, &c, 1) < 1)
47 return -1;
48 return 0;
49 }
50
51 default:
52 __set_errno (EINVAL);
53 return -1;
54 }
55}
56

source code of glibc/sysdeps/unix/bsd/tcflow.c