home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / goodies / mycopy / cpy.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  2KB  |  97 lines

  1. #include <string.h>
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include <clib/dos_protos.h>
  10. #include <clib/exec_protos.h>
  11.  
  12. #include <dos/stdio.h>
  13.  
  14. struct Library *DosBase = NULL;
  15. BPTR stdout;
  16.  
  17. LONG SizeOfFile( char *Name )
  18. {
  19.    BPTR                    lock;
  20.    struct FileInfoBlock   *InfoBlock;
  21.    LONG                    Size = 0L;
  22.  
  23.    if( InfoBlock = (struct FileInfoBlock *)
  24.                    AllocVec(sizeof(struct FileInfoBlock),MEMF_CLEAR) )
  25.    {
  26.       if( lock = Lock( (STRPTR)Name,ACCESS_READ ) )
  27.       {
  28.          if( Examine( lock,InfoBlock ) )
  29.             Size = InfoBlock->fib_Size;
  30.  
  31.          UnLock( lock );
  32.       }
  33.  
  34.       FreeVec( InfoBlock );
  35.    }
  36.  
  37.    return( Size );
  38. }
  39.  
  40. void
  41. main(int argc,char *argv[])
  42. {
  43.    BPTR out,in;
  44.    UBYTE *buffer;
  45.    long size, written;
  46.  
  47.    if(DosBase = OpenLibrary((STRPTR)"dos.library",37))
  48.    {
  49.       stdout = Output();
  50.  
  51.       if(argc == 3)
  52.       {
  53.          if(in = Open((UBYTE *)argv[1], MODE_OLDFILE))
  54.          {
  55.             if(out = Open((UBYTE *)argv[2], MODE_NEWFILE))
  56.             {
  57.                size = SizeOfFile(argv[1]);
  58.  
  59.                buffer = AllocVec(size+1,MEMF_CLEAR|MEMF_ANY);
  60.                if(buffer)
  61.                {
  62.                   if(Read(in,buffer,size) != (long)(-1))
  63.                   {
  64.                      if((written = Write(out,buffer,size)) == (long)(-1))
  65.                         PutStr((STRPTR)"Error while writing input file!\n");
  66.  
  67.                      if(written != size)
  68.                         PutStr((STRPTR)"File sizes differs!\n");
  69.                   }
  70.                   else
  71.                      PutStr((STRPTR)"Error while reading input file!\n");
  72.  
  73.                   FreeVec(buffer);
  74.  
  75.                   Printf((STRPTR)"File %s copied...\n",(ULONG)argv[1]);
  76.                }
  77.                else
  78.                   PutStr((STRPTR)"No memory available!\n");
  79.  
  80.                Close(out);
  81.             }
  82.             else
  83.                PutStr((STRPTR)"Can't open output file!\n");
  84.  
  85.             Close(in);
  86.          }
  87.          else
  88.             PutStr((STRPTR)"Can't open input file!\n");
  89.       }
  90.       else
  91.          Printf((STRPTR)"Call: %s <FROM-File> <TO-File>\n",(ULONG)argv[0]);
  92.  
  93.       CloseLibrary(DosBase);
  94.    }
  95. }
  96.  
  97.