/* The default prototype is: long X(long, long, long, long). */ static struct prototype * build_default_prototype(void) { static struct prototype *ret = NULL; if (ret != NULL) return ret; static struct prototype proto; prototype_init(&proto); struct arg_type_info *unknown_type = get_unknown_type(); assert(unknown_type != NULL); proto.return_info = unknown_type; proto.own_return_info = 0; struct param unknown_param; param_init_type(&unknown_param, unknown_type, 0); size_t i; for (i = 0; i < 4; ++i) if (prototype_push_param(&proto, &unknown_param) < 0) { report_global_error("build_default_prototype: %s", strerror(errno)); prototype_destroy(&proto); return NULL; } ret = &proto; return ret; }
static char * xstrndup(char *str, size_t len) { char *ret = (char *) malloc(len + 1); if (ret == NULL) { report_global_error("malloc: %s", strerror(errno)); return NULL; } strncpy(ret, str, len); ret[len] = 0; return ret; }
/* LHS->zero(RHS). Looks for a length of zero-terminated array, but * looks no further than first RHS bytes. */ static int zero_callback(struct value *ret_value, struct value *lhs, struct value *rhs, struct value_dict *arguments, void *data) { long l; if (value_extract_word(rhs, &l, arguments) < 0) return -1; if (l < 0) /* It might just be a positive value >2GB, but that's * not likely. */ report_global_error("maximum array length seems negative"); size_t max = (size_t)l; return zero_callback_max(ret_value, lhs, arguments, max, data); }