tcsetattr.c revision 1.8
11.8Sagc/*	$NetBSD: tcsetattr.c,v 1.8 2003/08/07 16:44:14 agc Exp $	*/
21.1Sjtc
31.1Sjtc/*-
41.1Sjtc * Copyright (c) 1989, 1993
51.1Sjtc *	The Regents of the University of California.  All rights reserved.
61.1Sjtc *
71.1Sjtc * Redistribution and use in source and binary forms, with or without
81.1Sjtc * modification, are permitted provided that the following conditions
91.1Sjtc * are met:
101.1Sjtc * 1. Redistributions of source code must retain the above copyright
111.1Sjtc *    notice, this list of conditions and the following disclaimer.
121.1Sjtc * 2. Redistributions in binary form must reproduce the above copyright
131.1Sjtc *    notice, this list of conditions and the following disclaimer in the
141.1Sjtc *    documentation and/or other materials provided with the distribution.
151.8Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Sjtc *    may be used to endorse or promote products derived from this software
171.1Sjtc *    without specific prior written permission.
181.1Sjtc *
191.1Sjtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Sjtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Sjtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Sjtc * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Sjtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Sjtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Sjtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Sjtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Sjtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Sjtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Sjtc * SUCH DAMAGE.
301.1Sjtc */
311.1Sjtc
321.3Schristos#include <sys/cdefs.h>
331.1Sjtc#if defined(LIBC_SCCS) && !defined(lint)
341.1Sjtc#if 0
351.1Sjtcstatic char sccsid[] = "@(#)termios.c	8.2 (Berkeley) 2/21/94";
361.1Sjtc#else
371.8Sagc__RCSID("$NetBSD: tcsetattr.c,v 1.8 2003/08/07 16:44:14 agc Exp $");
381.1Sjtc#endif
391.1Sjtc#endif /* LIBC_SCCS and not lint */
401.1Sjtc
411.4Sjtc#include "namespace.h"
421.1Sjtc#include <sys/ioctl.h>
431.5Slukem
441.5Slukem#include <assert.h>
451.5Slukem#include <errno.h>
461.5Slukem#include <stdio.h>
471.2Sjtc#include <termios.h>
481.4Sjtc
491.4Sjtc#ifdef __weak_alias
501.7Smycroft__weak_alias(tcsetattr,_tcsetattr)
511.4Sjtc#endif
521.1Sjtc
531.1Sjtcint
541.1Sjtctcsetattr(fd, opt, t)
551.1Sjtc	int fd, opt;
561.1Sjtc	const struct termios *t;
571.1Sjtc{
581.1Sjtc	struct termios localterm;
591.5Slukem
601.5Slukem	_DIAGASSERT(fd != -1);
611.5Slukem	_DIAGASSERT(t != NULL);
621.1Sjtc
631.1Sjtc	if (opt & TCSASOFT) {
641.1Sjtc		localterm = *t;
651.1Sjtc		localterm.c_cflag |= CIGNORE;
661.1Sjtc		t = &localterm;
671.1Sjtc	}
681.1Sjtc	switch (opt & ~TCSASOFT) {
691.1Sjtc	case TCSANOW:
701.1Sjtc		return (ioctl(fd, TIOCSETA, t));
711.1Sjtc	case TCSADRAIN:
721.1Sjtc		return (ioctl(fd, TIOCSETAW, t));
731.1Sjtc	case TCSAFLUSH:
741.1Sjtc		return (ioctl(fd, TIOCSETAF, t));
751.1Sjtc	default:
761.1Sjtc		errno = EINVAL;
771.1Sjtc		return (-1);
781.1Sjtc	}
791.1Sjtc}
80