svn commit: trunk/busybox: libbb networking

Vladimir N. Oleynik dzo at simtreas.ru
Thu Sep 29 15:04:20 UTC 2005


aldot at busybox.net wrote:

> +#ifdef L_llist_add_to_end
> +extern llist_t *llist_add_to_end(llist_t *list_head, char *data)
> +{
> +	llist_t *new_item, *tmp, *prev;
> +
> +	new_item = xmalloc(sizeof(llist_t));
> +	new_item->data = data;
> +	new_item->link = NULL;
> +
> +	prev = NULL;
> +	tmp = list_head;
> +	while (tmp) {
> +		prev = tmp;
> +		tmp = tmp->link;
> +	}
> +	if (prev) {
> +		prev->link = new_item;
> +	} else {
> +		list_head = new_item;
> +	}
> +
> +	return (list_head);
> +}
> +#endif

May be eq size, but one 1 temporary variable:

extern llist_t *llist_add_to_end(llist_t *list_head, char *data)
{
	llist_t *new_item;

	new_item = xmalloc(sizeof(llist_t));
	new_item->data = data;
	new_item->link = NULL;

	if(list_head == NULL) {
		list_head = new_item;
	} else {
		llist_t *bottom = list_head;
		while(bottom->link)
			bottom = bottom->link;
		bottom->link = new_item;
	}
	return list_head;
}



More information about the busybox mailing list