File: gstack_pop.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (20 lines) | stat: -rw-r--r-- 511 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdlib.h>

#include "gstack.h"

/** Remove the first (most recently pushed) element from the queue. If
 * the free function \c fn is \c NULL no data freeing is done. Note that
 * this does not return a pointer to the popped item, as once the item
 * has been popped it is also freed. */
void gstack_pop(struct gstack* s, adt_free_fn* fn)
{
  if (s->head) {
    struct gstack_node* head = s->head;
    if (fn != 0)
      fn(head->data);
    s->head = head->next;
    free(head);
    --s->count;
  }
}