mycpコマンドは、linux上でコードでcpコマンドを実現し、普通のファイルのcpコマンドしか実現できず、複数のファイルを実現すると同時にcp
679 ワード
#include
#include
#include
#include
#include
#include
int main(int argc,char * argv[])
{
int fd1,fd2;
fd1 = open(argv[1],O_RDONLY);
if(fd1 == -1)
{
return -1;
}
fd2 = open(argv[2],O_WRONLY | O_CREAT | O_TRUNC,0600);
assert(fd2 != -1);
char buff[1024];
int n = read(fd1,buff,sizeof(buff));//while
assert( n != -1);
write(fd2,buff,n);
close(fd1);
close(fd2);
return 0;
}