read(2) 是 C89 规范的一部分吗?

Is read(2) part of the C89 specification?

我对 C 有点陌生。我想知道,read(2) 函数是 C89 规范的一部分,还是只是 POSIX 一个?我问是因为我试图找出 read 的 return 类型,here say it's ssize_t. However, ssize_t is only required in POSIX, not regular C according to this question. This MSDN page 等地方的手册页似乎证实了我的怀疑,因为它说

This POSIX function is deprecated. Use the ISO C++ conformant _read instead.

我拿到了 draft of the C89 standard, and there is no mention of read in the table of contents. There is, however, a mention of fread: http://port70.net/~nsz/c/c89/c89-draft.html#4.9.8.1

那么使用例如从标准输入读取 fread(buf, 1, sizeof(buf), stdin) 而不是 read(STDIN_FILENO, buf, sizeof(buf))

编辑: 抱歉造成混淆。我没有引用 MSDN 来暗示 read 已被弃用,只是为了表明它确实是 POSIX 标准的一部分(它提到 "POSIX function")而不是 C 标准。

read() 不是也从来不是标准 C,所以如果你想编写从文件读取的可移植代码,请不要使用它;使用 fread().

另一方面,您可能希望在 Posix 系统上执行一些不可移植的操作,例如使用管道和套接字。在这种情况下,请继续使用 Posix 接口。