📄 cp.c
字号:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <utime.h>
int
main(int argc, char **argv){
struct stat s, s1;
struct utimbuf times;
int oldfile;
int newfile;
size_t nbytes=65534;
ssize_t nbytes2;
char buff[65535];
if(stat(argv[1], &s)<0) err_sys("stat error");
oldfile=open(argv[1],O_RDONLY);
if(oldfile<0) err_sys("open file error");
newfile=open(argv[2], O_RDWR | O_CREAT | O_TRUNC , s.st_mode);
if(newfile<0) err_sys("creat new file error");
while(1){
nbytes2=read(oldfile,buff,nbytes);
if(nbytes2==0) break;
if(nbytes2<0) err_sys("read file error");
nbytes2=write(newfile,buff,nbytes2);
if(nbytes2<=0) err_sys("write file error");
}
close(oldfile);
close(newfile);
times.actime=s.st_atime;
times.modtime=s.st_mtime;
if(utime(argv[2],×)<0) err_sys("modify time error");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -