1/* 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */ 29/* 30 * Copyright (c) 1988, 1989, 1993, 1994 31 * The Regents of the University of California. All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. All advertising materials mentioning features or use of this software 42 * must display the following acknowledgement: 43 * This product includes software developed by the University of 44 * California, Berkeley and its contributors. 45 * 4. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)termios.h 8.3 (Berkeley) 3/28/94 62 */ 63 64#ifndef _SYS_TERMIOS_H_ 65#define _SYS_TERMIOS_H_ 66 67#include <sys/cdefs.h> 68 69/* 70 * Special Control Characters 71 * 72 * Index into c_cc[] character array. 73 * 74 * Name Subscript Enabled by 75 */ 76#define VEOF 0 /* ICANON */ 77#define VEOL 1 /* ICANON */ 78#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 79#define VEOL2 2 /* ICANON together with IEXTEN */ 80#endif 81#define VERASE 3 /* ICANON */ 82#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 83#define VWERASE 4 /* ICANON together with IEXTEN */ 84#endif 85#define VKILL 5 /* ICANON */ 86#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 87#define VREPRINT 6 /* ICANON together with IEXTEN */ 88#endif 89/* 7 spare 1 */ 90#define VINTR 8 /* ISIG */ 91#define VQUIT 9 /* ISIG */ 92#define VSUSP 10 /* ISIG */ 93#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 94#define VDSUSP 11 /* ISIG together with IEXTEN */ 95#endif 96#define VSTART 12 /* IXON, IXOFF */ 97#define VSTOP 13 /* IXON, IXOFF */ 98#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 99#define VLNEXT 14 /* IEXTEN */ 100#define VDISCARD 15 /* IEXTEN */ 101#endif 102#define VMIN 16 /* !ICANON */ 103#define VTIME 17 /* !ICANON */ 104#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 105#define VSTATUS 18 /* ICANON together with IEXTEN */ 106/* 19 spare 2 */ 107#endif 108#define NCCS 20 109 110#include <sys/_types/_posix_vdisable.h> 111 112#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 113#define CCEQ(val, c) ((c) == (val) ? (val) != _POSIX_VDISABLE : 0) 114#endif 115 116/* 117 * Input flags - software input processing 118 */ 119#define IGNBRK 0x00000001 /* ignore BREAK condition */ 120#define BRKINT 0x00000002 /* map BREAK to SIGINTR */ 121#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ 122#define PARMRK 0x00000008 /* mark parity and framing errors */ 123#define INPCK 0x00000010 /* enable checking of parity errors */ 124#define ISTRIP 0x00000020 /* strip 8th bit off chars */ 125#define INLCR 0x00000040 /* map NL into CR */ 126#define IGNCR 0x00000080 /* ignore CR */ 127#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ 128#define IXON 0x00000200 /* enable output flow control */ 129#define IXOFF 0x00000400 /* enable input flow control */ 130#define IXANY 0x00000800 /* any char will restart after stop */ 131#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 132#define IMAXBEL 0x00002000 /* ring bell on input queue full */ 133#define IUTF8 0x00004000 /* maintain state for UTF-8 VERASE */ 134#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 135 136/* 137 * Output flags - software output processing 138 */ 139#define OPOST 0x00000001 /* enable following output processing */ 140#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ 141#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 142#define OXTABS 0x00000004 /* expand tabs to spaces */ 143#define ONOEOT 0x00000008 /* discard EOT's (^D) on output) */ 144#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 145/* 146 * The following block of features is unimplemented. Use of these flags in 147 * programs will currently result in unexpected behaviour. 148 * 149 * - Begin unimplemented features 150 */ 151#define OCRNL 0x00000010 /* map CR to NL on output */ 152#define ONOCR 0x00000020 /* no CR output at column 0 */ 153#define ONLRET 0x00000040 /* NL performs CR function */ 154#define OFILL 0x00000080 /* use fill characters for delay */ 155#define NLDLY 0x00000300 /* \n delay */ 156#define TABDLY 0x00000c04 /* horizontal tab delay */ 157#define CRDLY 0x00003000 /* \r delay */ 158#define FFDLY 0x00004000 /* form feed delay */ 159#define BSDLY 0x00008000 /* \b delay */ 160#define VTDLY 0x00010000 /* vertical tab delay */ 161#define OFDEL 0x00020000 /* fill is DEL, else NUL */ 162#if !defined(_SYS_IOCTL_COMPAT_H_) || __DARWIN_UNIX03 163/* 164 * These manifest constants have the same names as those in the header 165 * <sys/ioctl_compat.h>, so you are not permitted to have both definitions 166 * in scope simultaneously in the same compilation unit. Nevertheless, 167 * they are required to be in scope when _POSIX_C_SOURCE is requested; 168 * this means that including the <sys/ioctl_compat.h> header before this 169 * one when _POSIX_C_SOURCE is in scope will result in redefintions. We 170 * attempt to maintain these as the same values so as to avoid this being 171 * an outright error in most compilers. 172 */ 173#define NL0 0x00000000 174#define NL1 0x00000100 175#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 176#define NL2 0x00000200 177#define NL3 0x00000300 178#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 179#define TAB0 0x00000000 180#define TAB1 0x00000400 181#define TAB2 0x00000800 182/* not in sys/ioctl_compat.h, use OXTABS value */ 183#define TAB3 0x00000004 184#define CR0 0x00000000 185#define CR1 0x00001000 186#define CR2 0x00002000 187#define CR3 0x00003000 188#define FF0 0x00000000 189#define FF1 0x00004000 190#define BS0 0x00000000 191#define BS1 0x00008000 192#define VT0 0x00000000 193#define VT1 0x00010000 194#endif /* !_SYS_IOCTL_COMPAT_H_ */ 195/* 196 * + End unimplemented features 197 */ 198 199/* 200 * Control flags - hardware control of terminal 201 */ 202#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 203#define CIGNORE 0x00000001 /* ignore control flags */ 204#endif 205#define CSIZE 0x00000300 /* character size mask */ 206#define CS5 0x00000000 /* 5 bits (pseudo) */ 207#define CS6 0x00000100 /* 6 bits */ 208#define CS7 0x00000200 /* 7 bits */ 209#define CS8 0x00000300 /* 8 bits */ 210#define CSTOPB 0x00000400 /* send 2 stop bits */ 211#define CREAD 0x00000800 /* enable receiver */ 212#define PARENB 0x00001000 /* parity enable */ 213#define PARODD 0x00002000 /* odd parity, else even */ 214#define HUPCL 0x00004000 /* hang up on last close */ 215#define CLOCAL 0x00008000 /* ignore modem status lines */ 216#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 217#define CCTS_OFLOW 0x00010000 /* CTS flow control of output */ 218#define CRTSCTS (CCTS_OFLOW | CRTS_IFLOW) 219#define CRTS_IFLOW 0x00020000 /* RTS flow control of input */ 220#define CDTR_IFLOW 0x00040000 /* DTR flow control of input */ 221#define CDSR_OFLOW 0x00080000 /* DSR flow control of output */ 222#define CCAR_OFLOW 0x00100000 /* DCD flow control of output */ 223#define MDMBUF 0x00100000 /* old name for CCAR_OFLOW */ 224#endif 225 226 227/* 228 * "Local" flags - dumping ground for other state 229 * 230 * Warning: some flags in this structure begin with 231 * the letter "I" and look like they belong in the 232 * input flag. 233 */ 234 235#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 236#define ECHOKE 0x00000001 /* visual erase for line kill */ 237#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 238#define ECHOE 0x00000002 /* visually erase chars */ 239#define ECHOK 0x00000004 /* echo NL after line kill */ 240#define ECHO 0x00000008 /* enable echoing */ 241#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ 242#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 243#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ 244#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ 245#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 246#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ 247#define ICANON 0x00000100 /* canonicalize input lines */ 248#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 249#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ 250#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 251#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ 252#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 253#define EXTPROC 0x00000800 /* external processing */ 254#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 255#define TOSTOP 0x00400000 /* stop background jobs from output */ 256#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 257#define FLUSHO 0x00800000 /* output being flushed (state) */ 258#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ 259#define PENDIN 0x20000000 /* XXX retype pending input (state) */ 260#endif /*(_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 261#define NOFLSH 0x80000000 /* don't flush after interrupt */ 262 263typedef unsigned long tcflag_t; 264typedef unsigned char cc_t; 265typedef unsigned long speed_t; 266 267struct termios { 268 tcflag_t c_iflag; /* input flags */ 269 tcflag_t c_oflag; /* output flags */ 270 tcflag_t c_cflag; /* control flags */ 271 tcflag_t c_lflag; /* local flags */ 272 cc_t c_cc[NCCS]; /* control chars */ 273 speed_t c_ispeed; /* input speed */ 274 speed_t c_ospeed; /* output speed */ 275}; 276 277#ifdef KERNEL 278typedef __uint64_t user_tcflag_t; 279typedef __uint64_t user_speed_t; 280 281/* 282 * LP64 version of struct termios. tcflag_t and speed_t are long and must 283 * grow when we're dealing with a 64-bit process. 284 * WARNING - keep in sync with struct termios 285 */ 286 287struct user_termios { 288 user_tcflag_t c_iflag; /* input flags */ 289 user_tcflag_t c_oflag; /* output flags */ 290 user_tcflag_t c_cflag; /* control flags */ 291 user_tcflag_t c_lflag; /* local flags */ 292 cc_t c_cc[NCCS]; /* control chars */ 293 user_speed_t c_ispeed __attribute((aligned(8))); /* input speed */ 294 user_speed_t c_ospeed; /* output speed */ 295}; 296 297/* 32 bit version */ 298struct termios32 { 299 __uint32_t c_iflag; /* input flags */ 300 __uint32_t c_oflag; /* output flags */ 301 __uint32_t c_cflag; /* control flags */ 302 __uint32_t c_lflag; /* local flags */ 303 cc_t c_cc[NCCS]; /* control chars */ 304 __uint32_t c_ispeed; /* input speed */ 305 __uint32_t c_ospeed; /* output speed */ 306}; 307 308#endif /* KERNEL */ 309 310/* 311 * Commands passed to tcsetattr() for setting the termios structure. 312 */ 313#define TCSANOW 0 /* make change immediate */ 314#define TCSADRAIN 1 /* drain output, then change */ 315#define TCSAFLUSH 2 /* drain output, flush input */ 316#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 317#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ 318#endif 319 320/* 321 * Standard speeds 322 */ 323#define B0 0 324#define B50 50 325#define B75 75 326#define B110 110 327#define B134 134 328#define B150 150 329#define B200 200 330#define B300 300 331#define B600 600 332#define B1200 1200 333#define B1800 1800 334#define B2400 2400 335#define B4800 4800 336#define B9600 9600 337#define B19200 19200 338#define B38400 38400 339#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 340#define B7200 7200 341#define B14400 14400 342#define B28800 28800 343#define B57600 57600 344#define B76800 76800 345#define B115200 115200 346#define B230400 230400 347#define EXTA 19200 348#define EXTB 38400 349#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 350 351#ifndef KERNEL 352 353#define TCIFLUSH 1 354#define TCOFLUSH 2 355#define TCIOFLUSH 3 356#define TCOOFF 1 357#define TCOON 2 358#define TCIOFF 3 359#define TCION 4 360 361#include <sys/cdefs.h> 362 363__BEGIN_DECLS 364speed_t cfgetispeed(const struct termios *); 365speed_t cfgetospeed(const struct termios *); 366int cfsetispeed(struct termios *, speed_t); 367int cfsetospeed(struct termios *, speed_t); 368int tcgetattr(int, struct termios *); 369int tcsetattr(int, int, const struct termios *); 370int tcdrain(int) __DARWIN_ALIAS_C(tcdrain); 371int tcflow(int, int); 372int tcflush(int, int); 373int tcsendbreak(int, int); 374 375#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 376void cfmakeraw(struct termios *); 377int cfsetspeed(struct termios *, speed_t); 378#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 379__END_DECLS 380 381#endif /* !KERNEL */ 382 383#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 384 385/* 386 * Include tty ioctl's that aren't just for backwards compatibility 387 * with the old tty driver. These ioctl definitions were previously 388 * in <sys/ioctl.h>. 389 */ 390#include <sys/ttycom.h> 391#endif 392 393/* 394 * END OF PROTECTED INCLUDE. 395 */ 396#endif /* !_SYS_TERMIOS_H_ */ 397 398#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 399#include <sys/ttydefaults.h> 400#endif 401