系统相关
首页 > 系统相关> > 使用c完成linux的cp功能

使用c完成linux的cp功能

作者:互联网

使用c完成linux的cp功能

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>

int main( int argc, char **argv){
        int fdSrc;
        int fdDes;
        char *readBuf = NULL;
        fdSrc = open(argv[1],O_RDWR);
        int size = lseek(fdSrc,0,SEEK_END);
        lseek(fdSrc,0,SEEK_SET);
        readBuf = (char *)malloc(sizeof(char)*size+8);
        read(fdSrc,readBuf,1024);
        fdDes = open(argv[2],O_RDWR|O_CREAT,0600);
        int n_write = write(fdDes,readBuf,strlen(readBuf));
        close(fdSrc);
        close(fdDes);
        return 0;
}

标签:功能,cp,fdSrc,int,char,fdDes,readBuf,linux,include
来源: https://blog.csdn.net/weixin_41679960/article/details/114845815