Target::Target(const char* src_filename)
: fd_dst(-1), fd_src(-1)
{
  const char* base = strrchr(src_filename, '/');
  std::string dst_filename((base == 0) ? src_filename : base + 1);
  dst_filename += "_infected";

  fd_src = open(src_filename, O_RDONLY);
  if (fd_src >= 0)
  {
    filesize = lseek(fd_src, 0, SEEK_END);
    if ((off_t)-1 != filesize)
    {
      aligned_filesize = alignUp(filesize);
      p.v = mmap(0, filesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd_src, 0);
      if (MAP_FAILED != p.v)
      {
        fd_dst = open(dst_filename.c_str(),
	  O_WRONLY | O_CREAT | O_TRUNC, 0775);
	if (fd_dst >= 0)
	  return;
	perror("open");
      }
      else
	perror("mmap");
    }
    else
      perror("lseek");
  }
  else
    perror("open");
}
