]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libndb/ndbgetval.c
fix special case for null pointer constants in cond expressions
[plan9front.git] / sys / src / libndb / ndbgetval.c
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include "ndb.h"
5
6 /*
7  *  search for a tuple that has the given 'attr=val' and also 'rattr=x'.
8  *  copy 'x' into 'buf' and return the whole tuple.
9  *
10  *  return nil if not found.
11  */
12 char*
13 ndbgetvalue(Ndb *db, Ndbs *s, char *attr, char *val, char *rattr, Ndbtuple **pp)
14 {
15         Ndbtuple *t, *nt;
16         char *rv;
17         Ndbs temps;
18
19         if(s == nil)
20                 s = &temps;
21         if(pp)
22                 *pp = nil;
23         t = ndbsearch(db, s, attr, val);
24         while(t != nil){
25                 nt = ndbfindattr(t, s->t, rattr);
26                 if(nt != nil){
27                         rv = strdup(nt->val);
28                         if(pp != nil)
29                                 *pp = t;
30                         else
31                                 ndbfree(t);
32                         return rv;
33                 }
34                 ndbfree(t);
35                 t = ndbsnext(s, attr, val);
36         }
37         return nil;
38 }