10 int cdb_bread(fd
,buf
,len
)
19 while ((r
== -1) && (errno
== EINTR
));
20 if (r
== -1) return -1;
21 if (r
== 0) { errno
= EIO
; return -1; }
28 static int match(fd
,key
,len
)
40 if (cdb_bread(fd
,buf
,n
) == -1) return -1;
41 for (i
= 0;i
< n
;++i
) if (buf
[i
] != key
[i
]) return 0;
48 int cdb_seek(fd
,key
,len
,dlen
)
62 h
= cdb_hash(key
,len
);
65 if (lseek(fd
,(off_t
) pos
,SEEK_SET
) == -1) return -1;
67 if (cdb_bread(fd
,packbuf
,8) == -1) return -1;
69 pos
= cdb_unpack(packbuf
);
70 lenhash
= cdb_unpack(packbuf
+ 4);
72 if (!lenhash
) return 0;
73 h2
= (h
>> 8) % lenhash
;
75 for (loop
= 0;loop
< lenhash
;++loop
) {
76 if (lseek(fd
,(off_t
) (pos
+ 8 * h2
),SEEK_SET
) == -1) return -1;
77 if (cdb_bread(fd
,packbuf
,8) == -1) return -1;
78 poskd
= cdb_unpack(packbuf
+ 4);
80 if (cdb_unpack(packbuf
) == h
) {
81 if (lseek(fd
,(off_t
) poskd
,SEEK_SET
) == -1) return -1;
82 if (cdb_bread(fd
,packbuf
,8) == -1) return -1;
83 if (cdb_unpack(packbuf
) == len
)
84 switch(match(fd
,key
,len
)) {
88 *dlen
= cdb_unpack(packbuf
+ 4);
92 if (++h2
== lenhash
) h2
= 0;