如果在从属端读取之前将终端设置更改为非规范模式,则Linux上的pty驱动程序似乎正在用NUL字节()替换VEOF字符(^D,\4)。\0tcsetattr(TCSANOW)
为什么会这样呢?它有任何道理还是仅仅是一个错误?
有什么办法可以避免呢?-除了在写任何东西之前等待主端从属端的输入之前,这是不实际的,因为在从属端可能还有另一个程序-将终端设置为原始模式的例程,在此我已对其进行了简化通常是任何具有行编辑功能的Shell所要做的。
虽然可以期望将其\r替换为\n(因为ICRNL已经应用了该标志),但我无法对那些无处不在的NUL字节做出任何理由。
下面的测试用例:它将foo\x00\x00\x00\x00在Linux foo\x04\x04\x04\x04上打印,但在* BSD和fooSolaris 上打印。
#define _XOPEN_SOURCE 600
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <termios.h>
#include <err.h>
#ifdef __sun
#include <stropts.h>
#define push_streams(fd)\
if(ioctl(fd, I_PUSH, "ptem")) err(1, "ioctl(I_PUSH, ptem)");\
if(ioctl(fd, I_PUSH, "ldterm")) err(1, "ioctl(I_PUSH, ldterm)");
#else
#define push_streams(sd) /* no need */
#endif
int main(void){
int mt, st; char *sname;
/* openpty()-like boilerplate */
if((mt …Run Code Online (Sandbox Code Playgroud)