Esempio n. 1
0
void			*ft_realloc(void *ptr, size_t size)
{
	if (size <= 0)
	{
		ft_free(ptr);
		return (NULL);
	}
	else if (!ptr)
		return (ft_malloc(size));
	else
		return (search_realloc(ptr, size));
	return (NULL);
}
Esempio n. 2
0
t_tetri		*add_tetri(t_tetri *previous, t_id_piece id)
{
	t_tetri *tetri;

	tetri = ft_malloc(sizeof(t_tetri));
	tetri->id = id;
	previous->next = tetri;
	tetri->lettre = previous->lettre + 1;
	tetri->next = 0;
	tetri->position.x = 0;
	tetri->position.y = 0;
	return (tetri);
}
Esempio n. 3
0
t_array		*array_init(t_array *arr, size_t capacity,
							size_t size_type, t_flags flags)
{
	arr->size = 0;
	arr->capacity = capacity;
	arr->size_type = size_type;
	arr->it = 0;
	arr->flags = flags;
	arr->tab = (char *)ft_malloc(arr->size_change * capacity);
	if (flags & 1)
		ft_bzero(arr->tab, arr->size_change * capacity);
	return (arr);
}
Esempio n. 4
0
int			main(int argc, char *argv[])
{
	t_all		*all;

	all = ft_malloc(sizeof(t_all));
	frac_init(all, argc, argv);
	mlx_hook(all->env.win, 6, (1L << 6), mouse_move, all);
	mlx_key_hook(all->env.win, key_hook, all);
	mlx_mouse_hook(all->env.win, mouse_hook, all);
	mlx_loop_hook(all->env.mlx, loop_hook, all);
	mlx_expose_hook(all->env.win, expose_hook, all);
	mlx_loop(all->env.mlx);
	return (0);
}
Esempio n. 5
0
void *ft_memmove(void *dest, const void *src, unsigned int size)
{
  unsigned char	*s1;
  unsigned char	*s2;
  unsigned char	*s3;

  s1 = (unsigned char *)dest;
  s2 = (unsigned char *)src;
  s3 = (unsigned char *)ft_malloc (size * sizeof(unsigned char));
  ft_memcpy(s3, s2, size);
  ft_memcpy(s1, s3, size);

  return (dest);
}
Esempio n. 6
0
t_array	*array_resize(t_array *arr)
{
	void	*iarr;

	arr->capacity = arr->capacity_change != 0 ?
		arr->capacity + arr->capacity_change : arr->capacity * 2;
	iarr = ft_malloc(arr->size_type * arr->capacity);
	if (!iarr)
		return (NULL);
	ft_memcpy(iarr, arr->tab, arr->size * arr->size_type);
	free(arr->tab);
	arr->tab = iarr;
	return (arr);
}
Esempio n. 7
0
/**
 * ft_get_line - read an ASCII line from a file
 * @fp: file pointer 
 *
 * Get a line of ASCII text from a file. The file is read
 * up to the first \0 or \n.
 * 
 * Returns the dynamically-allocated string containing
 * that line. At the end of a file a string "" will
 * be returned.
 *
 * In *both* cases, the string must be free()d at some
 * point.
 *
 * %NULL may be returned on allocation failure.
 */ 
