Example #1
0
void	*ft_memalloc(size_t size)
{
	void *result;

	if (size == 0)
		return (NULL);
	result = malloc(sizeof(void *) * size);
	if (result == NULL)
		return (NULL);
	ft_bzero(result, size);
	return (result);
}
Example #2
0
File: ft_itoa.c Project: cyb-/libft
char		*ft_itoa(int n)
{
	char		buf[12];
	char		*ptr;

	ft_bzero(&buf, 12);
	ptr = buf;
	if (n < 0)
		*ptr++ = '-';
	ft_itoa_fillstr(n, ptr);
	return (ft_strdup(buf));
}
Example #3
0
void		*ft_memalloc(size_t size)
{
	void	*mem;

	if (size == 0)
		return (0);
	mem = malloc(size);
	if (!(mem))
		return (0);
	ft_bzero(mem, size);
	return (mem);
}
Example #4
0
char	*ft_strnew(size_t size)
{
	char *str;

	str = (char*)malloc(sizeof(char) * size);
	if (str)
	{
		ft_bzero(str, size);
		return (str);
	}
	return (NULL);
}
Example #5
0
char	*ft_strncpy(char *dst, const char *src, size_t n)
{
	if (!dst || !src)
		return (NULL);
	if (ft_strlen(src) < n)
	{
		ft_bzero((void *)dst, n);
		return (ft_strcpy(dst, src));
	}
	else
		return ((char *)ft_memcpy((void *)dst, (void *)src, n));
}
Example #6
0
void		*ft_memalloc(size_t size)
{
	void	*ptr;

	if (size == 0)
		return (0);
	ptr = malloc(size);
	if (ptr == 0)
		return (0);
	ft_bzero(ptr, size);
	return (ptr);
}
Example #7
0
void	*ft_memalloc(size_t size)
{
	void	*new_space;

	if (!size)
		return (NULL);
	new_space = (void*)malloc(size * sizeof(void*));
	if (!new_space)
		return (NULL);
	ft_bzero(new_space, size);
	return (new_space);
}
Example #8
0
File: ft_strnew.c Project: Selk/Dev
char	*ft_strnew(size_t size)
{
	char	*dest;

	dest = (char*)malloc(sizeof(char) * (size + 1));
	if (dest)
	{
		ft_bzero(dest, (size + 1));
		return (dest);
	}
	return (NULL);
}
Example #9
0
int				graph_seg(t_env *e, int cs)
{
	if (ft_strncmp(e->fds[cs].buf_read, "seg ", 4) == 0)
	{
		sprintf(e->fds[cs].buf_write, "%s",
				e->fds[cs].buf_read);
		ft_putstr_fd(e->fds[cs].buf_write, cs);
		ft_bzero(e->fds[cs].buf_write, BUF_SIZE);
		return (1);
	}
	return (0);
}
Example #10
0
int				graph_sgt(t_env *e, int cs)
{
	if (ft_strcmp(e->fds[cs].buf_read, "sgt\n") == 0)
	{
		sprintf(e->fds[cs].buf_write, "sgt %d\n",
				e->data.d_time);
		ft_putstr_fd(e->fds[cs].buf_write, cs);
		ft_bzero(e->fds[cs].buf_write, BUF_SIZE);
		return (1);
	}
	return (0);
}
Example #11
0
void	*ft_memalloc(size_t size)
{
	void	*mem;

	mem = malloc(size);
	if (mem)
	{
		ft_bzero(mem, size);
		return (mem);
	}
	return (0);
}
void			malloc_map(t_env *e)
{
	int			i;

	e->map = (t_case **)malloc(sizeof(t_case *) * (e->opt.y));
	i = -1;
	while (++i < e->opt.y)
	{
		e->map[i] = (t_case *)malloc(sizeof(t_case) * (e->opt.x));
		ft_bzero(e->map[i], sizeof(t_case) * (e->opt.x));
	}
}
Example #13
0
char		*ft_ltoa_base(long long n, int base)
{
	char *number;
	char tmp[66];

	ft_bzero(tmp, 66);
	if (n < 0)
		number = ft_strjoin("-", ft_strrev(ft_lbn(n, tmp, -1, base)));
	else
		number = ft_strdup(ft_strrev(ft_lbp(n, tmp, -1, base)));
	return (number);
}
Example #14
0
void	*ft_memalloc(size_t size)
{
	void	*result;

	result = malloc(size);
	if (result)
	{
		ft_bzero(result, size);
		return (result);
	}
	return (NULL);
}
Example #15
0
void	*ft_memalloc(size_t size)
{
	unsigned char	*tmp;

	if (size == 0)
		return (NULL);
	tmp = (unsigned char*)malloc(sizeof(*tmp) * size);
	if (!tmp)
		return (NULL);
	ft_bzero(tmp, size);
	return (tmp);
}
Example #16
0
static void		s_set_comment_in_header(t_arg arg)
{
	if (ft_strlen(arg.data) > COMMENT_LENGTH)
	{
		arg.column += 1;
		error_print(arg, "comment is too long");
		return (ft_strdel(&arg.data));
	}
	ft_bzero(sgt_asm()->cor.header.comment, COMMENT_LENGTH + 1);
	ft_strcpy(sgt_asm()->cor.header.comment, arg.data);
	ft_strdel(&arg.data);
}
Example #17
0
char		*uitoa_base_2(unsigned short int n, int base)
{
	char tmp[21];
	char *rt;

	if (n == 0)
		return (ft_strdup("0"));
	ft_bzero(tmp, 21);
	r_uitoa(n, tmp, base);
	rt = ft_strdup(tmp);
	return (rt);
}
Example #18
0
void	*ft_memalloc(size_t size)
{
	void	*s;

	if (size == 0)
		return (NULL);
	s = (void *)malloc(size);
	if (!s)
		return (NULL);
	ft_bzero(s, size);
	return (s);
}
Example #19
0
void	*ft_memalloc(size_t size)
{
	void	*area;

	area = NULL;
	if (size)
	{
		area = malloc(size);
		if (area)
			ft_bzero(area, size);
	}
	return (area);
}
Example #20
0
void	*ft_memalloc(size_t size)
{
	void	*ret;

	ret = NULL;
	if (size)
	{
		if ((ret = (void*)malloc(size)) == NULL)
			return (NULL);
		ft_bzero(ret, size);
	}
	return (ret);
}
Example #21
0
void	*ft_memalloc(size_t size)
{
	void	*tmp;

	if (size != 0)
	{
		tmp = malloc(size);
		if (tmp != NULL)
			ft_bzero(tmp, size);
		return (tmp);
	}
	return (NULL);
}
Example #22
0
int			last_byt(int fd)
{
	char	src[1024];
	char	*s;

	if (lseek(fd, 0, 0) < 0)
	{
		ft_printf("{fd}Error lseek\n", 2);
		return (-1);
	}
	s = NULL;
	ft_bzero(src, 1024);
	while (read(fd, src, 1024) > 0)
	{
		ft_strdel(&s);
		s = ft_strdup(src);
		ft_bzero(src, 1024);
	}
	if (ft_check_last(s) == -1)
		return (my_erormanager("", ft_tab(0, 0, 0), 10));
	return (0);
}
Example #23
0
t_player		*vm_read_player(t_app *app, char *filename)
{
	int				fd;
	t_player		*rt;

	rt = malloc(sizeof(t_player));
	ft_bzero(rt, sizeof(t_player));
	if (!filename)
		vm_print_error("Error : Wrong player");
	fd = open(filename, O_RDONLY);
	if (fd == -1)
		vm_print_error_str("Error : can't malloc or open player ", filename);
	if (read(fd, &rt->header, sizeof(t_header)) != sizeof(t_header))
		vm_print_error_str("Error : can't read player ", filename);
	vm_swap_bytes_4(&rt->header.prog_size);
	vm_swap_bytes_4(&rt->header.magic);
	ft_bzero(rt->header.prog_name + PROG_NAME_LENGTH + 1, 3);
	ft_bzero(rt->header.comment + COMMENT_LENGTH + 1, 3);
	vm_read_prog(fd, rt, filename);
	vm_create_instance(app);
	return (rt);
}
Example #24
0
static void	storage_file(t_map **addr, int fd, off_t size, char *file_name)
{
	char	map[size + 1];
	int		ret;
	int		tmp;

	ft_bzero((char *)map, (size + 1));
	ret = 0;
	while (((tmp = read(fd, (map + ret), size - ret)) < size) && tmp != (-1))
		ret += tmp;
	((tmp == (-1)) ? error_call_system("read") : 0);
	map_add(addr, map, file_name);
}
Example #25
0
char		*ft_get_pwd(void)
{
	char	*pwd;

	pwd = NULL;
	pwd = (char *)malloc((1024) * sizeof(char));
	if (pwd != NULL)
	{
		ft_bzero(pwd, 0);
		pwd = getcwd(pwd, 1024);
	}
	return (pwd);
}
Example #26
0
char		*handle_key_enter(t_pane *p)
{
	char	*ret;

	werase(p->win);
	ret = ft_strdup(p->input_msg);
	ft_bzero(p->input_msg, p->input_msg_len);
	p->input_msg_len = 0;
	p->cursor = 0;
	if ((p->flags & PANE_BOXED))
		box(p->win, ACS_VLINE, ACS_HLINE);
	return (ret);
}
Example #27
0
void *ft_memalloc(size_t size)
{
    void *ptr;

    ptr = NULL;
    if (size > 0)
    {
        ptr = malloc(size);
        if (ptr != NULL)
            ft_bzero(ptr, size);
    }
    return (ptr);
}
Example #28
0
void		test_ft_memalloc(void)
{
	char	*s1;
	char 	s2[] = "\0\0\0\0\0\0\0\0\0\0";
	char	s3[50];

	ft_bzero(s3, 50);
	s1 = ft_memalloc(10);
	if (!memcmp(s1, s2, 10) && !memcmp(s3, ft_memalloc(50), 50))
		ft_putstr("\033[32mAll test OK \033[m");
	else
		ft_putstr("\033[31mFAIL test ");
}
Example #29
0
static t_token	*get_token(char *buffer)
{
	t_token		*token;

	token = (t_token *)malloc(sizeof(t_token));
	if (!token)
		return (NULL);
	ft_bzero(token, sizeof(t_token));
	token->type = ft_get_addoctet((unsigned char *)buffer, 0, 2);
	buffer += 2;
	token->num = ft_get_addoctet((unsigned char *)buffer, 0, 2);
	buffer += 2;
	token->nbr = ft_get_addoctet((unsigned char *)buffer, 0, 2);
	buffer += 2;
	token->size = ft_get_addoctet((unsigned char *)buffer, 0, 4);
	buffer += 4;
	if (!(token->content = (char *)malloc(sizeof(char) * token->size + 1)))
		return (NULL);
	ft_bzero(token->content, token->size + 1);
	ft_memcpy(token->content, (const char *)buffer, token->size);
	return (token);
}
Example #30
0
void	*ft_memalloc(size_t size)
{
	char	*ptr;

	ptr = NULL;
	if (size <= 0)
		return (NULL);
	if ((ptr = (char *)malloc(size)))
	{
		ft_bzero(ptr, size);
	}
	return ((void *)ptr);
}