?? 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 + -