在以下代码段中,无论我输入多长时间(编辑:我正在复制并粘贴一个随机字符串),比如说一个包含 9998 个字符的字符串,read() 在 i = 4095 时停止。它声明它已读取在 EOF 字符中,但我的字符串没有 EOF 字符(例如,我尝试了一个 9998 'a's 的字符串)。返回值还表明 read() 没有错误。为什么 read() 只读取 4095 字节?
#include <unistd.h>
#include <stdio.h>
int main() {
char temp;
char buf[10000];
int i = 0;
while(read(STDIN_FILENO, &temp, 1) > 0) {
buf[i] = temp;
i++;
}
printf("%d\n", i);
}
编辑:为了澄清, read() 并没有从字面上说明它以 EOF 字符读取,每个https://linux.die.net/man/2/read read() 在经过 EOF 时返回 0。