bool target_open(Target* t, const char* src_filename)
{
  static const char suffix[] = "_infected"; 

  const char* base;
  size_t len;
  char* dst_filename;

  TRACE(stderr, "target_open(%s)\n", src_filename);
  base = strrchr(src_filename, '/');
  base = (base == 0) ? src_filename : base + 1;

  len = strlen(base);
  dst_filename = malloc(len + sizeof(suffix));
  if (dst_filename == 0)
  {
    TRACE(stderr, "Out of memory allocating %d bytes.\n",
      len + sizeof(suffix));
    return false;
  }

  memcpy(dst_filename, base, len);
  memcpy(dst_filename + len, suffix, sizeof(suffix));

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