标签:stat include open write int fine printf pass bsp
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> #define BUFSIZE 1024 /* ./mycp /etc/passwd /home/passwd diff /etc/passwd /home/passwd */ void copyfile(const char *s,const char *d) { int fd1,fd2,rnum,wnum; char buf[BUFSIZE]; fd1 = open(s,O_RDONLY); //if(fd1 == -1)......... fd2 = open(d,O_WRONLY|O_CREAT|O_TRUNC,0644); //if(fd2 == -1)........ while((rnum = read(fd1,buf,BUFSIZE))>0) { wnum = write(fd2,buf,rnum); if(wnum!=rnum) printf("write num less than rnum\n"); } close(fd1); close(fd2); } int main(int argc,char**argv) { if(argc != 3) { printf("arg num error\n"); exit(1); } copyfile(argv[1],argv[2]); exit(0); }
标签:stat include open write int fine printf pass bsp
原文地址:http://www.cnblogs.com/yege/p/7920338.html