t_env *put_in_list(t_env *root, char *param) { t_env *new_env; if ((new_env = (t_env *)malloc(sizeof(t_env))) == NULL) return ((t_env *)ft_error_null("Error, couldn't malloc\n")); new_env->num = root->prev->num + 1; new_env->prev = root->prev; new_env->next = root; root->prev->next = new_env; root->prev = new_env; if (!(new_env->var = ft_strdup(param))) return ((t_env *)ft_error_null("Error, couldn't strdup\n")); new_env->pos = -1; return (new_env); }
void ft_lstiter(t_list *lst, void (*f) (t_list *elem)) { if (!(lst) || !(f)) ft_error_null("ft_lstiter"); else while (lst) { f(lst); lst = lst->next; } }
char *ft_malloc(int size) { int i; char *str; i = 0; str = malloc(size); if (str == NULL) return (ft_error_null("Fail malloc")); while (i < size) str[i++] = '\0'; return (str); }
t_env *get_root(void) { t_env *root; if ((root = (t_env *)malloc(sizeof(t_env))) == NULL) return ((t_env *)ft_error_null("Error, couldn't malloc\n")); root->next = root; root->prev = root; root->var = NULL; root->pos = 1; root->num = 0; return (root); }
int ft_strequ(char const *s1, char const *s2) { size_t count; count = 0; if (!(s1) || !(s2)) return ((int)ft_error_null("ft_strequ")); while (s1[count] && s2[count]) { if (s1[count] != s2[count]) return (0); count++; } return (1); }
char *ft_realloc(char *cmd, int size) { int i; char *new_cmd; i = 0; new_cmd = malloc(size); if (new_cmd == NULL) return (ft_error_null("Fail malloc()")); while (cmd[i]) { new_cmd[i] = cmd[i]; i++; } while (i < size) new_cmd[i++] = '\0'; free(cmd); return (new_cmd); }
char *ft_strmapi(char const *s, char (*f) (unsigned int, char)) { char *str; unsigned int i; i = -1; if (!s || !f) { ft_error_null("ft_strmapi"); return (NULL); } if ((str = ft_strnew(ft_strlen(s)))) { while (s[++i]) str[i] = f(i, s[i]); return (str); } ft_error_malloc("ft_strmapi"); return (NULL); }