/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <b.h>

b_error_t
b_el_new (b_tcache_t * cache, b_el_t ** list)
{
  b_el_t *new;

  if (!(new = calloc (1, sizeof (b_el_t))))
    return B_ERROR_MEMORY;

  new->cache = cache;
  new->next = *list;
  *list = new;

  return B_OK;
}

void
b_el_free (b_el_t ** list)
{
  b_el_t *tmp;

  while (*list)
    {
      tmp = *list;
      *list = tmp->next;

      if (tmp->cache)
	b_tcache_destroy_single (NULL, NULL, tmp->cache);

      free (tmp);
    }
}

b_tcache_t *
b_el_first (b_el_t ** list)
{
  b_el_t *first;
  b_tcache_t *cache;

  first = *list;
  cache = first->cache;

  *list = first->next;
  free (first);

  return cache;
}

/* EOF */
