/** As memdup, but returns the memory from <b>area</b>. */ void * memarea_memdup(memarea_t *area, const void *s, size_t n) { char *result = memarea_alloc(area, n); memcpy(result, s, n); return result; }
/** As memarea_alloc(), but clears the memory it returns. */ void * memarea_alloc_zero(memarea_t *area, size_t sz) { void *result = memarea_alloc(area, sz); memset(result, 0, sz); return result; }
thread_list_t *new_thread_list(int tid){ thread_list_t *list = memarea_alloc(sizeof(thread_list_t)); if (list) { list->tid = tid; } return list; }
group_list_t *new_group_list(char *name){ group_list_t *list = memarea_alloc(sizeof(group_list_t)); if (list) { list->name = malloc(strlen(name)); strcpy(list->name, name); list->thread_list = NULL; } return list; }
/** As strndup, but returns the memory from <b>area</b>. */ char * memarea_strndup(memarea_t *area, const char *s, size_t n) { size_t ln = 0; char *result; tor_assert(n < SIZE_T_CEILING); for (ln = 0; ln < n && s[ln]; ++ln) ; result = memarea_alloc(area, ln+1); memcpy(result, s, ln); result[ln]='\0'; return result; }
/** As strndup, but returns the memory from <b>area</b>. */ char * memarea_strndup(memarea_t *area, const char *s, size_t n) { size_t ln; char *result; const char *cp, *end = s+n; for (cp = s; cp < end && *cp; ++cp) ; /* cp now points to s+n, or to the 0 in the string. */ ln = cp-s; result = memarea_alloc(area, ln+1); memcpy(result, s, ln); result[ln]='\0'; return result; }