#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "rs_timer.h"
void blad(char * fmt,...)
{
  va_list ap;
  va_start(ap,fmt);
  vfprintf(stderr,fmt,ap);
  va_end(ap);
  exit(1);
}

int f=-1; //Deskryptor pliku urządzenia

void main(int argc, char * argv[])
{
  int div=0;
  if(argc < 2)  blad("Prawidłowe wywołanie: rs_test plik_specjalny dzielnik\n");
  f = open(argv[1],O_RDONLY);
  div=atoi(argv[2]);
  if(f<0) blad("Nie mogę otworzyć pliku: %s\n",argv[1]);
  div=atoi(argv[2]);
  if(ioctl(f,IOCTL_SET_DIV,(long) div)<0) {
    perror("Błąd IOCTL:");
    exit(1);
  }
  while(1) {
    unsigned char c;
    read(f,&c,1);
    printf("Odczytałem: %d\n",(int) c);
  }
}