char * ft_get_line(FILE * fp)
{
	char * buf;
	char * cp;
	int c;
	size_t max = 128;

	buf = ft_malloc(max);
	if (!buf)
		return NULL;
 
	cp = buf; 

	do {
		switch (c = fgetc(fp)) {
			case EOF:
			case '\0':
				*cp = '\0';
				return buf;
				break;

			case '\n':
				*cp = (char)c;
				cp++;
				if (((size_t)(cp - buf)) == max) {
					buf = ft_realloc(buf, max + 64);
					if (!buf)
						return NULL;
					cp = buf+max;
					max += 64;
				}
				*cp = '\0';
				return buf;
				break;

			default:
				*cp = (char)c;
				cp++;
				if (((size_t)(cp - buf)) == max) {
					buf = ft_realloc(buf, max + 64);
					if (!buf)
						return NULL;
					cp = buf+max;
					max += 64;
				}
				break;
		}
	} while (1);
}
Esempio n. 8
0
t_img	*ft_load_img(void *mlx, char *src)
{
	t_img	*i;

	if (!src || !(i = (t_img*)ft_malloc(sizeof(t_img))))
		return (NULL);
	if (!(i->img = mlx_xpm_file_to_image(mlx, src, &(i->width), &(i->height))))
		return (NULL);
	i->data = mlx_get_data_addr(i->img, &(i->bpp),
								&(i->sizeline), &(i->endian));
	i->sl_div = i->sizeline / 4;
	i->bpp_div = i->bpp / 8 / 4;
	i->udata = (unsigned int*)i->data;
	return (i);
}
Esempio n. 9
0
t_list *ft_lstnew(void const *content, size_t content_size)
{
	t_list	*res;

	res = (t_list*)ft_malloc(sizeof(t_list));
	if (!res)
		return (NULL);
	res->next = NULL;
	if (!content)
	{
		res->content = NULL;
		res->content_size = 0;
		return (res);
	}
	res->content = ft_malloc(content_size);
	if (!res->content)
	{
		res->content_size = 0;
		return (NULL);
	}
	ft_memcpy(res->content, content, content_size);
	res->content_size = content_size;
	return (res);
}
Esempio n. 10
0
t_img	*ft_new_img(void *mlx, int width, int height)
{
	t_img	*i;

	if (!(i = (t_img*)ft_malloc(sizeof(t_img))))
		return (NULL);
	i->width = width;
	i->height = height;
	i->img = mlx_new_image(mlx, width, height);
	i->data = mlx_get_data_addr(i->img, &(i->bpp),
								&(i->sizeline), &(i->endian));
	i->sl_div = i->sizeline / 4;
	i->bpp_div = i->bpp / 8 / 4;
	i->udata = (unsigned int*)i->data;
	return (i);
}
Esempio n. 11
0
char		*m_strnew(size_t size)
{
	char	*newstr;
	size_t	i;

	i = 0;
	newstr = (char *)ft_malloc(sizeof(newstr) * size + 1);
	if (newstr == NULL)
		return (NULL);
	while (i <= size)
	{
		newstr[i] = '\0';
		i++;
	}
	newstr[size] = '\0';
	return (newstr);
}
Esempio n. 12
0
t_array	*array_insert(t_array *arr, void *value, size_t index)
{
	void	*temp;

	assert(index < arr->size);
	temp = ft_malloc((arr->size - index) * arr->size_type);
	if (!temp)
		return (NULL);
	ft_memcpy(temp, arr->tab + arr->size_type * index,
				(arr->size - index) * arr->size_type);
	ft_memcpy(arr->tab + arr->size_type * (index + 1), temp,
				(arr->size - index) * arr->size_type);
	array_set(arr, value, index);
	arr->size++;
	if (arr->size == arr->capacity)
		array_resize(arr);
	return (arr);
}
Esempio n. 13
0
static void		*realloc_large(void *ptr, size_t size)
{
	void		*ret;
	t_large		*tmp;

	tmp = g_pool.large_m;
	while (tmp)
	{
		if ((void *)tmp + sizeof(t_large) == ptr)
		{
			ret = ft_malloc(size);
			ret = ft_memcpy(ret, ptr, size);
			ft_free(ptr);
			return (ret);
		}
		tmp = tmp->next;
	}
	return (NULL);
}
Esempio n. 14
0
void		*ft_calloc(size_t n, size_t size)
{
	void		*p;

	context_acquire();
	if (g_ctx.cfg.print_allocated)
		ft_mlog(&g_ctx, INFO, "calloc(%zd, %zd)", n, size);
	context_release();
	p = ft_malloc(n * size);
	context_acquire();
	if (p)
		memset(p, 0, n * size);
	else
		ft_mlog(&g_ctx, ERROR, "null pointer exception!");
	if (g_ctx.cfg.print_nb_blocks)
		ft_mlog(&g_ctx, INFO, "Blocks: %zd", g_ctx.stat.nb_blocks);
	context_release();
	return (p);
}
int			main(void)
{
    char	*str;
    int j;

    for (int i = 0; i < 200000; i++)
    {
        str = (char *)ft_malloc(sizeof(char) * 40);
        if (!str)
        {
            printf("str doesnt exist\n");
            return (1);
        }
        j = -1;
        while (++j < 39)
            str[j] = 'a';
        str[j] = '\0';
        printf("%d %s\n", i, str);
    }
}
Esempio n. 16
0
static char						*convert_long_base(unsigned long nbr)
{
	int						i;
	static char				*res;
	const char				*base;

	i = 8;
	if (!res)
		if (!(res = (char *)ft_malloc(sizeof(char) * 9)))
			return (NULL);
	ft_bzero(res, 9);
	base = "0123456789abcdef";
	while ((nbr / 16) > 0 || i >= 8)
	{
		res[i] = base[(nbr % 16)];
		nbr /= 16;
		i--;
	}
	res[i] = base[(nbr % 16)];
	return (res);
}
Esempio n. 17
0
char			*ft_read_input(char *buffer, int fd)
{
	int				ret;
	char			*tmp;
	static int		check = 0;

	tmp = (char *)ft_malloc((sizeof(char) * BUFF_SIZE + 1));
	ret = (int)read(fd, tmp, BUFF_SIZE);
	if (ret > 0)
		buffer = get_line(tmp, buffer, check, ret);
	else
		ft_free(tmp);
	if (ret == BUFF_SIZE)
	{
		check++;
		return (ft_read_input(buffer, fd));
	}
	else
	{
		check = 0;
		return (buffer);
	}
}
Esempio n. 18
0
		else if (!(count = 0))
			return (NULL);
		ft_free_data_hash(save);
		save = NULL;
		ft_init_path();
	}
	return (save);
}

static void		ft_init_tab_path(char **final, int i, char *f_path)
{
	t_data			**tab;
	DIR				*d;
	struct dirent	*dir;

	tab = (t_data **)ft_malloc(sizeof(t_data *) * 4096);
	ft_init_tab(tab);
	while (final[++i] != NULL)
	{
		d = opendir(final[i]);
		if (d)
		{
			while ((dir = readdir(d)))
			{
				f_path = ft_strjoin(ft_strdup(final[i]), "/");
				f_path = ft_strjoin(f_path, dir->d_name);
				ft_set_node(dir->d_name, f_path, tab);
				ft_free(f_path);
			}
			closedir(d);
		}