![](https://img-blog.csdnimg.cn/direct/70c6a059855a4e2ca03b63edea076bb6.png)
int main(int argc, const char *argv[])
{
int retvald1=dup(2);
if(retvald1==-1){perror("retvald1:");return 1;}
int fd3=open("./err.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
if(fd3==-1){perror("fd3:");return 1;}
int retvald2=dup2(4,2);
if(retvald2==-1){perror("retvald2:");return 1;}
int fd1=open("./zuoye1.txt",O_RDONLY,0666);
if(fd1==-1){perror("fd1:");return 1;}
int fd2=open("./zuoye2.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
if(fd1==-1){perror("fd2:");return 1;}
char buf[10000]={0};
int retval1=read(fd1,buf,10000);
if(retval1==-1){perror("retval1:");return 1;}
int retval2=write(fd2,buf,10000);
if(retval2==-1){perror("retval2:");return 1;}
close(fd1);
close(fd2);
close(fd3);
return 0;
}
int main(int argc, const char *argv[])
{
struct stat buf={0};
stat(argv[1],&buf);
mode_t mode=buf.st_mode;
if((mode|S_IWUSR)==mode)
{chmod(argv[1],mode&~S_IWUSR);
system("ls -l");}
else
{chmod(argv[1],mode|S_IWUSR);
system("ls -l");}
return 0;
}