static void ft_getinput(t_env *e, char *av) { int j; int fd; char *s; char **tab; if ((fd = open(av, O_RDONLY)) == -1) ft_error("open: Le fichier n'a pas ete lu."); e->height = 0; e->width = 0x0FFFFFFF; e->grid = (t_pt**)ft_xmalloc(sizeof(t_pt*)); e->grid[0] = NULL; while (get_next_line(fd, &s) > 0 && ++(e->height)) { if (!(tab = ft_strsplit(s, ' '))) ft_error("ft_strsplit: La ligne ne peut pas etre splittee."); e->grid = ft_addline(e->grid, tab, e); free(s); j = 0; while (tab[j]) free(tab[j++]); free(tab); } close(fd); }
char *sh1_gethname(void) { char *ret; ret = (char*)ft_xmalloc(255); *ret = 0; gethostname(ret, 255); return (ret); }
t_fdf_matrix *fdf_matrix_scale(double s) { t_fdf_matrix *ret; ret = (t_fdf_matrix*)ft_xmalloc(sizeof(t_fdf_matrix)); ret->a1 = s; ret->b2 = s; ret->c3 = s; ret->d4 = 1; return (ret); }
static t_hack *init_ls_hack(void) { t_hack *ret; ret = (t_hack*)ft_xmalloc(sizeof(t_hack)); ret->dent = NULL; ret->args = NULL; ret->dcontent = NULL; ret->subdirs = NULL; ret->path = NULL; return (ret); }
t_tree *ft_new_elem(char *content) { t_tree *new_elem; if (!content) return (NULL); if (!(new_elem = (t_tree*)ft_xmalloc(sizeof(t_tree)))) return (NULL); new_elem->data = ft_strdup(content); new_elem->left = NULL; new_elem->right = NULL; return (new_elem); }
t_fdf_matrix *fdf_matrix_rotation_z(double beta) { t_fdf_matrix *ret; ret = (t_fdf_matrix*)ft_xmalloc(sizeof(t_fdf_matrix)); ret->a1 = cos(beta); ret->a2 = -sin(beta); ret->b1 = sin(beta); ret->b2 = cos(beta); ret->c3 = 1; ret->d4 = 1; return (ret); }
t_fdf_matrix *fdf_matrix_translation(double tx, double ty, double tz) { t_fdf_matrix *ret; ret = (t_fdf_matrix*)ft_xmalloc(sizeof(t_fdf_matrix)); ret->a4 = tx; ret->b4 = ty; ret->c4 = tz; ret->a1 = 1; ret->b2 = 1; ret->c3 = 1; ret->d4 = 1; return (ret); }
t_rl_ctx *rl_ctx_init(char *header) { t_rl_ctx *ret; struct termios org_opts; ret = (t_rl_ctx*)ft_xmalloc(sizeof(t_rl_ctx)); ret->line = NULL; ret->header = NULL; ret->pos = 0; ret->max = 0; ret->header = header; if (tcgetattr(fileno(stdin), &org_opts) < 0) exit(-1); return (ret); }
t_max *init_max_chars(void) { t_max *max_c; max_c = (t_max*)ft_xmalloc(sizeof(t_max)); if (!max_c) { write(1, "ft_ls: insufficient memory\n", 27); exit (1); } MAXL = 0; MAXU = 0; MAXG = 0; MAXS = 0; MAXT = 0; MAXM = 0; return (max_c); }
char *ls_mkpath(char *left, char *right) { char *ret; if (left && !right) return (ft_strdup(left)); else if (right && !left) return (ft_strdup(right)); else { ret = (char*)ft_xmalloc(ft_strlen(left) + ft_strlen(right) + 2); ft_strcpy(ret, left); if (ft_strcmp(left, "/")) ft_strcat(ret, "/"); ft_strcat(ret, right); return (ret); } }
char *rl_list_to_tab(t_lst **line) { char *ret; t_uint i; t_lst *tmp; ret = (char*)ft_xmalloc(ft_lstlen(*line) + 1); i = 0; while (*line) { tmp = *line; ret[i++] = *((char*)(*line)->data); (*line) = (*line)->next; free(tmp->data); free(tmp); } ret[i] = 0; *line = NULL; return (ret); }
char *sh1_getenv_name(char *full_var) { char *ret; char *pos; t_uint i; ret = NULL; if ((pos = ft_strchr(full_var, '='))) { i = 0; ret = (char*)ft_xmalloc(pos - full_var + 1); while (full_var[i] != '=') { ret[i] = full_var[i]; ++i; } ret[i] = 0; } return (ret); }
char *get_path_link(char *name) { int len; struct stat lstats; char *linkname; if (lstat(name, &lstats) < 0) exit (1); if (S_ISLNK(lstats.st_mode)) { linkname = (char*)ft_xmalloc(sizeof(char) * 1024); if (linkname == NULL) { ft_putendl_fd("insufficient memory\n", 2); exit (1); } if ((len = readlink(name, linkname, 1024)) < 0) exit (1); linkname[len] = '\0'; return (linkname); } return (NULL); }