예제 #1
0
t_point		*new_point(t_int y, t_int x)
{
	t_point	*ans;

	if (!(ans = (t_point *)malloc(sizeof(t_point))))
		malloc_fail();
	ans->x = x;
	ans->y = y;
	return (ans);
}
예제 #2
0
t_dim		*new_dim(t_int width, t_int height)
{
	t_dim	*ans;

	if (!(ans = (t_dim *)malloc(sizeof(t_dim))))
		malloc_fail();
	ans->width = width;
	ans->height = height;
	return (ans);
}
예제 #3
0
char	*get_prompt(t_var var)
{
  var.i = 0;
  if ((var.buf = malloc(sizeof(char *) * 4096)) == NULL)
    malloc_fail();
  if ((var.buf = getcwd(var.buf, 4096)) == NULL);
  while (var.buf[var.i++] != 0);
  var.buf[--var.i] = '>';
  var.buf[++var.i] = ' ';
  return (var.buf);
}
예제 #4
0
t_max		*new_max(void)
{
	t_max		*ans;

	if (!(ans = (t_max *)malloc(sizeof(t_max))))
		malloc_fail();
	ans->value = 0;
	ans->x = 0;
	ans->y = 0;
	return (ans);
}
예제 #5
0
파일: xmalloc.c 프로젝트: cojocar/cmus-dbus
char *xstrndup(const char *str, size_t n)
{
	int len;
	char *s;

	for (len = 0; len < n && str[len]; len++)
		;
	s = malloc(len + 1);
	if (unlikely(s == NULL))
		malloc_fail();
	memcpy(s, str, len);
	s[len] = 0;
	return s;
}
예제 #6
0
int	create_file(char *name)
{
  int   fd;
  char  *new_name;
  int	start;

  start = sizeofpath(name);
  new_name = my_strndup
    (&name[start], my_strlen(name) - sizeofextens(name) - start);
  if ((new_name = realloc
       (new_name, my_strlen(name) - sizeofextens(name) - start + 5)) == NULL)
    return (malloc_fail(), 1);
  my_strcat(new_name, ".cor");
  if ((fd = open(new_name, O_WRONLY | O_CREAT | O_TRUNC,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) == -1)
    return (1);
  free(new_name);
  return (fd);
}
예제 #7
0
t_work		*new_work(char *str)
{
	char	*ptr;
	t_work	*ans;

	ptr = str;
	if (!(ans = (t_work *)malloc(sizeof(t_work))))
		malloc_fail();
	while (*ptr != '\0')
		ptr++;
	ans->map = new_dim(0, 0);
	ans->taken = *(--ptr);
	ans->obstacle = *(--ptr);
	ans->room = *(--ptr);
	*(ptr) = 'X';
	ans->map->height = ft_atoi(str);
	if (ans->map->height == 0 || ans->taken == ans->room
		|| ans->taken == ans->obstacle || ans->room == ans->obstacle)
		return (0);
	ans->max = new_max();
	ans->cur_line = 0;
	ans->to_be_skipped = 0;
	return (ans);
}