【发布时间】:2013-07-31 09:03:33
【问题描述】:
在这里,我尝试使用 open read 和 write 系统调用将一个文件的内容复制到其他(unix)中,但由于某种原因,代码运行了无限时间...
我没有收到错误,所以如果你能帮助我!!
#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
#include<fcntl.h>
#include<stdlib.h>
#include<string.h>
int main(int args,char *ar[])
{
char *source=ar[1];
char *dest="def.txt";
char *buf=(char *)malloc(sizeof(char)*120);
int fd1,fd2;
fd1=open(source,O_CREAT,0744);
fd2=open(dest,O_CREAT,0744);
while(read(fd1,buf,120)!=-1)
{
printf("%s",buf);
//printf("Processing\n");
write(fd2,buf,120);
}
printf("Process Done");
close(fd1);
close(fd2);
}
提前谢谢...
【问题讨论】:
标签: c unix system-calls