home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / internet / wsplug31.zip / SCOPY.C < prev    next >
Text File  |  1996-02-06  |  1KB  |  63 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <io.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include <sys\stat.h>
  8. #include <share.h>
  9.  
  10. extern int errno;
  11.  
  12. main(argc,argv)
  13. int argc;
  14. char **argv;
  15. { int hs,hd,more=1 ;
  16.   char buf[512]    ;
  17.  
  18.   if (argc < 3)
  19.   { printf("Missing arguments ... \n");
  20.     printf("scopy source_file target_file \n");
  21.     return(0);
  22.   }
  23.  
  24.   while(more)
  25.   {
  26.   hs = open(argv[1],O_BINARY|O_RDONLY);
  27.   if (hs == -1)
  28.     { if (errno != EACCES)
  29.       { printf("Unable to Open [errno=%d]%s...\n",errno,argv[1]);
  30.     return(0) ;
  31.       }
  32.       else printf("Scopy, File %s Permission Denied...\n",argv[1]);
  33.     }
  34.    else more=0;
  35.   }
  36.  
  37.   more=1;
  38.   while(more)
  39.   {
  40.   hd = sopen(argv[2],O_BINARY|O_RDWR|O_CREAT|O_TRUNC,SH_DENYRW,S_IREAD|S_IWRITE);
  41.   if (hd == -1)
  42.     { if (errno != EACCES)
  43.       { printf("Unable to Open [errno=%d]%s...\n",errno,argv[2]);
  44.     close(hs) ;
  45.     return(0) ;
  46.       }
  47.       else printf("File %s Permission Denied...\n",argv[1]);
  48.     }
  49.    else more=0;
  50.   }
  51.  
  52.   more = 1;
  53.   while(more)
  54.   { more= read(hs,buf,512) ;
  55.     if (more >0) more = write(hd,buf,more) ;
  56.   }
  57.   close(hs)  ;
  58.   close (hd) ;
  59.  
  60.  return(0);
  61. }
  62.  
  63.