open、read write
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
int main(int argc,char *argv[]){
int fd = 0;
//fd = open("../demo01/source/main.cpp",O_RDONLY);
//fd = open("./test.c",O_WRONLY|O_CREAT|O_TRUNC,0644);//rw-r--r--
fd = open(argv[1],O_RDONLY);
int fdw;
fdw= open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0644);
if(-1 == fd){
printf("open failed");
printf("errno=%d,%s\n",errno,strerror(errno));
}
if(-1 == fdw){
printf("open failed");
}
//ssize_t read(int fd, void *buf, size_t count);
ssize_t nread;
char buff[1024];
while((nread = read(fd,buff,20))!=0){
write(fdw,buff,nread);
}
printf("%d,%d\n",fd,fdw);
close(fd);
close(fdw);
}