/* priklad pr8_12.c kopirovanie so zadanim nazvov suborov cez parametre*/
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#define MAXB 512

void main(int argc, char *argv[])
{
  char buf[MAXB];
  int in,out,lng;

  if (argc == 1) printf("Volanie: %s file1 file2\n",argv[0]);
  else if (argc == 2)printf("Volanie: %s file1 file2\n",argv[0]);
  else
  {
    if((in=open(*++argv,O_RDONLY)) == -1)
    {
      printf("Can't open [%s]\n",*argv);
      exit();
    }
    if((out=open(*++argv,O_CREAT|O_RDWR,S_IWRITE)) == -1)
    {
      printf("Can't open [%s]\n",*argv);
      exit();
    }
    while((lng=read(in,buf,MAXB)) > 0) write(out,buf,lng);
    close(in);
    close(out);
  }
}