Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/nss/slist.c
blob: 160c17e315fb9ee3c1aad20770db540e698e6eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#include "slist.h"

void slist_init(struct slist* self) {
  self->next = self;
}

bool slist_null(struct slist* self) {
  return self == self->next;
}

bool slist_non_null(struct slist* self) {
  return self != self->next;
}

void slist_extend(struct slist* self, struct slist* rhs) {
  rhs->next = self->next;
  self->next = rhs;
}

size_t slist_length(struct slist* self) {
  /* XXX: Arithmetic overflow! */
  size_t result = 0;
  while (slist_non_null(self)) {
    result++;
    self = self->next;
  }
  return result;
}