mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-04-14 18:30:28 +08:00
完成了第 15 章 套接字和标准I/O
This commit is contained in:
21
ch15/syscpy.c
Normal file
21
ch15/syscpy.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#define BUF_SIZE 3
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd1, fd2;
|
||||
int len;
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
fd1 = open("news.txt", O_RDONLY);
|
||||
fd2 = open("cpy.txt", O_WRONLY | O_CREAT | O_TRUNC);
|
||||
|
||||
while ((len = read(fd1, buf, sizeof(buf))) > 0)
|
||||
write(fd2, buf, len);
|
||||
|
||||
close(fd1);
|
||||
close(fd2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user