Linux cp 指令代码编写
#include<stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char **argv)
{
int fdScr;
int fdDes;
char *readBuf = NULL;
if(argc != 3){
printf("pararm error\n");
exit(-1);
}
fdScr = open(argv[1],O_RDWR);
int size = lseek(fdScr,0,SEEK_END);
lseek(fdScr,0,SEEK_SET);
readBuf = (char *)malloc(sizeof(char)*size + 8);
int n_read = read(fdScr,readBuf,size);
fdDes = open(argv[2],O_RDWR|O_CREAT|O_TRUNC,0600);
int n_write = write(fdDes,readBuf,strlen(readBuf));
close(fdScr);
close(fdDes);
return 0;
}