代码:
#include <stdio.h> #include <sys/fcntl.h> #include <sys/syscall.h> #define PERMS 0666
main(int argc,char **argv) { int f1,f2,n; char buf[BUFSIZ];
if (argc!=3) printf("usage: cp from to,\n"); if ((f1=open(argv[1],O_RDONLY,0))==-1) printf("cant open the file:%s \n",argv[1]); if ((f2=creat(argv[2],PERMS))==-1) printf("cant create the file %s ,mode %s \n",argv[2],PERMS); while ((n=read(f1,buf,BUFSIZ))>0) if (write (f2,buf,n)!=n) printf("write file %s error \n",argv[2]); return 0; }
大家可以把PERMS换成从目录获取。定义error,把printf换掉。 ENV:freebsd4.7+vmware+windows2000
|