/*
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