~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/sdbm/_sdbm.c

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 */
9
9
 
10
10
#ifndef lint
11
 
/*char sdbm_rcsid[] = "$Id: _sdbm.c 27836 2010-05-16 12:15:36Z yugui $";*/
 
11
/*char sdbm_rcsid[] = "$Id: _sdbm.c 31176 2011-03-25 06:46:57Z naruse $";*/
12
12
#endif
13
13
 
14
14
#include "ruby/config.h"
30
30
 
31
31
#ifdef BSD42
32
32
#define SEEK_SET        L_SET
33
 
#define memset(s,c,n)   bzero(s, n)             /* only when c is zero */
34
 
#define memcpy(s1,s2,n) bcopy(s2, s1, n)
35
 
#define memcmp(s1,s2,n) bcmp(s1,s2,n)
 
33
#define memset(s,c,n)   bzero((s), (n))         /* only when c is zero */
 
34
#define memcpy(s1,s2,n) bcopy((s2), (s1), (n))
 
35
#define memcmp(s1,s2,n) bcmp((s1),(s2),(n))
36
36
#endif
37
37
 
38
38
/*
39
39
 * important tuning parms (hah)
40
40
 */
41
41
 
42
 
#define SEEDUPS         /* always detect duplicates */
43
 
#define BADMESS         /* generate a message for worst case:
 
42
#ifndef SEEDUPS
 
43
#define SEEDUPS 1       /* always detect duplicates */
 
44
#endif
 
45
#ifndef BADMESS
 
46
#define BADMESS 1       /* generate a message for worst case:
44
47
                           cannot make room after SPLTMAX splits */
 
48
#endif
 
49
 
45
50
/*
46
51
 * misc
47
52
 */
55
60
#define GET_SHORT(p, i) (((unsigned)((unsigned char *)(p))[(i)*2] << 8) + (((unsigned char *)(p))[(i)*2 + 1]))
56
61
#define PUT_SHORT(p, i, s) (((unsigned char *)(p))[(i)*2] = (unsigned char)((s) >> 8), ((unsigned char *)(p))[(i)*2 + 1] = (unsigned char)(s))
57
62
#else
58
 
#define GET_SHORT(p, i) ((p)[i])
59
 
#define PUT_SHORT(p, i, s)      ((p)[i] = (s))
 
63
#define GET_SHORT(p, i) ((p)[(i)])
 
64
#define PUT_SHORT(p, i, s)      ((p)[(i)] = (s))
60
65
#endif
61
66
 
62
67
/*#include "pair.h"*/
67
72
static int   chkpage proto((char *));
68
73
static datum getnkey proto((char *, int));
69
74
static void  splpage proto((char *, char *, long));
70
 
#ifdef SEEDUPS
 
75
#if SEEDUPS
71
76
static int   duppair proto((char *, datum));
72
77
#endif
73
78
 
150
155
        register DBM *db;
151
156
        register char *dirname;
152
157
        register char *pagname;
153
 
        register int n;
 
158
        register size_t n;
154
159
 
155
160
        if (file == NULL || !*file)
156
161
                return errno = EINVAL, (DBM *) NULL;
159
164
 */
160
165
        n = strlen(file) * 2 + strlen(DIRFEXT) + strlen(PAGFEXT) + 2;
161
166
 
162
 
        if ((dirname = malloc((unsigned) n)) == NULL)
 
167
        if ((dirname = malloc(n)) == NULL)
163
168
                return errno = ENOMEM, (DBM *) NULL;
164
169
/*
165
170
 * build the file names
302
307
 */
303
308
                if (flags == DBM_REPLACE)
304
309
                        (void) delpair(db->pagbuf, key);
305
 
#ifdef SEEDUPS
 
310
#if SEEDUPS
306
311
                else if (duppair(db->pagbuf, key))
307
312
                        return 1;
308
313
#endif
421
426
 * if we are here, this is real bad news. After SPLTMAX splits,
422
427
 * we still cannot fit the key. say goodnight.
423
428
 */
424
 
#ifdef BADMESS
425
 
        (void) write(2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44);
 
429
#if BADMESS
 
430
        (void) (write(2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44) < 0);
426
431
#endif
427
432
        return 0;
428
433
 
600
605
 */
601
606
 
602
607
#ifndef lint
603
 
/*char pair_rcsid[] = "$Id: _sdbm.c 27836 2010-05-16 12:15:36Z yugui $";*/
 
608
/*char pair_rcsid[] = "$Id: _sdbm.c 31176 2011-03-25 06:46:57Z naruse $";*/
604
609
#endif
605
610
 
606
611
#ifndef BSD42
698
703
        return val;
699
704
}
700
705
 
701
 
#ifdef SEEDUPS
 
706
#if SEEDUPS
702
707
static int
703
708
duppair(char *pag, datum key)
704
709
{
750
755
                register int m;
751
756
                register char *dst = pag + (i == 1 ? PBLKSIZ : GET_SHORT(ino,i - 1));
752
757
                register char *src = pag + GET_SHORT(ino,i + 1);
753
 
                register int   zoo = dst - src;
 
758
                register ptrdiff_t   zoo = dst - src;
754
759
 
755
 
                debug(("free-up %d ", zoo));
 
760
                debug(("free-up %"PRIdPTRDIFF" ", zoo));
756
761
/*
757
762
 * shift data/keys down
758
763
 */
861
866
        register int off;
862
867
        register short *ino = (short *) pag;
863
868
 
864
 
        if ((n = GET_SHORT(ino,0)) < 0 || n > PBLKSIZ / sizeof(short))
 
869
        if ((n = GET_SHORT(ino,0)) < 0 || n > PBLKSIZ / (int)sizeof(short))
865
870
                return 0;
866
871
 
867
872
        if (n > 0) {