/[LeafOK_CVS]/pvpgn-1.7.4/src/tinycdb/cdb_make_add.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/tinycdb/cdb_make_add.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
CVS Tags: pvpgn_1-7-4-0_MIL
Branch point for: GNU, MAIN
Content type: text/x-csrc
Initial revision

1 sysadm 1.1 /* basic cdb_make_add routine
2     *
3     * This file is a part of tinycdb package by Michael Tokarev, mjt@corpit.ru.
4     * Public domain.
5     */
6    
7     #include "common/setup_before.h"
8     #ifdef STDC_HEADERS
9     # include <stdlib.h>
10     #else
11     # ifdef HAVE_MALLOC_H
12     # include <malloc.h>
13     # endif
14     #endif
15     #include "common/xalloc.h"
16     #include "cdb_int.h"
17     #include "common/setup_after.h"
18    
19     int
20     cdb_make_add(struct cdb_make *cdbmp,
21     const void *key, unsigned klen,
22     const void *val, unsigned vlen)
23     {
24     unsigned char rlen[8];
25     unsigned hval;
26     struct cdb_rl *rl;
27     if (klen > 0xffffffff - (cdbmp->cdb_dpos + 8) ||
28     vlen > 0xffffffff - (cdbmp->cdb_dpos + klen + 8))
29     return errno = ENOMEM, -1;
30     hval = cdb_hash(key, klen);
31     rl = cdbmp->cdb_rec[hval&255];
32     if (!rl || rl->cnt >= sizeof(rl->rec)/sizeof(rl->rec[0])) {
33     rl = (struct cdb_rl*)xmalloc(sizeof(struct cdb_rl));
34     if (!rl)
35     return errno = ENOMEM, -1;
36     rl->cnt = 0;
37     rl->next = cdbmp->cdb_rec[hval&255];
38     cdbmp->cdb_rec[hval&255] = rl;
39     }
40     rl->rec[rl->cnt].hval = hval;
41     rl->rec[rl->cnt].rpos = cdbmp->cdb_dpos;
42     ++rl->cnt;
43     ++cdbmp->cdb_rcnt;
44     cdb_pack(klen, rlen);
45     cdb_pack(vlen, rlen + 4);
46     if (_cdb_make_write(cdbmp, rlen, 8) < 0 ||
47     _cdb_make_write(cdbmp, key, klen) < 0 ||
48     _cdb_make_write(cdbmp, val, vlen) < 0)
49     return -1;
50     return 0;
51     }
52    

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1