tcsetattr.c revision 1.5
11.5Slukem/*	$NetBSD: tcsetattr.c,v 1.5 1999/09/16 11:45:45 lukem 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.1Sjtc * 3. All advertising materials mentioning features or use of this software
161.1Sjtc *    must display the following acknowledgement:
171.1Sjtc *	This product includes software developed by the University of
181.1Sjtc *	California, Berkeley and its contributors.
191.1Sjtc * 4. Neither the name of the University nor the names of its contributors
201.1Sjtc *    may be used to endorse or promote products derived from this software
211.1Sjtc *    without specific prior written permission.
221.1Sjtc *
231.1Sjtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
241.1Sjtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
251.1Sjtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261.1Sjtc * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271.1Sjtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281.1Sjtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
291.1Sjtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.1Sjtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.1Sjtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.1Sjtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.1Sjtc * SUCH DAMAGE.
341.1Sjtc */
351.1Sjtc
361.3Schristos#include <sys/cdefs.h>
371.1Sjtc#if defined(LIBC_SCCS) && !defined(lint)
381.1Sjtc#if 0
391.1Sjtcstatic char sccsid[] = "@(#)termios.c	8.2 (Berkeley) 2/21/94";
401.1Sjtc#else
411.5Slukem__RCSID("$NetBSD: tcsetattr.c,v 1.5 1999/09/16 11:45:45 lukem Exp $");
421.1Sjtc#endif
431.1Sjtc#endif /* LIBC_SCCS and not lint */
441.1Sjtc
451.4Sjtc#include "namespace.h"
461.1Sjtc#include <sys/ioctl.h>
471.5Slukem
481.5Slukem#include <assert.h>
491.5Slukem#include <errno.h>
501.5Slukem#include <stdio.h>
511.2Sjtc#include <termios.h>
521.4Sjtc
531.4Sjtc#ifdef __weak_alias
541.4Sjtc__weak_alias(tcsetattr,_tcsetattr);
551.4Sjtc#endif
561.1Sjtc
571.1Sjtcint
581.1Sjtctcsetattr(fd, opt, t)
591.1Sjtc	int fd, opt;
601.1Sjtc	const struct termios *t;
611.1Sjtc{
621.1Sjtc	struct termios localterm;
631.5Slukem
641.5Slukem	_DIAGASSERT(fd != -1);
651.5Slukem	_DIAGASSERT(t != NULL);
661.5Slukem#ifdef _DIAGNOSTIC
671.5Slukem	if (fd == -1) {
681.5Slukem		errno = EBADF;
691.5Slukem		return (-1);
701.5Slukem	}
711.5Slukem	if (t == NULL) {
721.5Slukem		errno = EFAULT;
731.5Slukem		return (-1);
741.5Slukem	}
751.5Slukem#endif
761.1Sjtc
771.1Sjtc	if (opt & TCSASOFT) {
781.1Sjtc		localterm = *t;
791.1Sjtc		localterm.c_cflag |= CIGNORE;
801.1Sjtc		t = &localterm;
811.1Sjtc	}
821.1Sjtc	switch (opt & ~TCSASOFT) {
831.1Sjtc	case TCSANOW:
841.1Sjtc		return (ioctl(fd, TIOCSETA, t));
851.1Sjtc	case TCSADRAIN:
861.1Sjtc		return (ioctl(fd, TIOCSETAW, t));
871.1Sjtc	case TCSAFLUSH:
881.1Sjtc		return (ioctl(fd, TIOCSETAF, t));
891.1Sjtc	default:
901.1Sjtc		errno = EINVAL;
911.1Sjtc		return (-1);
921.1Sjtc	}
931.1Sjtc}
94