这里第 10 行 打印的是 buf 指针的大小吧?
我刚才试了一下,输入很长的串也可以,是不是因为它不检查越界什么的?
cat read_one.c
#include <unistd.h>
#include <stdio.h>
int main() {
ssize_t read(int fd, void *buffer, size_t count);
char buf[3];
printf("size: %d\n", sizeof(buf));
while (read(0, &buf, 1) != 0)
write(1, &buf, 1);
return 0;
}
size: 3
as;dlfkj;slakdjf;lksaj;lkjd;lkwejodijaskc;
as;dlfkj;slakdjf;lksaj;lkjd;lkwejodijaskc;
as;dlkfj;lkjg;sldkjg;lksdfvmkldsmvldskf;glkjsd;lkfjg;kerstj;lewrkj
as;dlkfj;lkjg;sldkjg;lksdfvmkldsmvldskf;glkjsd;lkfjg;kerstj;lewrkj
^C
|