Switch/ext/ebtree/ebtree/common/chunk.h
static inline char *chunk_dup(struct chunk *dst, const struct chunk *src)
{
	if (!dst || !src || src->len < 0 || !src->str)
		return NULL;

	if (dst->size)
		free(dst->str);
	dst->len = src->len;
	dst->size = src->len;
	if (dst->size < src->size || !src->size)
		dst->size++;

	dst->str = (char *)malloc(dst->size);
	memcpy(dst->str, src->str, dst->len);
	if (dst->len < dst->size)
		dst->str[dst->len] = 0;

	return dst->str;
}
/*
 * frees the destination chunk if already allocated, allocates a new string,
 * and copies the source into it. The new chunk will have extra room for a
 * trailing zero unless the source chunk was actually full. The pointer to
 * the destination string is returned, or NULL if the allocation fails or if
 * any pointer is NULL.
 */
frees the destination chunk if already allocated, allocates a new string,
and copies the source into it. The new chunk will have extra room for a
trailing zero unless the source chunk was actually full. The pointer to
the destination string is returned, or NULL if the allocation fails or if
any pointer is NULL.
frees the destination chunk if already allocated allocates a new string and copies the source into it . The new chunk will have extra room for a trailing zero unless the source chunk was actually full . The pointer to the destination string is returned or NULL if the allocation fails or if any pointer is NULL .
static inline char *chunk_dup(struct chunk *dst, const struct chunk *src)
{
	if (!dst || !src || src->len < 0 || !src->str)
		return NULL;
	if (dst->size)
		free(dst->str);
	dst->len = src->len;
	dst->size = src->len;
	if (dst->size < src->size || !src->size)
		dst->size++;
	dst->str = (char *)malloc(dst->size);
	memcpy(dst->str, src->str, dst->len);
	if (dst->len < dst->size)
		dst->str[dst->len] = 0;
	return dst->str;
}
static inline char * chunk_dup ( struct chunk * dst , const struct chunk * src ) { if ( ! dst || ! src || src -> len < 0 || ! src -> str ) return NULL ; if ( dst -> size ) free ( dst -> str ) ; dst -> len = src -> len ; dst -> size = src -> len ; if ( dst -> size < src -> size || ! src -> size ) dst -> size ++ ; dst -> str = ( char * ) malloc ( dst -> size ) ; memcpy ( dst -> str , src -> str , dst -> len ) ; if ( dst -> len < dst -> size ) dst -> str [ dst -> len ] = 0 ; return dst -> str ; }
frees the destination chunk if already allocated, allocates a new string,
 and copies the source into it.
frees the destination chunk if already allocated allocates a new string and copies the source into it .