POSIX 是否定义了向终端发送 NUL 时的行为?
Does POSIX define the behavior when sending NUL to terminal?
这是一个将 ASCII NUL 作为输出发送的 Perl 程序:
print "hello[=11=]world"
下面是如何 运行 来自 sh
或 bash
的程序:
perl -e 'print "hello[=12=]world"'
在 Mac OS X 10.11.2 上,这会产生可见输出:
helloworld
但是,对于所有 POSIX 兼容的终端仿真器,这种行为是否一致? (例如,与将 NUL 打印为新行或崩溃相反?)
不,这不能保证;正如 chepner 在对该问题的评论中指出的那样,POSIX 规范没有定义终端仿真器的行为。 确实存在一种标准终端协议,ECMA-48,但现代操作系统一致支持标准定义的终端协议之外的多种终端协议。
一些终端打印本地字体为代码点提供的任何字符(并且U+0000
是一个有效的代码点)。
顺便说一句,ECMA-48 终端标准(用于 ANSI 终端——同样,并非所有终端都需要 符合 ANSI)关于 NUL 的说明如下字符:
8.3.88 NUL - NULL
Notation: (C0)
Representation: 00/00
NUL is used for media-fill or time-fill. NUL characters may be inserted into, or removed from, a data
stream without affecting the information content of that stream, but such action may affect the
information layout and/or the control of equipment.
因此,对于 ANSI 终端,为 NUL 打印空白 space 是符合标准的操作(允许 NUL 用于填充缓冲区而无需修改内容),但不要求不符合 ECMA-48 的终端类型以相同方式运行。
这是一个将 ASCII NUL 作为输出发送的 Perl 程序:
print "hello[=11=]world"
下面是如何 运行 来自 sh
或 bash
的程序:
perl -e 'print "hello[=12=]world"'
在 Mac OS X 10.11.2 上,这会产生可见输出:
helloworld
但是,对于所有 POSIX 兼容的终端仿真器,这种行为是否一致? (例如,与将 NUL 打印为新行或崩溃相反?)
不,这不能保证;正如 chepner 在对该问题的评论中指出的那样,POSIX 规范没有定义终端仿真器的行为。 确实存在一种标准终端协议,ECMA-48,但现代操作系统一致支持标准定义的终端协议之外的多种终端协议。
一些终端打印本地字体为代码点提供的任何字符(并且U+0000
是一个有效的代码点)。
顺便说一句,ECMA-48 终端标准(用于 ANSI 终端——同样,并非所有终端都需要 符合 ANSI)关于 NUL 的说明如下字符:
8.3.88 NUL - NULL
Notation: (C0) Representation: 00/00NUL is used for media-fill or time-fill. NUL characters may be inserted into, or removed from, a data stream without affecting the information content of that stream, but such action may affect the information layout and/or the control of equipment.
因此,对于 ANSI 终端,为 NUL 打印空白 space 是符合标准的操作(允许 NUL 用于填充缓冲区而无需修改内容),但不要求不符合 ECMA-48 的终端类型以相同方式运行。