21 static int posplus(
struct cdb_make *c,uint32 len)
23 uint32 newpos = c->
pos + len;
24 if (newpos < len) { errno =
error_nomem;
return -1; }
45 if (posplus(c,8) == -1)
return -1;
46 if (posplus(c,keylen) == -1)
return -1;
47 if (posplus(c,datalen) == -1)
return -1;
55 if (keylen > 0xffffffff) { errno =
error_nomem;
return -1; }
56 if (datalen > 0xffffffff) { errno =
error_nomem;
return -1; }
64 int cdb_make_add(
struct cdb_make *c,
const char *key,
unsigned int keylen,
const char *data,
unsigned int datalen)
84 for (i = 0;i < 256;++i)
94 for (i = 0;i < 256;++i) {
101 u = (uint32) 0 - (uint32) 1;
102 u /=
sizeof(
struct cdb_hp);
103 if (memsize > u) { errno =
error_nomem;
return -1; }
106 if (!c->
split)
return -1;
111 for (i = 0;i < 256;++i) {
122 for (i = 0;i < 256;++i) {
129 for (u = 0;u < len;++u)
133 for (u = 0;u < count;++u) {
134 where = (hp->
h >> 8) % len;
135 while (c->
hash[where].
p)
138 c->
hash[where] = *hp++;
141 for (u = 0;u < len;++u) {
145 if (posplus(c,8) == -1)
return -1;
char * alloc(unsigned int n)
struct cdb_hp hp[CDB_HPLIST]
int buffer_unixwrite(int, const char *, unsigned int)
void uint32_pack(char s[4], uint32 u)
int cdb_make_add(struct cdb_make *c, const char *key, unsigned int keylen, const char *data, unsigned int datalen)
int cdb_make_start(struct cdb_make *c, int fd)
void buffer_init(buffer *s, int(*op)(), int fd, char *buf, unsigned int len)
int buffer_putalign(buffer *, const char *, unsigned int)
int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen)
int seek_set(int, seek_pos)
int buffer_putflush(buffer *, const char *, unsigned int)
int cdb_make_finish(struct cdb_make *c)
int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h)
int buffer_flush(buffer *)
uint32 cdb_hash(const char *, unsigned int)