aboutsummaryrefslogtreecommitdiff
path: root/src/libndb/ndbdiscard.c
blob: 9b2fc0c98fc02c3271eb576050048d75563221bf (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
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ndb.h>

/* remove a from t and free it */
Ndbtuple*
ndbdiscard(Ndbtuple *t, Ndbtuple *a)
{
	Ndbtuple *nt;

	/* unchain a */
	for(nt = t; nt != nil; nt = nt->entry){
		if(nt->line == a)
			nt->line = a->line;
		if(nt->entry == a)
			nt->entry = a->entry;
	}

	/* a may be start of chain */
	if(t == a)
		t = a->entry;

	/* free a */
	a->entry = nil;
	ndbfree(a);

	return t;
}