home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / r_la4_02 / copy2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-13  |  1.1 KB  |  38 lines

  1. /* COPY2.C - From page 467 of "Microsoft C Programming for      */
  2. /* the IBM" by Robert Lafore. This does the same as DOS,s       */
  3. /* COPY command.                                                */
  4. /****************************************************************/
  5.  
  6. #include "fcntl.h"            /*needed for oflags*/
  7. #include "types.h"            /*needed for stat.h*/
  8. #include "stat.h"             /*needed for pmode*/
  9. #define BUFSIZ 4096
  10. char buff[BUFSIZ];
  11.  
  12. main(argc, argv)
  13. int argc;
  14. char *argv[];
  15. {
  16. int inhandle, outhandle, bytes;
  17.  
  18.    if(argc != 3) {
  19.       printf("\nFormat: A>copy2 source.xxx dest.xxx");
  20.       exit();
  21.    }
  22.    if ((inhandle = open(argv[1], O_RDONLY | O_BINARY)) < 0) {
  23.       printf("\nCan't open file %s.", argv[1]);
  24.       exit();
  25.    }
  26.    if ((outhandle = open(argv[2],
  27.          O_CREAT | O_WRONLY | O_BINARY, S_IWRITE)) < 0) {
  28.       printf("\nCan't open file %s.", argv[2]);
  29.       exit();
  30.    }
  31.    while((bytes = read(inhandle, buff, BUFSIZ)) > 0)
  32.       write(outhandle, buff, bytes);
  33.    close(inhandle);
  34.    close(outhandle);
  35. }
  36.  
  37.  
  38.