
#include "filedesc.h"

void FileDescState::SaveState ()
{
  if(fd==-1) cerr << "ERROR: FileDescState";
  (void) ioctl(fd, TIOCGETP,(char*)&original_params);
  (void) ioctl(fd, TIOCLGET,(char*)&original_mode);
  original_fcntl_fl = fcntl(fd,F_GETFL,NULL);
}
void FileDescState::RestoreState ()
{
  if(fd==-1) { cerr << "ERROR: FileDescStateR"; return; }
  (void) ioctl(fd, TIOCSETP, (char*)&original_params);
  (void) ioctl(fd, TIOCLSET, (char*)&original_mode);
  (void) fcntl(fd, F_SETFL, original_fcntl_fl);
}
void FileDescState::Param_add(int n)
{
  struct sgttyb params;
  (void) ioctl(fd, TIOCGETP, (char*)&params);
  params.sg_flags |= n;
  (void) ioctl(fd, TIOCSETP, (char*)&params);
}
void FileDescState::Param_remove(int n)
{
  struct sgttyb params;
  (void) ioctl(fd, TIOCGETP, (char*)&params);
  params.sg_flags &= ~n;
  (void) ioctl(fd, TIOCSETP, (char*)&params);
}


