Lines Matching refs:c
41 static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz) { in cdb_make_write() argument
42 return php_stream_write(c->fp, buf, sz) == sz ? 0 : -1; in cdb_make_write()
46 static int cdb_posplus(struct cdb_make *c, uint32 len) in cdb_posplus() argument
48 uint32 newpos = c->pos + len; in cdb_posplus()
53 c->pos = newpos; in cdb_posplus()
59 int cdb_make_start(struct cdb_make *c, php_stream * f) in cdb_make_start() argument
61 c->head = 0; in cdb_make_start()
62 c->split = 0; in cdb_make_start()
63 c->hash = 0; in cdb_make_start()
64 c->numentries = 0; in cdb_make_start()
65 c->fp = f; in cdb_make_start()
66 c->pos = sizeof(c->final); in cdb_make_start()
67 if (php_stream_seek(f, c->pos, SEEK_SET) == -1) { in cdb_make_start()
71 return php_stream_tell(c->fp); in cdb_make_start()
76 int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h) in cdb_make_addend() argument
80 head = c->head; in cdb_make_addend()
86 head->next = c->head; in cdb_make_addend()
87 c->head = head; in cdb_make_addend()
90 head->hp[head->num].p = c->pos; in cdb_make_addend()
92 ++c->numentries; in cdb_make_addend()
93 if (cdb_posplus(c,8) == -1) in cdb_make_addend()
95 if (cdb_posplus(c, keylen) == -1) in cdb_make_addend()
97 if (cdb_posplus(c, datalen) == -1) in cdb_make_addend()
104 int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen) in cdb_make_addbegin() argument
119 if (cdb_make_write(c, buf, 8) != 0) in cdb_make_addbegin()
125 int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) in cdb_make_add() argument
127 if (cdb_make_addbegin(c, keylen, datalen) == -1) in cdb_make_add()
129 if (cdb_make_write(c, key, keylen) != 0) in cdb_make_add()
131 if (cdb_make_write(c, data, datalen) != 0) in cdb_make_add()
133 return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen)); in cdb_make_add()
138 int cdb_make_finish(struct cdb_make *c) in cdb_make_finish() argument
151 c->count[i] = 0; in cdb_make_finish()
153 for (x = c->head; x; x = x->next) { in cdb_make_finish()
156 ++c->count[255 & x->hp[i].h]; in cdb_make_finish()
161 u = c->count[i] * 2; in cdb_make_finish()
166 memsize += c->numentries; /* no overflow possible up to now */ in cdb_make_finish()
174 c->split = (struct cdb_hp *) safe_emalloc(memsize, sizeof(struct cdb_hp), 0); in cdb_make_finish()
175 if (!c->split) in cdb_make_finish()
178 c->hash = c->split + c->numentries; in cdb_make_finish()
182 u += c->count[i]; /* bounded by numentries, so no overflow */ in cdb_make_finish()
183 c->start[i] = u; in cdb_make_finish()
186 for (x = c->head; x; x = x->next) { in cdb_make_finish()
189 c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; in cdb_make_finish()
193 count = c->count[i]; in cdb_make_finish()
196 uint32_pack(c->final + 8 * i,c->pos); in cdb_make_finish()
197 uint32_pack(c->final + 8 * i + 4,len); in cdb_make_finish()
200 c->hash[u].h = c->hash[u].p = 0; in cdb_make_finish()
202 hp = c->split + c->start[i]; in cdb_make_finish()
205 while (c->hash[where].p) in cdb_make_finish()
208 c->hash[where] = *hp++; in cdb_make_finish()
212 uint32_pack(buf, c->hash[u].h); in cdb_make_finish()
213 uint32_pack(buf + 4, c->hash[u].p); in cdb_make_finish()
214 if (cdb_make_write(c, buf, 8) != 0) in cdb_make_finish()
216 if (cdb_posplus(c, 8) == -1) in cdb_make_finish()
221 if (c->split) in cdb_make_finish()
222 efree(c->split); in cdb_make_finish()
224 for (x = c->head; x; c->head = x) { in cdb_make_finish()
226 efree(c->head); in cdb_make_finish()
229 if (php_stream_flush(c->fp) != 0) in cdb_make_finish()
231 php_stream_rewind(c->fp); in cdb_make_finish()
232 if (php_stream_tell(c->fp) != 0) in cdb_make_finish()
234 if (cdb_make_write(c, c->final, sizeof(c->final)) != 0) in cdb_make_finish()
236 return php_stream_flush(c->fp); in cdb_make_finish()