日期:2014-05-16 浏览次数:20877 次
 1 #include<stdio.h>
  2 #include<unistd.h>
  3 #include<sys/types.h>
  4 #include<sys/stat.h>
  5 #include<fcntl.h>
  6 #include<string.h>
  7 #include<stdlib.h>
  8 
  9 int main(int argc,char **argv){
 10 
 11     char *oldpath = argv[1];
 12     char *newpath = argv[2];
 13     char *output = argv[3];
 14     char buf[1024];
 15     int n;
 16 
 17     if(symlink(oldpath,newpath) < 0){
 18         perror("symlink");exit(-1);
 19     }
 20 
 21     int fdin = open(newpath,O_RDONLY);
 22     int fdout = open(output,O_WRONLY|O_CREAT);
 23     if(fdin < 0 || fdout < 0){
 24         perror("open");exit(-1);
 25     }
 26     while((n = read(fdin,buf,sizeof(buf))) > 0){
 27         write(fdout,buf,n);
 28         bzero(buf,sizeof(buf));
 29     }
 30     return 0;
 31 
 32 }
~