open-read-write--copy.c
2018-12-22 本文已影响10人
半步江南
include <unistd.h>
include <sys/stat.h>
include <stdlib.h>
include <fcntl.h>
include <stdio.h>
int main(){
char buffer[11];
int nread=1,nwrite=0;
int in,out;
//char * path;
//int i,flag;
char path1[]="/root/study-dir/linux_program_design/chapter_3/read.c";
char path2[]="/root/study-dir/linux_program_design/chapter_3/test.out";
in = open(path1,O_RDONLY);
out = open(path2,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);
while(nread!=0)
{
nread=read(in,buffer,11);
nwrite=write(out,buffer,nread);
}
exit(0);
}