Exemplo n.º 1
0
void		*malloc(size_t size)
{
	void	*ptr;

	size = 0 ? 1 : size;
	if (!g_map.tiny && !g_map.small && !g_map.large)
		init_glob();
	if (size + sizeof(t_header) > g_map.max_size || size > g_map.max_size)
		return (NULL);
	size += sizeof(t_block);
	if (size - sizeof(t_block) <= g_map.size_tiny)
	{
		if (!g_map.tiny && new_map(g_map.size_tiny, &g_map.tiny, NULL) < 0)
			return (NULL);
		ptr = find_free_space(g_map.size_tiny, size, &g_map.tiny);
	}
	else if (size - sizeof(t_block) <= g_map.size_small)
	{
		if (!g_map.small && new_map(g_map.size_small, &g_map.small, NULL) < 0)
			return (NULL);
		ptr = find_free_space(g_map.size_small, size, &g_map.small);
	}
	else
		ptr = large_alloc(size, &g_map.large);
	if (ptr)
		ptr = (void *)ptr + sizeof(t_block);
	return (ptr);
}
Exemplo n.º 2
0
Arquivo: init.c Projeto: GhaisB/42sh
t_glob		*init(int ac, char **av, char **envp)
{
  t_glob	*glob;

  ac = ac;
  av = av;
  glob = xmalloc(sizeof(t_glob));
  if (glob)
    {
      init_glob(glob);
      if (!init_env(glob, envp))
	return (NULL);
      if (!init_history(glob))
	return (NULL);
      if (!init_builtins(glob))
	return (NULL);
      glob->var = NULL;
      init_config(glob);
    }
  return (glob);
}