tcsendbreak 中文man頁面
NAME
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed - 獲取和設(shè)置終端屬性,行控制,獲取和設(shè)置波特率
SYNOPSIS 總覽
#include <termios.h>
#include <unistd.h> fd, struct termios *termios_p);
int tcgetattr(int
int tcsetattr(int fd, int optional_actions, struct termios *termios_p);
int tcsendbreak(int fd, int duration);
int tcdrain(int fd);
int tcflush(int fd, int queue_selector);
int tcflow(int fd, int action);
int cfmakeraw(struct termios *termios_p);
speed_t cfgetispeed(struct termios *termios_p);
speed_t cfgetospeed(struct termios *termios_p);
int cfsetispeed(struct termios *termios_p, speed_t speed);
int cfsetospeed(struct termios *termios_p, speed_t speed);
DESCRIPTION 描述
termios 函數(shù)族提供了一個(gè)常規(guī)的終端接口,用于控制非同步通信端口。
這里描述的大部分屬性有一個(gè) termios_p 類型的參數(shù),它是指向一個(gè) termios 結(jié)構(gòu)的指針。這個(gè)結(jié)構(gòu)包含了至少下列成員:
-
tcflag_t c_iflag; /* 輸入模式 */ tcflag_t c_oflag; /* 輸出模式 */ tcflag_t c_cflag; /* 控制模式 */ tcflag_t c_lflag; /* 本地模式 */ cc_t c_cc[NCCS]; /* 控制字符 */
c_iflag 標(biāo)志常量:
- IGNBRK
- 忽略輸入中的 BREAK 狀態(tài)。
- BRKINT
- 如果設(shè)置了 IGNBRK,將忽略 BREAK。如果沒有設(shè)置,但是設(shè)置了 BRKINT,那么 BREAK 將使得輸入和輸出隊(duì)列被刷新,如果終端是一個(gè)前臺進(jìn)程組的控制終端,這個(gè)進(jìn)程組中所有進(jìn)程將收到 SIGINT 信號。如果既未設(shè)置 IGNBRK 也未設(shè)置 BRKINT,BREAK 將視為與 NUL 字符同義,除非設(shè)置了 PARMRK,這種情況下它被視為序列 \377 \0 \0。
- IGNPAR
- 忽略楨錯(cuò)誤和奇偶校驗(yàn)錯(cuò)。
- PARMRK
- 如果沒有設(shè)置 IGNPAR,在有奇偶校驗(yàn)錯(cuò)或楨錯(cuò)誤的字符前插入 \377 \0。如果既沒有設(shè)置 IGNPAR 也沒有設(shè)置 PARMRK,將有奇偶校驗(yàn)錯(cuò)或楨錯(cuò)誤的字符視為 \0。
- INPCK
- 啟用輸入奇偶檢測。
- ISTRIP
- 去掉第八位。
- INLCR
- 將輸入中的 NL 翻譯為 CR。
- IGNCR
- 忽略輸入中的回車。
- ICRNL
- 將輸入中的回車翻譯為新行 (除非設(shè)置了 IGNCR)。
- IUCLC
- (不屬于 POSIX) 將輸入中的大寫字母映射為小寫字母。
- IXON
- 啟用輸出的 XON/XOFF 流控制。
- IXANY
- (不屬于 POSIX.1;XSI) 允許任何字符來重新開始輸出。(?)
- IXOFF
- 啟用輸入的 XON/XOFF 流控制。
- IMAXBEL
- (不屬于 POSIX) 當(dāng)輸入隊(duì)列滿時(shí)響零。Linux 沒有實(shí)現(xiàn)這一位,總是將它視為已設(shè)置。
POSIX.1 中定義的 c_oflag 標(biāo)志常量:
- OPOST
- 啟用具體實(shí)現(xiàn)自行定義的輸出處理。
其余 c_oflag 標(biāo)志常量定義在 POSIX 1003.1-2001 中,除非另外說明。
- OLCUC
- (不屬于 POSIX) 將輸出中的小寫字母映射為大寫字母。
- ONLCR
- (XSI) 將輸出中的新行符映射為回車-換行。
- OCRNL
- 將輸出中的回車映射為新行符
- ONOCR
- 不在第 0 列輸出回車。
- ONLRET
- 不輸出回車。
- OFILL
- 發(fā)送填充字符作為延時(shí),而不是使用定時(shí)來延時(shí)。
- OFDEL
- (不屬于 POSIX) 填充字符是 ASCII DEL (0177)。如果不設(shè)置,填充字符則是 ASCII NUL。
- NLDLY
- 新行延時(shí)掩碼。取值為 NL0 和 NL1。
- CRDLY
- 回車延時(shí)掩碼。取值為 CR0, CR1, CR2, 或 CR3。
- TABDLY
- 水平跳格延時(shí)掩碼。取值為 TAB0, TAB1, TAB2, TAB3 (或 XTABS)。取值為 TAB3,即 XTABS,將擴(kuò)展跳格為空格 (每個(gè)跳格符填充 8 個(gè)空格)。(?)
- BSDLY
- 回退延時(shí)掩碼。取值為 BS0 或 BS1。(從來沒有被實(shí)現(xiàn)過)
- VTDLY
- 豎直跳格延時(shí)掩碼。取值為 VT0 或 VT1。
- FFDLY
- 進(jìn)表延時(shí)掩碼。取值為 FF0 或 FF1。
c_cflag 標(biāo)志常量:
- CBAUD
- (不屬于 POSIX) 波特率掩碼 (4+1 位)。
- CBAUDEX
- (不屬于 POSIX) 擴(kuò)展的波特率掩碼 (1 位),包含在 CBAUD 中。
(POSIX 規(guī)定波特率存儲在 termios 結(jié)構(gòu)中,并未精確指定它的位置,而是提供了函數(shù) cfgetispeed() 和 cfsetispeed() 來存取它。一些系統(tǒng)使用 c_cflag 中 CBAUD 選擇的位,其他系統(tǒng)使用單獨(dú)的變量,例如 sg_ispeed 和 sg_ospeed 。)
- CSIZE
- 字符長度掩碼。取值為 CS5, CS6, CS7, 或 CS8。
- CSTOPB
- 設(shè)置兩個(gè)停止位,而不是一個(gè)。
- CREAD
- 打開接受者。
- PARENB
- 允許輸出產(chǎn)生奇偶信息以及輸入的奇偶校驗(yàn)。
- PARODD
- 輸入和輸出是奇校驗(yàn)。
- HUPCL
- 在最后一個(gè)進(jìn)程關(guān)閉設(shè)備后,降低 modem 控制線 (掛斷)。(?)
- CLOCAL
- 忽略 modem 控制線。
- LOBLK
- (不屬于 POSIX) 從非當(dāng)前 shell 層阻塞輸出(用于 shl )。(?)
- CIBAUD
- (不屬于 POSIX) 輸入速度的掩碼。CIBAUD 各位的值與 CBAUD 各位相同,左移了 IBSHIFT 位。
- CRTSCTS
- (不屬于 POSIX) 啟用 RTS/CTS (硬件) 流控制。
c_lflag 標(biāo)志常量:
- ISIG
- 當(dāng)接受到字符 INTR, QUIT, SUSP, 或 DSUSP 時(shí),產(chǎn)生相應(yīng)的信號。
- ICANON
- 啟用標(biāo)準(zhǔn)模式 (canonical mode)。允許使用特殊字符 EOF, EOL, EOL2, ERASE, KILL, LNEXT, REPRINT, STATUS, 和 WERASE,以及按行的緩沖。
- XCASE
- (不屬于 POSIX; Linux 下不被支持) 如果同時(shí)設(shè)置了 ICANON,終端只有大寫。輸入被轉(zhuǎn)換為小寫,除了以 \ 前綴的字符。輸出時(shí),大寫字符被前綴 \,小寫字符被轉(zhuǎn)換成大寫。
- ECHO
- 回顯輸入字符。
- ECHOE
- 如果同時(shí)設(shè)置了 ICANON,字符 ERASE 擦除前一個(gè)輸入字符,WERASE 擦除前一個(gè)詞。
- ECHOK
- 如果同時(shí)設(shè)置了 ICANON,字符 KILL 刪除當(dāng)前行。
- ECHONL
- 如果同時(shí)設(shè)置了 ICANON,回顯字符 NL,即使沒有設(shè)置 ECHO。
- ECHOCTL
- (不屬于 POSIX) 如果同時(shí)設(shè)置了 ECHO,除了 TAB, NL, START, 和 STOP 之外的 ASCII 控制信號被回顯為 ^X, 這里 X 是比控制信號大 0x40 的 ASCII 碼。例如,字符 0x08 (BS) 被回顯為 ^H。
- ECHOPRT
- (不屬于 POSIX) 如果同時(shí)設(shè)置了 ICANON 和 IECHO,字符在刪除的同時(shí)被打印。
- ECHOKE
- (不屬于 POSIX) 如果同時(shí)設(shè)置了 ICANON,回顯 KILL 時(shí)將刪除一行中的每個(gè)字符,如同指定了 ECHOE 和 ECHOPRT 一樣。
- DEFECHO
- (不屬于 POSIX) 只在一個(gè)進(jìn)程讀的時(shí)候回顯。
- FLUSHO
- (不屬于 POSIX; Linux 下不被支持) 輸出被刷新。這個(gè)標(biāo)志可以通過鍵入字符 DISCARD 來開關(guān)。
- NOFLSH
- 禁止在產(chǎn)生 SIGINT, SIGQUIT 和 SIGSUSP 信號時(shí)刷新輸入和輸出隊(duì)列。
- TOSTOP
- 向試圖寫控制終端的后臺進(jìn)程組發(fā)送 SIGTTOU 信號。
- PENDIN
- (不屬于 POSIX; Linux 下不被支持) 在讀入下一個(gè)字符時(shí),輸入隊(duì)列中所有字符被重新輸出。(bash 用它來處理 typeahead)
- IEXTEN
- 啟用實(shí)現(xiàn)自定義的輸入處理。這個(gè)標(biāo)志必須與 ICANON 同時(shí)使用,才能解釋特殊字符 EOL2,LNEXT,REPRINT 和 WERASE,IUCLC 標(biāo)志才有效。
c_cc 數(shù)組定義了特殊的控制字符。符號下標(biāo) (初始值) 和意義為:
- VINTR
- (003, ETX, Ctrl-C, or also 0177, DEL, rubout) 中斷字符。發(fā)出 SIGINT 信號。當(dāng)設(shè)置 ISIG 時(shí)可被識別,不再作為輸入傳遞。
- VQUIT
- (034, FS, Ctrl-\) 退出字符。發(fā)出 SIGQUIT 信號。當(dāng)設(shè)置 ISIG 時(shí)可被識別,不再作為輸入傳遞。
- VERASE
- (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #) 刪除字符。刪除上一個(gè)還沒有刪掉的字符,但不刪除上一個(gè) EOF 或行首。當(dāng)設(shè)置 ICANON 時(shí)可被識別,不再作為輸入傳遞。
- VKILL
- (025, NAK, Ctrl-U, or Ctrl-X, or also @) 終止字符。刪除自上一個(gè) EOF 或行首以來的輸入。當(dāng)設(shè)置 ICANON 時(shí)可被識別,不再作為輸入傳遞。
- VEOF
- (004, EOT, Ctrl-D) 文件尾字符。更精確地說,這個(gè)字符使得 tty 緩沖中的內(nèi)容被送到等待輸入的用戶程序中,而不必等到 EOL。如果它是一行的第一個(gè)字符,那么用戶程序的 read() 將返回 0,指示讀到了 EOF。當(dāng)設(shè)置 ICANON 時(shí)可被識別,不再作為輸入傳遞。
- VMIN
- 非 canonical 模式讀的最小字符數(shù)。
- VEOL
- (0, NUL) 附加的行尾字符。當(dāng)設(shè)置 ICANON 時(shí)可被識別。
- VTIME
- 非 canonical 模式讀時(shí)的延時(shí),以十分之一秒為單位。
- VEOL2
- (not in POSIX; 0, NUL) 另一個(gè)行尾字符。當(dāng)設(shè)置 ICANON 時(shí)可被識別。
- VSWTCH
- (not in POSIX; not supported under Linux; 0, NUL) 開關(guān)字符。(只為 shl 所用。)
- VSTART
- (021, DC1, Ctrl-Q) 開始字符。重新開始被 Stop 字符中止的輸出。當(dāng)設(shè)置 IXON 時(shí)可被識別,不再作為輸入傳遞。
- VSTOP
- (023, DC3, Ctrl-S) 停止字符。停止輸出,直到鍵入 Start 字符。當(dāng)設(shè)置 IXON 時(shí)可被識別,不再作為輸入傳遞。
- VSUSP
- (032, SUB, Ctrl-Z) 掛起字符。發(fā)送 SIGTSTP 信號。當(dāng)設(shè)置 ISIG 時(shí)可被識別,不再作為輸入傳遞。
- VDSUSP
- (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y) 延時(shí)掛起信號。當(dāng)用戶程序讀到這個(gè)字符時(shí),發(fā)送 SIGTSTP 信號。當(dāng)設(shè)置 IEXTEN 和 ISIG,并且系統(tǒng)支持作業(yè)管理時(shí)可被識別,不再作為輸入傳遞。
- VLNEXT
- (not in POSIX; 026, SYN, Ctrl-V) 字面上的下一個(gè)。引用下一個(gè)輸入字符,取消它的任何特殊含義。當(dāng)設(shè)置 IEXTEN 時(shí)可被識別,不再作為輸入傳遞。
- VWERASE
- (not in POSIX; 027, ETB, Ctrl-W) 刪除詞。當(dāng)設(shè)置 ICANON 和 IEXTEN 時(shí)可被識別,不再作為輸入傳遞。
- VREPRINT
- (not in POSIX; 022, DC2, Ctrl-R) 重新輸出未讀的字符。當(dāng)設(shè)置 ICANON 和 IEXTEN 時(shí)可被識別,不再作為輸入傳遞。
- VDISCARD
- (not in POSIX; not supported under Linux; 017, SI, Ctrl-O) 開關(guān):開始/結(jié)束丟棄未完成的輸出。當(dāng)設(shè)置 IEXTEN 時(shí)可被識別,不再作為輸入傳遞。
- VSTATUS
- (not in POSIX; not supported under Linux; status request: 024, DC4, Ctrl-T).
這些符號下標(biāo)值是互不相同的,除了 VTIME,VMIN 的值可能分別與 VEOL,VEOF 相同。 (在 non-canonical 模式下,特殊字符的含義更改為延時(shí)含義。MIN 表示應(yīng)當(dāng)被讀入的最小字符數(shù)。TIME 是以十分之一秒為單位的計(jì)時(shí)器。如果同時(shí)設(shè)置了它們,read 將等待直到至少讀入一個(gè)字符,一旦讀入 MIN 個(gè)字符或者從上次讀入字符開始經(jīng)過了 TIME 時(shí)間就立即返回。如果只設(shè)置了 MIN,read 在讀入 MIN 個(gè)字符之前不會(huì)返回。如果只設(shè)置了 TIME,read 將在至少讀入一個(gè)字符,或者計(jì)時(shí)器超時(shí)的時(shí)候立即返回。如果都沒有設(shè)置,read 將立即返回,只給出當(dāng)前準(zhǔn)備好的字符。) (?)
tcgetattr() 得到與 fd 指向的對象相關(guān)的參數(shù),將它們保存于 termios_p 引用的 termios 結(jié)構(gòu)中。函數(shù)可以從后臺進(jìn)程中調(diào)用;但是,終端屬性可能被后來的前臺進(jìn)程所改變。
tcsetattr() 設(shè)置與終端相關(guān)的參數(shù) (除非需要底層支持卻無法滿足),使用 termios_p 引用的 termios 結(jié)構(gòu)。optional_actions 指定了什么時(shí)候改變會(huì)起作用:
- TCSANOW
- 改變立即發(fā)生
- TCSADRAIN
- 改變在所有寫入 fd 的輸出都被傳輸后生效。這個(gè)函數(shù)應(yīng)當(dāng)用于修改影響輸出的參數(shù)時(shí)使用。
- TCSAFLUSH
- 改變在所有寫入 fd 引用的對象的輸出都被傳輸后生效,所有已接受但未讀入的輸入都在改變發(fā)生前丟棄。
tcsendbreak() 傳送連續(xù)的 0 值比特流,持續(xù)一段時(shí)間,如果終端使用異步串行數(shù)據(jù)傳輸?shù)脑挕H绻?duration 是 0,它至少傳輸 0.25 秒,不會(huì)超過 0.5 秒。如果 duration 非零,它發(fā)送的時(shí)間長度由實(shí)現(xiàn)定義。
如果終端并非使用異步串行數(shù)據(jù)傳輸,tcsendbreak() 什么都不做。
tcdrain() 等待直到所有寫入 fd 引用的對象的輸出都被傳輸。
tcflush() 丟棄要寫入 引用的對象,但是尚未傳輸?shù)臄?shù)據(jù),或者收到但是尚未讀取的數(shù)據(jù),取決于 queue_selector 的值:
- TCIFLUSH
- 刷新收到的數(shù)據(jù)但是不讀
- TCOFLUSH
- 刷新寫入的數(shù)據(jù)但是不傳送
- TCIOFLUSH
- 同時(shí)刷新收到的數(shù)據(jù)但是不讀,并且刷新寫入的數(shù)據(jù)但是不傳送
tcflow() 掛起 fd 引用的對象上的數(shù)據(jù)傳輸或接收,取決于 action 的值:
- TCOOFF
- 掛起輸出
- TCOON
- 重新開始被掛起的輸出
- TCIOFF
- 發(fā)送一個(gè) STOP 字符,停止終端設(shè)備向系統(tǒng)傳送數(shù)據(jù)
- TCION
- 發(fā)送一個(gè) START 字符,使終端設(shè)備向系統(tǒng)傳輸數(shù)據(jù)
打開一個(gè)終端設(shè)備時(shí)的默認(rèn)設(shè)置是輸入和輸出都沒有掛起。
波特率函數(shù)被用來獲取和設(shè)置 termios 結(jié)構(gòu)中,輸入和輸出波特率的值。新值不會(huì)馬上生效,直到成功調(diào)用了 tcsetattr() 函數(shù)。
設(shè)置速度為 B0 使得 modem "掛機(jī)"。與 B38400 相應(yīng)的實(shí)際比特率可以用 setserial(8) 調(diào)整。
輸入和輸出波特率被保存于 termios 結(jié)構(gòu)中。
cfmakeraw 設(shè)置終端屬性如下:
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON); termios_p->c_oflag &= ~OPOST; termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); termios_p->c_cflag &= ~(CSIZE|PARENB); termios_p->c_cflag |= CS8;
cfgetospeed() 返回 termios_p 指向的 termios 結(jié)構(gòu)中存儲的輸出波特率
cfsetospeed() 設(shè)置 termios_p 指向的 termios 結(jié)構(gòu)中存儲的輸出波特率為 speed。取值必須是以下常量之一:
B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 B38400 B57600 B115200 B230400
零值 B0 用來中斷連接。如果指定了 B0,不應(yīng)當(dāng)再假定存在連接。通常,這樣將斷開連接。CBAUDEX 是一個(gè)掩碼,指示高于 POSIX.1 定義的速度的那一些 (57600 及以上)。因此,B57600 & CBAUDEX 為非零。
cfgetispeed() 返回 termios 結(jié)構(gòu)中存儲的輸入波特率。
cfsetispeed() 設(shè)置 termios 結(jié)構(gòu)中存儲的輸入波特率為 speed。如果輸入波特率被設(shè)為0,實(shí)際輸入波特率將等于輸出波特率。
RETURN VALUE 返回值
cfgetispeed() 返回 termios 結(jié)構(gòu)中存儲的輸入波特率。
cfgetospeed() 返回 termios 結(jié)構(gòu)中存儲的輸出波特率。
其他函數(shù)返回:
- 0
- 成功
- -1
- 失敗,并且為 errno 置值來指示錯(cuò)誤。
注意 tcsetattr() 返回成功,如果任何所要求的修改可以實(shí)現(xiàn)的話。因此,當(dāng)進(jìn)行多重修改時(shí),應(yīng)當(dāng)在這個(gè)函數(shù)之后再次調(diào)用 tcgetattr() 來檢測是否所有修改都成功實(shí)現(xiàn)。
NOTES 注意
Unix V7 以及很多后來的系統(tǒng)有一個(gè)波特率的列表,在十四個(gè)值 B0, ..., B9600 之后可以看到兩個(gè)常數(shù) EXTA, EXTB ("External A" and "External B")。很多系統(tǒng)將這個(gè)列表擴(kuò)展為更高的波特率。
tcsendbreak 中非零的 duration 有不同的效果。SunOS 指定中斷 duration*N 秒,其中 N 至少為 0.25,不高于 0.5 。Linux, AIX, DU, Tru64 發(fā)送 duration 微秒的 break 。FreeBSD, NetBSD, HP-UX 以及 MacOS 忽略 duration 的值。在 Solaris 和 Unixware 中, tcsendbreak 搭配非零的 duration 效果類似于 tcdrain。
SEE ALSO 參見
stty(1), setserial(8)
#p#
NAME
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed - get and set terminal attributes, line control, get and set baud rate
SYNOPSIS
#include <termios.h>
#include <unistd.h> fd, struct termios *termios_p);
int tcgetattr(int
int tcsetattr(int fd, int optional_actions, struct termios *termios_p);
int tcsendbreak(int fd, int duration);
int tcdrain(int fd);
int tcflush(int fd, int queue_selector);
int tcflow(int fd, int action);
int cfmakeraw(struct termios *termios_p);
speed_t cfgetispeed(struct termios *termios_p);
speed_t cfgetospeed(struct termios *termios_p);
int cfsetispeed(struct termios *termios_p, speed_t speed);
int cfsetospeed(struct termios *termios_p, speed_t speed);
DESCRIPTION
The termios functions describe a general terminal interface that is provided to control asynchronous communications ports.
Many of the functions described here have a termios_p argument that is a pointer to a termios structure. This structure contains at least the following members:
-
tcflag_t c_iflag; /* input modes */ tcflag_t c_oflag; /* output modes */ tcflag_t c_cflag; /* control modes */ tcflag_t c_lflag; /* local modes */ cc_t c_cc[NCCS]; /* control chars */
c_iflag flag constants:
- IGNBRK
- Ignore BREAK condition on input.
- BRKINT
- If IGNBRK is set, a BREAK is ignored. If it is not set but BRKINT is set, then a BREAK causes the input and output queues to be flushed, and if the terminal is the controlling terminal of a foreground process group, it will cause a SIGINT to be sent to this foreground process group. When neither IGNBRK nor BRKINT are set, a BREAK reads as a NUL character, except when PARMRK is set, in which case it reads as the sequence \377 \0 \0.
- IGNPAR
- Ignore framing errors and parity errors.
- PARMRK
- If IGNPAR is not set, prefix a character with a parity error or framing error with \377 \0. If neither IGNPAR nor PARMRK is set, read a character with a parity error or framing error as \0.
- INPCK
- Enable input parity checking.
- ISTRIP
- Strip off eighth bit.
- INLCR
- Translate NL to CR on input.
- IGNCR
- Ignore carriage return on input.
- ICRNL
- Translate carriage return to newline on input (unless IGNCR is set).
- IUCLC
- (not in POSIX) Map uppercase characters to lowercase on input.
- IXON
- Enable XON/XOFF flow control on output.
- IXANY
- (not in POSIX.1; XSI) Enable any character to restart output.
- IXOFF
- Enable XON/XOFF flow control on input.
- IMAXBEL
- (not in POSIX) Ring bell when input queue is full. Linux does not implement this bit, and acts as if it is always set.
c_oflag flag constants defined in POSIX.1:
- OPOST
- Enable implementation-defined output processing.
The remaining c_oflag flag constants are defined in POSIX 1003.1-2001, unless marked otherwise.
- OLCUC
- (not in POSIX) Map lowercase characters to uppercase on output.
- ONLCR
- (XSI) Map NL to CR-NL on output.
- OCRNL
- Map CR to NL on output.
- ONOCR
- Don't output CR at column 0.
- ONLRET
- Don't output CR.
- OFILL
- Send fill characters for a delay, rather than using a timed delay.
- OFDEL
- (not in POSIX) Fill character is ASCII DEL (0177). If unset, fill character is ASCII NUL.
- NLDLY
- Newline delay mask. Values are NL0 and NL1.
- CRDLY
- Carriage return delay mask. Values are CR0, CR1, CR2, or CR3.
- TABDLY
- Horizontal tab delay mask. Values are TAB0, TAB1, TAB2, TAB3 (or XTABS). A value of TAB3, that is, XTABS, expands tabs to spaces (with tab stops every eight columns).
- BSDLY
- Backspace delay mask. Values are BS0 or BS1. (Has never been implemented.)
- VTDLY
- Vertical tab delay mask. Values are VT0 or VT1.
- FFDLY
- Form feed delay mask. Values are FF0 or FF1.
c_cflag flag constants:
- CBAUD
- (not in POSIX) Baud speed mask (4+1 bits).
- CBAUDEX
- (not in POSIX) Extra baud speed mask (1 bit), included in CBAUD.
(POSIX says that the baud speed is stored in the termios structure without specifying where precisely, and provides cfgetispeed() and cfsetispeed() for getting at it. Some systems use bits selected by CBAUD in c_cflag, other systems use separate fields, e.g. sg_ispeed and sg_ospeed.)
- CSIZE
- Character size mask. Values are CS5, CS6, CS7, or CS8.
- CSTOPB
- Set two stop bits, rather than one.
- CREAD
- Enable receiver.
- PARENB
- Enable parity generation on output and parity checking for input.
- PARODD
- Parity for input and output is odd.
- HUPCL
- Lower modem control lines after last process closes the device (hang up).
- CLOCAL
- Ignore modem control lines.
- LOBLK
- (not in POSIX) Block output from a noncurrent shell layer. (For use by shl.)
- CIBAUD
- (not in POSIX) Mask for input speeds. The values for the CIBAUD bits are the same as the values for the CBAUD bits, shifted left IBSHIFT bits.
- CRTSCTS
- (not in POSIX) Enable RTS/CTS (hardware) flow control.
c_lflag flag constants:
- ISIG
- When any of the characters INTR, QUIT, SUSP, or DSUSP are received, generate the corresponding signal.
- ICANON
- Enable canonical mode. This enables the special characters EOF, EOL, EOL2, ERASE, KILL, LNEXT, REPRINT, STATUS, and WERASE, and buffers by lines.
- XCASE
- (not in POSIX; not supported under Linux) If ICANON is also set, terminal is uppercase only. Input is converted to lowercase, except for characters preceded by \. On output, uppercase characters are preceded by \ and lowercase characters are converted to uppercase.
- ECHO
- Echo input characters.
- ECHOE
- If ICANON is also set, the ERASE character erases the preceding input character, and WERASE erases the preceding word.
- ECHOK
- If ICANON is also set, the KILL character erases the current line.
- ECHONL
- If ICANON is also set, echo the NL character even if ECHO is not set.
- ECHOCTL
- (not in POSIX) If ECHO is also set, ASCII control signals other than TAB, NL, START, and STOP are echoed as ^X, where X is the character with ASCII code 0x40 greater than the control signal. For example, character 0x08 (BS) is echoed as ^H.
- ECHOPRT
- (not in POSIX) If ICANON and IECHO are also set, characters are printed as they are being erased.
- ECHOKE
- (not in POSIX) If ICANON is also set, KILL is echoed by erasing each character on the line, as specified by ECHOE and ECHOPRT.
- DEFECHO
- (not in POSIX) Echo only when a process is reading.
- FLUSHO
- (not in POSIX; not supported under Linux) Output is being flushed. This flag is toggled by typing the DISCARD character.
- NOFLSH
- Disable flushing the input and output queues when generating the SIGINT, SIGQUIT and SIGSUSP signals.
- TOSTOP
- Send the SIGTTOU signal to the process group of a background process which tries to write to its controlling terminal.
- PENDIN
- (not in POSIX; not supported under Linux) All characters in the input queue are reprinted when the next character is read. (bash handles typeahead this way.)
- IEXTEN
- Enable implementation-defined input processing. This flag, as well as ICANON must be enabled for the special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted, and for the IUCLC flag to be effective.
The c_cc array defines the special control characters. The symbolic indices (initial values) and meaning are:
- VINTR
- (003, ETX, Ctrl-C, or also 0177, DEL, rubout) Interrupt character. Send a SIGINT signal. Recognized when ISIG is set, and then not passed as input.
- VQUIT
- (034, FS, Ctrl-\) Quit character. Send SIGQUIT signal. Recognized when ISIG is set, and then not passed as input.
- VERASE
- (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #) Erase character. This erases the previous not-yet-erased character, but does not erase past EOF or beginning-of-line. Recognized when ICANON is set, and then not passed as input.
- VKILL
- (025, NAK, Ctrl-U, or Ctrl-X, or also @) Kill character. This erases the input since the last EOF or beginning-of-line. Recognized when ICANON is set, and then not passed as input.
- VEOF
- (004, EOT, Ctrl-D) End-of-file character. More precisely: this character causes the pending tty buffer to be sent to the waiting user program without waiting for end-of-line. If it is the first character of the line, the read() in the user program returns 0, which signifies end-of-file. Recognized when ICANON is set, and then not passed as input.
- VMIN
- Minimum number of characters for non-canonical read.
- VEOL
- (0, NUL) Additional end-of-line character. Recognized when ICANON is set.
- VTIME
- Timeout in deciseconds for non-canonical read.
- VEOL2
- (not in POSIX; 0, NUL) Yet another end-of-line character. Recognized when ICANON is set.
- VSWTCH
- (not in POSIX; not supported under Linux; 0, NUL) Switch character. (Used by shl only.)
- VSTART
- (021, DC1, Ctrl-Q) Start character. Restarts output stopped by the Stop character. Recognized when IXON is set, and then not passed as input.
- VSTOP
- (023, DC3, Ctrl-S) Stop character. Stop output until Start character typed. Recognized when IXON is set, and then not passed as input.
- VSUSP
- (032, SUB, Ctrl-Z) Suspend character. Send SIGTSTP signal. Recognized when ISIG is set, and then not passed as input.
- VDSUSP
- (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y) Delayed suspend character: send SIGTSTP signal when the character is read by the user program. Recognized when IEXTEN and ISIG are set, and the system supports job control, and then not passed as input.
- VLNEXT
- (not in POSIX; 026, SYN, Ctrl-V) Literal next. Quotes the next input character, depriving it of a possible special meaning. Recognized when IEXTEN is set, and then not passed as input.
- VWERASE
- (not in POSIX; 027, ETB, Ctrl-W) Word erase. Recognized when ICANON and IEXTEN are set, and then not passed as input.
- VREPRINT
- (not in POSIX; 022, DC2, Ctrl-R) Reprint unread characters. Recognized when ICANON and IEXTEN are set, and then not passed as input.
- VDISCARD
- (not in POSIX; not supported under Linux; 017, SI, Ctrl-O) Toggle: start/stop discarding pending output. Recognized when IEXTEN is set, and then not passed as input.
- VSTATUS
- (not in POSIX; not supported under Linux; status request: 024, DC4, Ctrl-T).
These symbolic subscript values are all different, except that VTIME, VMIN may have the same value as VEOL, VEOF, respectively. (In non-canonical mode the special character meaning is replaced by the timeout meaning. MIN represents the minimum number of characters that should be received to satisfy the read. TIME is a decisecond-valued timer. When both are set, a read will wait until at least one character has been received, and then return as soon as either MIN characters have been received or time TIME has passed since the last character was received. If only MIN is set, the read will not return before MIN characters have been received. If only TIME is set, the read will return as soon as either at least one character has been received, or the timer times out. If neither is set, the read will return immediately, only giving the currently already available characters.)
tcgetattr() gets the parameters associated with the object referred by fd and stores them in the termios structure referenced by termios_p. This function may be invoked from a background process; however, the terminal attributes may be subsequently changed by a foreground process.
tcsetattr() sets the parameters associated with the terminal (unless support is required from the underlying hardware that is not available) from the termios structure referred to by termios_p. optional_actions specifies when the changes take effect:
- TCSANOW
- the change occurs immediately.
- TCSADRAIN
- the change occurs after all output written to fd has been transmitted. This function should be used when changing parameters that affect output.
- TCSAFLUSH
- the change occurs after all output written to the object referred by fd has been transmitted, and all input that has been received but not read will be discarded before the change is made.
tcsendbreak() transmits a continuous stream of zero-valued bits for a specific duration, if the terminal is using asynchronous serial data transmission. If duration is zero, it transmits zero-valued bits for at least 0.25 seconds, and not more that 0.5 seconds. If duration is not zero, it sends zero-valued bits for some implementation-defined length of time.
If the terminal is not using asynchronous serial data transmission, tcsendbreak() returns without taking any action.
tcdrain() waits until all output written to the object referred to by fd has been transmitted.
tcflush() discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of queue_selector:
- TCIFLUSH
- flushes data received but not read.
- TCOFLUSH
- flushes data written but not transmitted.
- TCIOFLUSH
- flushes both data received but not read, and data written but not transmitted.
tcflow() suspends transmission or reception of data on the object referred to by fd, depending on the value of action:
- TCOOFF
- suspends output.
- TCOON
- restarts suspended output.
- TCIOFF
- transmits a STOP character, which stops the terminal device from transmitting data to the system.
- TCION
- transmits a START character, which starts the terminal device transmitting data to the system.
The default on open of a terminal file is that neither its input nor its output is suspended.
The baud rate functions are provided for getting and setting the values of the input and output baud rates in the termios structure. The new values do not take effect until tcsetattr() is successfully called.
Setting the speed to B0 instructs the modem to "hang up". The actual bit rate corresponding to B38400 may be altered with setserial(8).
The input and output baud rates are stored in the termios structure.
cfmakeraw sets the terminal attributes as follows:
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON); termios_p->c_oflag &= ~OPOST; termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); termios_p->c_cflag &= ~(CSIZE|PARENB); termios_p->c_cflag |= CS8;
cfgetospeed() returns the output baud rate stored in the termios structure pointed to by termios_p.
cfsetospeed() sets the output baud rate stored in the termios structure pointed to by termios_p to speed, which must be one of these constants:
B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 B38400 B57600 B115200 B230400
The zero baud rate, B0, is used to terminate the connection. If B0 is specified, the modem control lines shall no longer be asserted. Normally, this will disconnect the line. CBAUDEX is a mask for the speeds beyond those defined in POSIX.1 (57600 and above). Thus, B57600 & CBAUDEX is nonzero.
cfgetispeed() returns the input baud rate stored in the termios structure.
cfsetispeed() sets the input baud rate stored in the termios structure to speed. If the input baud rate is set to zero, the input baud rate will be equal to the output baud rate.
RETURN VALUE
cfgetispeed() returns the input baud rate stored in the termios structure.
cfgetospeed() returns the output baud rate stored in the termios structure.
All other functions return:
- 0
- on success.
- -1
- on failure and set errno to indicate the error.
Note that tcsetattr() returns success if any of the requested changes could be successfully carried out. Therefore, when making multiple changes it may be necessary to follow this call with a further call to tcgetattr() to check that all changes have been performed successfully.
NOTES
Unix V7 and several later systems have a list of baud rates where after the fourteen values B0, ..., B9600 one finds the two constants EXTA, EXTB ("External A" and "External B"). Many systems extend the list with much higher baud rates.
The effect of a nonzero duration with tcsendbreak varies. SunOS specifies a break of duration*N seconds, where N is at least 0.25, and not more than 0.5. Linux, AIX, DU, Tru64 send a break of duration milliseconds. FreeBSD and NetBSD and HP-UX and MacOS ignore the value of duration. Under Solaris and Unixware, tcsendbreak with nonzero duration behaves like tcdrain.
SEE ALSO
stty(1), setserial(8)