/* 功能:从sour_file文件的offset偏移处开始
将count个字节数据复制到dest_file文件 */
int myfilecopy(const char *sour_file,
const char *dest_file, int offset, int count, int copy_mode)
{
int in_file, out_file;
int counter = 0;
char buff_unit;
if ((in_file = open(sour_file, O_RDONLY|O_NONBLOCK)) < 0)
{
printf("Function myfilecopy error in source file\n");
return -1;
}
if ((out_file = open(dest_file,
O_CREAT|O_RDWR|O_TRUNC|O_NONBLOCK, 0644)) < 0)
{
printf("Function myfilecopy error in destination file:");
return -1;
}
$ ./com_host
Input some words(enter 'quit' to exit):
Hello, Target!
Input some words(enter 'quit' to exit):
I'm host program!
Input some words(enter 'quit' to exit):
Byebye!
Input some words(enter 'quit' to exit):
quit /* 这个输入使双方的程序都结束*/
$ ./com_target
Input some words(enter 'quit' to exit):
Hello, Host!
Input some words(enter 'quit' to exit):
I'm target program!
Input some words(enter 'quit' to exit):
Byebye!