#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd1 = open("/home/cp/a.txt",O_RDONLY);
if(fd1 < 0)
{
perror("a open ");
exit(1);
}
void *buff = malloc(100);
int ret = read(fd1,buff,100);
if(ret < 0)
{
perror("read a");
exit(1);
}
int fd2 = open("/home/cp/cyuyan/cp.txt",O_WRONLY|O_TRUNC|O_CREAT,0644);
if(fd2 == -1)
{
perror("cp.txt open ");
exit(1);
}
ret = write(fd2,buff,ret);
if(ret < 0)
{
perror("write ");
exit(1);
}
if(buff)
{
free(buff);
buff = 0x0;
}
close(fd1);
close(fd2);
system("cat /home/cp/cyuyan/cp.txt");
return 0;
}