mycp命令,在linux上用代码实现cp命令,只能实现普通文件的cp命令,不能实现多个文件的同时cp

#include<stdio.h> 
#include<fcntl.h>
#include<stdlib.h> 
#include<string.h> 
#include<unistd.h> 
#include<assert.h>  
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; 
}

猜你喜欢

转载自blog.csdn.net/obitosbb/article/details/90677710