void select_add(select_function *sfn, union arg *args, size_t nargs) { if(!(nselectors + 1)) fatal(0, "too many selectors"); selectors = xrecalloc(selectors, nselectors + 1, sizeof *selectors); selectors[nselectors].sfn = sfn; selectors[nselectors].args = args; selectors[nselectors].nargs = nargs; ++nselectors; }
/** @brief Find a free slot in @ref handles * @param id Where to store handle * @param type @ref SSH_FXP_OPEN or @ref SSH_FXP_OPENDIR */ static void find_free_handle(struct handleid *id, int type) { size_t n; for(n = 0; n < nhandles && handles[n].tag; ++n) ; if(n == nhandles && nhandles < MAXHANDLES) { /* need more space */ nhandles = (nhandles ? 2 * nhandles : 16); assert(nhandles != 0); handles = xrecalloc(handles, nhandles, sizeof (*handles)); memset(handles + n, 0, (nhandles - n) * sizeof (*handles)); } while(!sequence) ++sequence; /* never have a tag of 0 */ handles[n].tag = sequence++; handles[n].type = type; id->id = n; id->tag = handles[n].tag; }
void *__xrecalloc(char *file, int line, void *ptr, size_t nelem, size_t elemsz) { XALLOC_REC *rec, srch; if(!xalloc_initialized) xalloc_init(); if(ptr) { srch.ptr = ptr; if((rec = hash_search(xalloc_hash, &srch)) == NULL) { ulog(ULOG_INFO, "(%s, %d): xrecalloc: attempted to recalloc " "from bad pointer.\n", file, line); return(NULL); } hash_delete(xalloc_hash, rec); xar_destroy(rec); } ptr = xrecalloc(ptr, nelem, elemsz); xalloc_numrealloc++, xalloc_id++; rec = xar_create(file, line, xalloc_id, xrecalloc_name, ptr, nelem * elemsz); hash_insert(xalloc_hash, rec); return(ptr); }