⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library_16.html

📁 Linux程序员的工作手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:
descriptors.  This means, for example, that you can't open one filedescriptor or stream to read from a terminal in the normalline-buffered, echoed mode; and simultaneously have another filedescriptor for the same terminal that you use to read from it insingle-character, non-echoed mode.  Instead, you have to explicitlyswitch the terminal back and forth between the two modes.<P><H3><A NAME="SEC275" HREF="library_toc.html#SEC275" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC275">Setting Terminal Modes Properly</A></H3><P>When you set terminal modes, you should call <CODE>tcgetattr</CODE> first toget the current modes of the particular terminal device, modify onlythose modes that you are really interested in, and store the result with<CODE>tcsetattr</CODE>.<P>It's a bad idea to simply initialize a <CODE>struct termios</CODE> structureto a chosen set of attributes and pass it directly to <CODE>tcsetattr</CODE>.Your program may be run years from now, on systems that support membersnot documented in this manual.  The way to avoid setting these membersto unreasonable values is to avoid changing them.<P>What's more, different terminal devices may require different modesettings in order to function properly.  So you should avoid blindlycopying attributes from one terminal device to another.<P>When a member contains a collection of independent flags, as the<CODE>c_iflag</CODE>, <CODE>c_oflag</CODE> and <CODE>c_cflag</CODE> members do, evensetting the entire member is a bad idea, because particular operatingsystems have their own flags.  Instead, you should start with thecurrent value of the member and alter only the flags whose values matterin your program, leaving any other flags unchanged.<P>Here is an example of how to set one flag (<CODE>ISTRIP</CODE>) in the<CODE>struct termios</CODE> structure while properly preserving all the otherdata in the structure:<P><PRE>intset_istrip (int desc, int value){  struct termios settings;  int result;  result = tcgetattr (desc, &#38;settings);  if (result &#60; 0)    {      perror ("error in tcgetattr");      return 0;    }  settings.c_iflag &#38;= ~ISTRIP;  if (value)    settings.c_iflag |= ISTRIP;  result = tcgetattr (desc, &#38;settings);  if (result &#60; 0)    {      perror ("error in tcgetattr");      return;   }  return 1;}</PRE><P><H3><A NAME="SEC276" HREF="library_toc.html#SEC276" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC276">Input Modes</A></H3><P>This section describes the terminal attribute flags that controlfairly low-level aspects of input processing: handling of parity errors,break signals, flow control, and <KBD>RET</KBD> and <KBD>LFD</KBD> characters.<P>All of these flags are bits in the <CODE>c_iflag</CODE> member of the<CODE>struct termios</CODE> structure.  The member is an integer, and youchange flags using the operators <CODE>&#38;</CODE>, <CODE>|</CODE> and <CODE>^</CODE>.  Don'ttry to specify the entire value for <CODE>c_iflag</CODE>---instead, changeonly specific flags and leave the rest untouched (see section <A HREF="library_16.html#SEC275" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC275">Setting Terminal Modes Properly</A>).<P><A NAME="IDX1103"></A><DL COMPACT><A NAME="IDX1104"></A><DT><CODE>INPCK</CODE><DD>If this bit is set, input parity checking is enabled.  If it is not set,no checking at all is done for parity errors on input; thecharacters are simply passed through to the application.<P>Parity checking on input processing is independent of whether paritydetection and generation on the underlying terminal hardware is enabled;see section <A HREF="library_16.html#SEC278" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC278">Control Modes</A>.  For example, you could clear the <CODE>INPCK</CODE>input mode flag and set the <CODE>PARENB</CODE> control mode flag to ignoreparity errors on input, but still generate parity on output.<P>If this bit is set, what happens when a parity error is detected dependson whether the <CODE>IGNPAR</CODE> or <CODE>PARMRK</CODE> bits are set.  If neitherof these bits are set, a byte with a parity error is passed to theapplication as a <CODE>'\0'</CODE> character.<A NAME="IDX1105"></A><P><DT><CODE>IGNPAR</CODE><DD>If this bit is set, any byte with a framing or parity error is ignored.This is only useful if <CODE>INPCK</CODE> is also set.<A NAME="IDX1106"></A><P><DT><CODE>PARMRK</CODE><DD>If this bit is set, input bytes with parity or framing errors are markedwhen passed to the program.  This bit is meaningful only when<CODE>INPCK</CODE> is set and <CODE>IGNPAR</CODE> is not set.<P>The way erroneous bytes are marked is with two preceding bytes,<CODE>377</CODE> and <CODE>0</CODE>.  Thus, the program actually reads three bytesfor one erroneous byte received from the terminal.<P>If a valid byte has the value <CODE>0377</CODE>, and <CODE>ISTRIP</CODE> (see below)is not set, the program might confuse it with the prefix that marks aparity error.  So a valid byte <CODE>0377</CODE> is passed to the program astwo bytes, <CODE>0377</CODE> <CODE>0377</CODE>, in this case.<A NAME="IDX1107"></A><P><DT><CODE>ISTRIP</CODE><DD>If this bit is set, valid input bytes are stripped to seven bits;otherwise, all eight bits are available for programs to read.<A NAME="IDX1108"></A><P><DT><CODE>IGNBRK</CODE><DD>If this bit is set, break conditions are ignored.<A NAME="IDX1109"></A><P>A <DFN>break condition</DFN> is defined in the context of asynchronousserial data transmission as a series of zero-value bits longer than asingle byte.<A NAME="IDX1110"></A><P><DT><CODE>BRKINT</CODE><DD>If this bit is set and <CODE>IGNBRK</CODE> is not set, a break conditionclears the terminal input and output queues and raises a <CODE>SIGINT</CODE>signal for the foreground process group associated with the terminal.<P>If neither <CODE>BRKINT</CODE> nor <CODE>IGNBRK</CODE> are set, a break condition ispassed to the application as a single <CODE>'\0'</CODE> character if<CODE>PARMRK</CODE> is not set, or otherwise as a three-character sequence <CODE>'\377'</CODE>, <CODE>'\0'</CODE>, <CODE>'\0'</CODE>.<A NAME="IDX1111"></A><P><DT><CODE>IGNCR</CODE><DD>If this bit is set, carriage return characters (<CODE>'\r'</CODE>) arediscarded on input.  Discarding carriage return may be useful onterminals that send both carriage return and linefeed when you type the<KBD>RET</KBD> key.<A NAME="IDX1112"></A><P><DT><CODE>ICRNL</CODE><DD>If this bit is set and <CODE>IGNCR</CODE> is not set, carriage return characters(<CODE>'\r'</CODE>) received as input are passed to the application as newlinecharacters (<CODE>'\n'</CODE>).<A NAME="IDX1113"></A><P><DT><CODE>INLCR</CODE><DD>If this bit is set, newline characters (<CODE>'\n'</CODE>) received as inputare passed to the application as carriage return characters (<CODE>'\r'</CODE>).<A NAME="IDX1114"></A><P><DT><CODE>IXOFF</CODE><DD>If this bit is set, start/stop control on input is enabled.  In otherwords, the computer sends STOP and START characters as necessary toprevent input from coming in faster than programs are reading it.  Theidea is that the actual terminal hardware that is generating the inputdata responds to a STOP character by suspending transmission, and to aSTART character by resuming transmission.  See section <A HREF="library_16.html#SEC285" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC285">Special Characters for Flow Control</A>.<A NAME="IDX1115"></A><P><DT><CODE>IXON</CODE><DD>If this bit is set, start/stop control on output is enabled.  In otherwords, if the computer receives a STOP character, it suspends outputuntil a START character is received.  In this case, the STOP and STARTcharacters are never passed to the application program.  If this bit isnot set, then START and STOP can be read as ordinary characters.See section <A HREF="library_16.html#SEC285" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC285">Special Characters for Flow Control</A>.<P><DT><CODE>IXANY</CODE><DD>If this bit is set, any input character restarts output when output hasbeen suspended with the STOP character.  Otherwise, only the STARTcharacter restarts output.<P><DT><CODE>IMAXBEL</CODE><DD>If this bit is set, then filling up the terminal input buffer sends aBEL character (code <CODE>007</CODE>) to the terminal to ring the bell.</DL><P><H3><A NAME="SEC277" HREF="library_toc.html#SEC277" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC277">Output Modes</A></H3><P>This section describes the terminal flags and fields that control howoutput characters are translated and padded for display.  All of theseare contained in the <CODE>c_oflag</CODE> member of the <CODE>struct termios</CODE>structure.<P>The <CODE>c_oflag</CODE> member itself is an integer, and you change the flagsand fields using the operators <CODE>&#38;</CODE>, <CODE>|</CODE>, and <CODE>^</CODE>.  Don'ttry to specify the entire value for <CODE>c_oflag</CODE>---instead, changeonly specific flags and leave the rest untouched (see section <A HREF="library_16.html#SEC275" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC275">Setting Terminal Modes Properly</A>).<P><A NAME="IDX1116"></A><U>Macro:</U> int <B>OPOST</B><P>If this bit is set, output data is processed in some unspecified way sothat it is displayed appropriately on the terminal device.  Thistypically includes mapping newline characters (<CODE>'\n'</CODE>) ontocarriage return and linefeed pairs.<P>If this bit isn't set, the characters are transmitted as-is.<P>The following three bits are BSD features, and they have no effect onnon-BSD systems.  On all systems, they are effective only if<CODE>OPOST</CODE> is set.<P><A NAME="IDX1117"></A><U>Macro:</U> int <B>ONLCR</B><P>If this bit is set, convert the newline character on output into a pairof characters, carriage return followed by linefeed.<P><A NAME="IDX1118"></A><U>Macro:</U> int <B>OXTABS</B><P>If this bit is set, convert tab characters on output into the appropriatenumber of spaces to emulate a tab stop every eight columns.<P><A NAME="IDX1119"></A><U>Macro:</U> int <B>ONOEOT</B><P>If this bit is set, discard <KBD>C-d</KBD> characters (code <CODE>004</CODE>) onoutput.  These characters cause many dial-up terminals to disconnect.<P><H3><A NAME="SEC278" HREF="library_toc.html#SEC278" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC278">Control Modes</A></H3><P>This section describes the terminal flags and fields that controlparameters usually associated with asynchronous serial datatransmission.  These flags may not make sense for other kinds ofterminal ports (such as a network connection pseudo-terminal).  All ofthese are contained in the <CODE>c_cflag</CODE> member of the <CODE>structtermios</CODE> structure.<P>The <CODE>c_cflag</CODE> member itself is an integer, and you change the flagsand fields using the operators <CODE>&#38;</CODE>, <CODE>|</CODE>, and <CODE>^</CODE>.  Don'ttry to specify the entire value for <CODE>c_cflag</CODE>---instead, changeonly specific flags and leave the rest untouched (see section <A HREF="library_16.html#SEC275" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC275">Setting Terminal Modes Properly</A>).<P><A NAME="IDX1120"></A><DL COMPACT><DT><CODE>CLOCAL</CODE><DD>If this bit is set, it indicates that the terminal is connected"locally" and that the modem status lines (such as carrier detect)should be ignored.<A NAME="IDX1122"></A><A NAME="IDX1121"></A><P>If this bit is not set and you call <CODE>open</CODE> without the<CODE>O_NONBLOCK</CODE> flag set, <CODE>open</CODE> blocks until a modemconnection is established.<P>If this bit is not set and a modem disconnect is detected, a<CODE>SIGHUP</CODE> signal is sent to the controlling process group for theterminal (if it has one).  Normally, this causes the process to exit;see section <A HREF="library_21.html#SEC330" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_21.html#SEC330">Signal Handling</A>.  Reading from the terminal after a disconnectcauses an end-of-file condition, and writing causes an <CODE>EIO</CODE> errorto be returned.  The terminal device must be closed and reopened toclear the condition.<A NAME="IDX1123"></A><A NAME="IDX1124"></A><P><DT><CODE>HUPCL</CODE><DD>If this bit is set, a modem disconnect is generated when all processesthat have the terminal device open have either closed the file or exited.<A NAME="IDX1125"></A>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -