Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_posix/sys/src/libndb/ndbsubstitute.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <bio.h>
4
#include <ndb.h>
5
 
6
/* replace a in t with b, the line structure in b is lost, c'est la vie */
7
Ndbtuple*
8
ndbsubstitute(Ndbtuple *t, Ndbtuple *a, Ndbtuple *b)
9
{
10
	Ndbtuple *nt;
11
 
12
	if(a == b){
13
		ndbsetmalloctag(t, getcallerpc(&t));
14
		return t;
15
	}
16
	if(b == nil){
17
		t = ndbdiscard(t, a);
18
		ndbsetmalloctag(t, getcallerpc(&t));
19
		return t;
20
	}
21
 
22
	/* all pointers to a become pointers to b */
23
	for(nt = t; nt != nil; nt = nt->entry){
24
		if(nt->line == a)
25
			nt->line = b;
26
		if(nt->entry == a)
27
			nt->entry = b;
28
	}
29
 
30
	/* end of b chain points to a's successors */
31
	for(nt = b; nt->entry; nt = nt->entry)
32
		nt->line = nt->entry;
33
	nt->line = a->line;
34
	nt->entry = a->entry;
35
 
36
	a->entry = nil;
37
	ndbfree(a);
38
 
39
	if(a == t){
40
		ndbsetmalloctag(b, getcallerpc(&t));
41
		return b;
42
	}else{
43
		ndbsetmalloctag(t, getcallerpc(&t));
44
		return t;
45
	}
46
}