/*
Low Level I/O - Read and Write
Chapter 8 - The C Programming Language - K&R
Header file in the original code is "syscalls.h"
Also BUFSIZ is supposed to be defined in the same header file
*/
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#define BUFSIZ 1
int main() /* copy input to output */
{
char buf[BUFSIZ];
int n;
while ((n = read(0, buf, BUFSIZ)) > 0)
write(1, buf, n);
return 0;
}
当我输入“∂ΣΣ®†¥¥¥˚πΔ~~∫∫√tu tu 886661〜EOF”作为输入时,复制相同的内容。 如此多的非ASCII字符被同时存储?unix读取和写入功能
BUFSIZ是要传输的字节数。 BUFSIZ如何限制字节传输如果对于任何值,任何东西都可以从输入复制到输出?
char buf [BUFSIZ]如何存储非ASCII字符?
今天的非ASCII字符通常编码为UTF-8,所以一个字符可以被设置为高位的*多个*字节编码。 – 2012-07-29 07:47:01
通常,BUFSIZ在''中定义,通常是512以上的两个幂。在这种情况下,将其定义为1是合法的(但不寻常)。您显示的代码不需要''或''; ''就足够了。 –
2012-07-29 08:55:56