1*90275da6Sabs /* $NetBSD: tcflow.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */
25f11a56cSjtc
35f11a56cSjtc /*-
45f11a56cSjtc * Copyright (c) 1989, 1993
55f11a56cSjtc * The Regents of the University of California. All rights reserved.
65f11a56cSjtc *
75f11a56cSjtc * Redistribution and use in source and binary forms, with or without
85f11a56cSjtc * modification, are permitted provided that the following conditions
95f11a56cSjtc * are met:
105f11a56cSjtc * 1. Redistributions of source code must retain the above copyright
115f11a56cSjtc * notice, this list of conditions and the following disclaimer.
125f11a56cSjtc * 2. Redistributions in binary form must reproduce the above copyright
135f11a56cSjtc * notice, this list of conditions and the following disclaimer in the
145f11a56cSjtc * documentation and/or other materials provided with the distribution.
15eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
165f11a56cSjtc * may be used to endorse or promote products derived from this software
175f11a56cSjtc * without specific prior written permission.
185f11a56cSjtc *
195f11a56cSjtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
205f11a56cSjtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
215f11a56cSjtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
225f11a56cSjtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
235f11a56cSjtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
245f11a56cSjtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
255f11a56cSjtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
265f11a56cSjtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
275f11a56cSjtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
285f11a56cSjtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
295f11a56cSjtc * SUCH DAMAGE.
305f11a56cSjtc */
315f11a56cSjtc
323ad08ca2Schristos #include <sys/cdefs.h>
335f11a56cSjtc #if defined(LIBC_SCCS) && !defined(lint)
345f11a56cSjtc #if 0
355f11a56cSjtc static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94";
365f11a56cSjtc #else
37*90275da6Sabs __RCSID("$NetBSD: tcflow.c,v 1.9 2012/06/25 22:32:46 abs Exp $");
385f11a56cSjtc #endif
395f11a56cSjtc #endif /* LIBC_SCCS and not lint */
405f11a56cSjtc
4143fa6fe3Sjtc #include "namespace.h"
425f11a56cSjtc #include <sys/ioctl.h>
43b48252f3Slukem
44b48252f3Slukem #include <assert.h>
45b48252f3Slukem #include <errno.h>
465f11a56cSjtc #include <termios.h>
475f11a56cSjtc #include <unistd.h>
485f11a56cSjtc
4943fa6fe3Sjtc #ifdef __weak_alias
__weak_alias(tcflow,_tcflow)5060549036Smycroft __weak_alias(tcflow,_tcflow)
5143fa6fe3Sjtc #endif
5243fa6fe3Sjtc
535f11a56cSjtc int
54*90275da6Sabs tcflow(int fd, int action)
555f11a56cSjtc {
565f11a56cSjtc struct termios term;
575f11a56cSjtc u_char c;
585f11a56cSjtc
59b48252f3Slukem _DIAGASSERT(fd != -1);
60b48252f3Slukem
615f11a56cSjtc switch (action) {
625f11a56cSjtc case TCOOFF:
635f11a56cSjtc return (ioctl(fd, TIOCSTOP, 0));
645f11a56cSjtc case TCOON:
655f11a56cSjtc return (ioctl(fd, TIOCSTART, 0));
665f11a56cSjtc case TCION:
675f11a56cSjtc case TCIOFF:
685f11a56cSjtc if (tcgetattr(fd, &term) == -1)
695f11a56cSjtc return (-1);
705f11a56cSjtc c = term.c_cc[action == TCIOFF ? VSTOP : VSTART];
715f11a56cSjtc if (c != _POSIX_VDISABLE && write(fd, &c, sizeof(c)) == -1)
725f11a56cSjtc return (-1);
735f11a56cSjtc return (0);
745f11a56cSjtc default:
755f11a56cSjtc errno = EINVAL;
765f11a56cSjtc return (-1);
775f11a56cSjtc }
785f11a56cSjtc /* NOTREACHED */
795f11a56cSjtc }
80