home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d110 / pdc.lha / Pdc / examples / cp.c < prev    next >
C/C++ Source or Header  |  1987-10-28  |  1KB  |  51 lines

  1. #define NULL        0
  2. #define BUFLEN        1024
  3. #define MODE_NEWFILE    1006
  4. #define MODE_OLDFILE    1005
  5.  
  6. main(argc, argv)
  7. int argc;
  8. char **argv;
  9. {
  10.     /* Test AmigaDos File I/O */
  11.     int i;
  12.     long   fromfile, tofile;    /* Bptr from Open */
  13.     long   length;
  14.     char   buffer[BUFLEN];
  15.     char   *fromname, *toname;
  16.     extern long Open(), Read(), Write();
  17.  
  18.     if (argc != 3)
  19.        {
  20.          printf("Useage: Copy fromfile tofile");
  21.          exit(4);
  22.        }
  23.  
  24.     fromfile = Open(argv[1], MODE_OLDFILE);
  25.     printf("%s opened with result %ld\n", argv[1], fromfile);
  26.     if (fromfile == NULL )
  27.        {
  28.          printf("Can't open: %s\n", argv[1]);
  29.          exit(4);
  30.        }
  31.  
  32.     tofile = Open(argv[2], MODE_NEWFILE);
  33.     printf("%s opened with result %ld\n", argv[2], tofile);
  34.     if (tofile == NULL )
  35.        {
  36.          printf("Can't open: %s\n", argv[2]);
  37.          exit(4);
  38.        }
  39.  
  40.     length = Read( fromfile, buffer, BUFLEN );
  41.     while ( length > 0 )
  42.       {
  43.          Write( tofile, buffer, length);
  44.          length = Read( fromfile, buffer, BUFLEN );
  45.       }
  46.  
  47.     Close( fromfile);
  48.     Close( tofile );
  49.     exit(0);
  50. }
  51.