【发布时间】:2019-07-04 18:34:20
【问题描述】:
既然'fd'没有返回,那以后怎么读/写呢?
例如:
void init(void)
{
....
(void) open("/dev/tty1",O_RDWR,0);
....
【问题讨论】:
-
系统会按顺序创建描述符。如果没有,则以
0开头。 -
linux 1.0 源代码,main.c。 mirrors.edge.kernel.org/pub/linux/kernel/Historic/old-versions
-
它不需要分配 FD,因为它知道这将是 FD 0,因为尚未打开任何其他内容。
-
请注意,在
open之前有(void)演员表。正常行为是使用函数open返回的整数值。 man7.org/linux/man-pages/man2/open.2.html