Example #1
0
int
main(int argc, char **argv)
{
    int fd;

    fd = open(fn, O_RDWR | O_CREAT | O_TRUNC, 0644);
    if (fd < 0)
	err(1, "open1");
    if (write(fd, "kaka", 4) != 4)
	errx(1, "write1");
    check_size(fn, 4, 1);
    if (close(fd) < 0)
	err(1, "close1");

    check_size(fn, 4, 0);

    fd = open(fn, O_RDWR | O_CREAT | O_TRUNC, 644);
    if (fd < 0)
	err(1, "open2");
    check_size(fn, 0, 1);
    if (write(fd, "kaka", 4) != 4)
	errx(1, "write2");
    check_size(fn, 4, 1);
    check_size_read(fd, 4);
    if (close(fd) < 0)
	err(1, "close2");
    check_size(fn, 4, 1);

    unlink(fn);

    return 0;
}
static int		load_file_in_arena(unsigned char *arena,
					   unsigned char *info_arena,
					   t_champions *champions)
{
  int			fd;
  int			s_read;
  char			buf;
  unsigned int		i;
  int			size;

  while (champions)
  {
    size = 0;
    i = champions->load_address;
    if (get_name_comment_champions(champions, &fd) == -1)
      return (-1);
    while ((s_read = read(fd, &buf, 1)) > 0 && ++size)
    {
      arena[i] = buf;
      if (check_place_arena(info_arena, champions->prog_number, &i) == -1)
	return (-1);
      (i == MEM_SIZE - 1) ? (i = 0) : (0);
    }
    if ((check_size_read(size, champions, fd, s_read)) == -1)
      return (-1);
    champions = champions->next;
  }
  return (0);
}