#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char *argv[])
{
const char *r= argv[1];
const char *w= argv[2];
int rfp = open(r, O_RDONLY);
if ( rfp == -1) {
perror("Error opening ");
return 1;
}
int wfp = open(w, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (wfp == -1) {
perror("Error opening ");
return 1;
}
int a=dup(2);
int file=open("./err.txt",O_WRONLY | O_CREAT | O_TRUNC,0664);
dup(file,2);
while(1)
{
char str[200];
ssize_t res1= read (rfp,str, strlen(str));
ssize_t res2= write (wfp, str, res1);
if (res1 == 0) {
break;
}
perror("res2");
}
close(rfp);
close(wfp);
close(file);
return 0;
}
IOday3
最新推荐文章于 2024-07-29 23:42:35 发布