static char *ft_realloc(char *buff, size_t size) { char *newbuff; if ((newbuff = ft_memalloc(size + BUFFSIZE)) == NULL) return (NULL); if (buff) { ft_strcpy(newbuff, buff); ft_memdel((void **)&buff); } return (newbuff); }
char *ft_strndup(char const *src, size_t len) { char *dst; char *s; if (!(dst = ft_memalloc(sizeof(char) * len + 1))) return (NULL); s = dst; while((*s++ = *src++) != '\0' && --len) continue; *s = '\0'; return (dst); }
t_conv *ft_newconv(t_conv *nxt, char *ptn, char *(*f)(t_str_conv*)) { t_conv *conv; conv = (t_conv*)ft_memalloc(sizeof(t_conv)); if (!conv) return (NULL); conv->ltr = ptn; conv->size = ft_strlen(ptn); conv->f = f; conv->next = nxt; return (conv); }
int main() { char *dest, *src; src = (char *) ft_memalloc(sizeof(*src) * BUFF_SIZE); src = "Testing tests with testing tests."; dest = ft_strdup(src); if (ft_memcmp(dest, src, ft_strlen(src)) == 0) printf("OK"); else printf("%d --- duplicated string is: %s\n", ft_memcmp(dest, src, ft_strlen(src)), dest); return 0; }
static void ft_list_image(t_texture *t) { t->list_img = (t_img **)ft_memalloc(sizeof(t_img) * 8); t->list_img[0] = &t->bluestone; t->list_img[1] = &t->colorstone; t->list_img[2] = &t->eagle; t->list_img[3] = &t->greystone; t->list_img[4] = &t->mossy; t->list_img[5] = &t->purplestone; t->list_img[6] = &t->redbrick; t->list_img[7] = &t->wood; ft_putstr("List texture image : DONE\n"); }
int main(int argc, char **argv, char **env) { t_env *e; UNUSED argc; UNUSED argv; if ((e = (t_env*)(ft_memalloc(sizeof(t_env)))) == NULL) ft_mallerr(); e->env = env; e->path = ft_load_path(ft_get_env("PATH", e->env)); ft_command_line(e); return 0; }
t_dlist *ft_lstnew(int content, int i, int j) { t_dlist *ret; if (!(ret = (t_dlist *)ft_memalloc(sizeof(t_dlist)))) return (NULL); ret->next = NULL; ret->down = NULL; ret->p.z = content; ret->p.x = i; ret->p.y = j; return (ret); }
t_list *ft_lstnew(void const *content, size_t content_size) { t_list *result; result = (t_list *)ft_memalloc(sizeof(t_list)); if (!result) return (NULL); result->content = NULL; result->next = NULL; if (!content) result->content_size = 0; else { result->content = (void *)ft_memalloc(content_size); if (result->content) { ft_memcpy(result->content, content, content_size); result->content_size = content_size; } } return (result); }
char *ft_strndup(const char *s1, size_t n) { char *copy; copy = NULL; copy = (char*)ft_memalloc(n + 1); if (copy) { ft_strncpy(copy, s1, n); copy[n] = '\0'; } return (copy); }
char *ft_strnew(size_t size) { char *str; int i; i = 0; str = (char *)ft_memalloc(size + 1); if (str == NULL) return (NULL); while (str[i]) str[i++] = '\0'; return (str); }
t_list *ft_lstnew(void const *content, size_t content_size) { t_list *list; list = (t_list *)ft_memalloc(sizeof(t_list)); if (list != NULL) { if (content == NULL) { list->content = NULL; list->content_size = 0; } else { list->content = ft_memalloc(content_size); ft_memcpy(list->content, content, content_size); list->content_size = content_size; } list->next = NULL; } return (list); }
void *ft_memmove(void *s1, const void *s2, size_t n) { void *src; if (n) { src = ft_memalloc(n); ft_memcpy(src, s2, n); ft_memcpy(s1, src, n); free(src); } return (s1); }
void *ft_realloc(void *ptr, size_t size) { void *dup; dup = ft_memalloc(size); if (ptr) { if (dup) ft_memcpy(dup, ptr, size); ft_memdel(&ptr); } return (dup); }
t_puiss *new_puiss(char **av) { t_puiss *p4; int i; p4 = (t_puiss *)ft_memalloc(sizeof(t_puiss)); if ((p4->nb_col = ft_atoi(av[1])) < 7) { if (error_entry(p4->nb_col, 1) == 0) return (NULL); } if ((p4->nb_lines = ft_atoi(av[2])) < 6) { if (error_entry(p4->nb_lines, 1) == 0) return (NULL); } p4->array = (int **)ft_memalloc(sizeof(int *) * (p4->nb_lines + 1)); i = 0; while (i < p4->nb_lines) p4->array[i++] = (int *)ft_memalloc(sizeof(int) * (p4->nb_col + 1)); return (p4); }
static void init_game(t_env *env) { int i; init_scoreboard(env); if ((env->plate = (int **)malloc(sizeof(int *) * env->size)) == NULL) exit(0); if ((env->last_plate = (int **)malloc(sizeof(int *) * env->size)) == NULL) exit(0); i = -1; while (++i < env->size) { if ((env->plate[i] = (int *)ft_memalloc(sizeof(int) * env->size)) == 0) exit(0); if ((env->last_plate[i] = (int *)ft_memalloc(sizeof(int) * env->size)) == 0) exit(0); } pop_new(env->plate, env->size); pop_new(env->plate, env->size); set_winsize(env); }
void add_obj_lst(t_obj_list_begin *begin, t_obj *elem) { t_obj_list *node; node = ft_memalloc(sizeof(t_obj_list)); node->obj = elem; if (!begin->size) begin->begin = node; else begin->end->next = node; begin->end = node; begin->size++; }
void *ft_realloc(void *ptr, size_t size) { void *dst; if (!(dst = ft_memalloc(size))) return (ptr); if (ptr) { ft_memcpy(dst, ptr, size); free(ptr); } return (dst); }
t_hmap *hmap_create(hmap_compare compare, hmap_hash hash) { t_hmap *map; if (!(map = ft_memalloc(sizeof(t_hmap)))) return (ft_printf("Out of memory (hmap_create map)!"), NULL); map->compare = compare == NULL ? default_compare : compare; map->hash = hash == NULL ? default_hash : hash; if (!(map->contents = array_create(sizeof(t_array *), DEFAULT_NB_CONTENTS))) return (ft_printf("Out of memory (hmap_create contents)!"), NULL); map->contents->end = map->contents->max; return (map); }
void *ft_memalloc_error(size_t size) { void *ret; ret = ft_memalloc(size); if (ret == NULL) { perror(ft_strjoin("Fail to allocate memory with size: ", ft_itoa((int)size))); exit(-1); } return (ret); }
char *load_program_source(char *kernel_path) { int fd; char *line; char *source; line = NULL; source = (char *)ft_memalloc(sizeof(char) * 42000); fd = open(kernel_path, O_RDONLY); while (get_next_line(fd, &line) == 1) ft_strcat(source, line); return (source); }
int ft_strfillsplit(char const *s, char **split, int number, char c) { int i; i = 0; split[number] = (char *)ft_memalloc(sizeof(char) + ft_strlen(s) + 1); while (s[i] != (char)c && s[i] != '\0') { split[number][i] = s[i]; i++; } split[number][i] = '\0'; return (i); }
int main(int argc, char **argv) { t_id s; int i; i = -1; s.niveau = (char**)ft_memalloc(sizeof(char*) * 5); while (++i < 5) s.niveau[i] = (char*)ft_memalloc(sizeof(char) * 25); i = -1; s.weapon = (char**)ft_memalloc(sizeof(char*) * 10); while (++i < 10) s.weapon[i] = (char*)ft_memalloc(sizeof(char) * 25); s.mlx = mlx_init(); s.win = mlx_new_window(s.mlx, W_X, W_Y, WIN_NAME); ft_weapons_and_maps(&s); if (argc != 4) ft_error("Incorrect number of arguments.\n"); ft_first_spawn(&s, argv); ft_initialisation(&s); free(s.map); return (0); }
t_list *ft_lstnew(void const *content, size_t content_size) { t_list *link; link = ft_memalloc(sizeof(t_list)); if (!(link)) return (NULL); (*link).content = ft_memalloc(content_size); if (!((*link).content)) return (NULL); if (content == NULL) { (*link).content = NULL; (*link).content_size = 0; } else { ft_memcpy((*link).content, content, content_size); (*link).content_size = content_size; } (*link).next = NULL; return (link); }
t_dic_entry *ft_dicnew(char *key, void *content, size_t size) { t_dic_entry *entry; entry = (t_dic_entry *)ft_memalloc(sizeof(t_dic_entry)); if (!entry) return (NULL); entry->key = ft_strdup(key); if (!entry->key) { free(entry); return (NULL); } entry->content = ft_memalloc(size); if (!entry->content) { free(entry->key); free(entry); return (NULL); } ft_memcpy(entry->content, content, size); return (entry); }
void restart_prompt(int sig) { t_env *env; (void)sig; env = get_t_env(NULL); ft_putchar_fd('\n', get_fd(-1)); display_prompt(env); clear_line(get_first_line(env->le.line)); env->le.line = ft_memalloc(sizeof(t_line)); env->le.line->is_orig = 1; history(RES_ORI, NULL); env->le.pos_x = 4; }
char *ft_strdup(const char *str) { char *str1; int i; i = -1; if (!str1) return (NULL); str1 = (char *)ft_memalloc((ft_strlen(str) + 1) * sizeof(char)); while (str[++i]) str1[i] = str[i]; str1[i] = '\0'; return (str1); }
static int obj_struct_init_gvtx(t_env *env) { debug_stdout("INIT", FILE_LINE_FUN); if (SCOP_DEBUG) fprintf(stdout, "g_vtx_size: %zu, g_vtxs_nb: %d; g_vtxs_malloc: %zu\n", sizeof(t_g_vertex), OBJ_CNTS[e_geometric_vertex], sizeof(t_g_vertex) * OBJ_CNTS[e_geometric_vertex]); if (OBJ_CNTS[e_geometric_vertex] && !(OBJ_GVTX = (t_g_vertex *) ft_memalloc(sizeof(t_g_vertex) * OBJ_CNTS[e_geometric_vertex]))) return (ft_error(env, __FUNCTION__, "malloc OBJ_GVTX failed")); debug_stdout("END", FILE_LINE_FUN); return (EXIT_SUCCESS); }
t_btree ft_btreenew(void *c, int flag) { t_btree newbtree; newbtree = (t_btree)ft_memalloc(sizeof(struct s_btree)); if (!newbtree) return (NULL); newbtree->content = c; newbtree->flag = flag; newbtree->fath = NULL; newbtree->rson = NULL; newbtree->lson = NULL; return (newbtree); }
static int obj_struct_init_color(t_env *env) { debug_stdout("INIT", FILE_LINE_FUN); if (SCOP_DEBUG) fprintf(stdout, "color_size: %zu, color_nb: %d; color_malloc: %zu\n", sizeof(t_color), OBJ_CNTS[e_color], sizeof(t_color) * OBJ_CNTS[e_color]); if (OBJ_CNTS[e_color] && !(OBJ_COLS = (t_color *) ft_memalloc(sizeof(t_color) * OBJ_CNTS[e_color]))) return (ft_error(env, __FUNCTION__, "malloc OBJ_COLS failed")); debug_stdout("END", FILE_LINE_FUN); return (EXIT_SUCCESS); }
int main(void) { t_env *env; char buffer[20]; init_signals(); tgetent(0, getenv("TERM")); if (!(env = malloc(sizeof(*env)))) quit("Failed to malloc env"); if (!(env->caps = malloc(sizeof(*env->caps)))) quit("Failed to malloc env caps"); env->messages = NULL; if (!(env->input = ft_memalloc(1))) quit("Failed to malloc new input"); init_caps(env->caps); terminal_catch_mode(); ft_putstr(env->caps->fullscreen_start); ft_putstr(env->caps->clear); ft_putstr(env->caps->stand_start); ft_putstr(env->caps->bold_start); int i = 0; set_cursor_position(env, 0, get_window_height() - 2); int width = get_window_width(); while (i < width) { ft_putchar('-'); i++; } ft_putstr(env->caps->stand_end); fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); int t = 0; int rd; while (t < 50) { ft_bzero(buffer, 20); while ((rd = read(0, buffer, 20)) < 1) { if (errno != EAGAIN && errno != EWOULDBLOCK) quit("Error on stdin read"); //check tcp //check resize } ft_putstr(buffer); t++; } fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK); ft_putstr(env->caps->fullscreen_end); terminal_normal_mode(); return (0); }