void handle_getdir(struct request *req, int val){ aiob *aio = req->aio; close(aio->aio_fildes); val = aio_return(aio); array_t *ret = allocate_empty_array(val); int i; if(val > -1) { struct linux_dirent *de = (struct linux_dirent *)aio->aio_buf; for(i=0; ((char *)de) - (char *)(aio->aio_buf) < val; i++) { svalue_t *vp = &(ret->item[i]); vp->type = T_STRING; vp->subtype = STRING_MALLOC; //printf("%s ", de->d_name); vp->u.string = string_copy(de->d_name, "encode_stat"); de = (struct linux_dirent *)(((char *)de) + de->d_reclen); } } ret = RESIZE_ARRAY(ret, i); ret->size = i; push_refed_array(ret); set_eval(max_cost); safe_call_efun_callback(req->fun, 1); }
/* * Slice of an array. * It now frees the passed array */ array_t *slice_array P3(array_t *, p, int, from, int, to) { int cnt; svalue_t *sv1, *sv2; if (from < 0) from = 0; if (to >= p->size) to = p->size - 1; if (from > to) { free_array(p); return null_array(); } if (!(--p->ref)){ #ifdef PACKAGE_MUDLIB_STATS add_array_size(&p->stats, -((int)p->size)); #endif total_array_size += (to - from + 1 - p->size) * sizeof(svalue_t); if (from) { sv1 = p->item + from; cnt = from; while (cnt--) free_svalue(--sv1, "slice_array:2"); cnt = to - from + 1; sv1 = p->item; sv2 = p->item + from; while (cnt--) *sv1++ = *sv2++; } else { sv2 = p->item + to + 1; } cnt = (p->size - 1) - to; while (cnt--) free_svalue(sv2++, "slice_array:3"); p = RESIZE_ARRAY(p, to-from+1); #ifdef PACKAGE_MUDLIB_STATS if (current_object) { assign_stats(&p->stats, current_object); add_array_size(&p->stats, to - from + 1); } else null_stats(&p->stats); #endif p->size = to-from+1; p->ref = 1; return p; } else { array_t *d; d = allocate_empty_array(to - from + 1); sv1 = d->item - from; sv2 = p->item; for (cnt = from; cnt <= to; cnt++) assign_svalue_no_free(sv1 + cnt, sv2 + cnt); return d; } }