t_lvar *lvar_cons(t_lvar *a, t_lvar *b, int *errn) { t_llst *tmp; t_lvar *res; if (b->type == T_LLSTP) { if (!(res = lvar_new())) { error_raise(errn, ERR_NO_MEM); return (NULL); } tmp = llst_cons(a, b->val->llstp, errn); if (*errn) { error_print_stack("lvar cons (system function)"); GC_DEC(res); return (NULL); } res->val->llstp = tmp; res->type = T_LLSTP; GC_INC(b); return (res); } error_raise(errn, ERR_WRONG_TYPE); return (NULL); }
static inline t_lvar *lvar_add_error(t_lvar *res, int *errn, int errint) { GC_DEC(res); error_raise(errn, errint); error_print_stack("+ (system function)"); return (NULL); }
void ns_add(t_nshash *glob, char *str, t_lvar *var, int *errn) { int hres; t_nshi *bucket; hres = ns_global_hash(str); bucket = glob->buckets[hres]; if (!bucket) { if (!(glob->buckets[hres] = nshash_new_bucket(str, var))) error_raise(errn, ERR_NO_MEM); return ; } while (bucket && bucket->next) bucket = bucket->next; if (bucket->val) GC_DEC(bucket->val); if (!(bucket->next = nshash_new_bucket(str, var))) error_raise(errn, ERR_NO_MEM); }
t_lvar *lvar_new_llst(t_lvar *var, int *errn) { t_llst *tmp; t_lvar *res; if (!(tmp = llst_new())) { error_raise(errn, ERR_NO_MEM); return (NULL); } if (!(res = lvar_new())) { error_raise(errn, ERR_NO_MEM); free(tmp); return (NULL); } res->val->llstp = tmp; res->type = T_LLSTP; tmp->val = var; return (res); }
static int ftrace_timestamp_option(const char *arg) { (void) arg; if (g_timestamp_type == TS_NONE) g_timestamp_type = TS_TIME; else if (g_timestamp_type == TS_TIME) g_timestamp_type = TS_MILLISECOND; else return (error_raise("Invalid option given"), -1); return (0); }
t_nshash *ns_global_new(int *errn) { t_nshash *res; if (!(res = malloc(sizeof(t_nshash)))) { error_raise(errn, ERR_NO_MEM); return (NULL); } if (!(res->buckets = malloc(sizeof(t_nshi *) * 188))) { free(res); error_raise(errn, ERR_NO_MEM); return (NULL); } res->hash = &ns_global_hash; res->get = &ns_get; res->add = &ns_add; res->parent = NULL; return (res); }
int ftrace_elf_open(const char *path, struct s_ftrace_opts *opts) { assert(path != NULL); assert(opts != NULL); if (elf_version(EV_CURRENT) == EV_NONE) return (error_raise(elf_errmsg(-1)), -1); opts->elf_fd = open(path, O_RDONLY); if (opts->elf_fd == -1) return (error_raise_errno(), -1); opts->elf = elf_begin(opts->elf_fd, ELF_C_READ, NULL); if (opts->elf == NULL) return (error_raise_ctx(elf_errmsg(-1), path), -1); return (0); }
t_lvar *ns_get(t_nshash *glob, char *str, int *errn) { int hres; t_nshi *bucket; hres = ns_global_hash(str); bucket = glob->buckets[hres]; while (bucket && ft_strcmp(bucket->name, str)) bucket = bucket->next; if (!bucket) { error_raise(errn, ERR_NOT_DEFINED); return (NULL); } else return (bucket->val); }