1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | //**************************************************************************/ |
---|
6 | // |
---|
7 | // |
---|
8 | //**************************************************************************/ |
---|
9 | // 'ndbm.cc' containes all low-level functions to manipulate dbm-files |
---|
10 | // for the original Copyright of this file and 'ndbm.h' see below . |
---|
11 | // |
---|
12 | // some minor change where needed to compile and run under MacOS/MPW |
---|
13 | // |
---|
14 | //**************************************************************************/ |
---|
15 | |
---|
16 | #include "config.h" |
---|
17 | #include <kernel/mod2.h> |
---|
18 | #ifdef HAVE_DBM |
---|
19 | #ifndef HPUX_9 |
---|
20 | #include <strings.h> |
---|
21 | #endif |
---|
22 | /* |
---|
23 | * Copyright (c) 1983 Regents of the University of California. |
---|
24 | * All rights reserved. The Berkeley software License Agreement |
---|
25 | * specifies the terms and conditions for redistribution. |
---|
26 | * for details see ndbm.h |
---|
27 | */ |
---|
28 | |
---|
29 | #if defined(LIBC_SCCS) && !defined(lint) |
---|
30 | static char sccsid[] = "@(#)ndbm.c 5.3 (Berkeley) 3/9/86"; |
---|
31 | #endif |
---|
32 | |
---|
33 | //**************************************************************************/ |
---|
34 | |
---|
35 | #include <stdio.h> |
---|
36 | /* alternative: |
---|
37 | * # define EPERM 1 |
---|
38 | * # define ENOMEM 23 |
---|
39 | * # define ENOSPC 28 |
---|
40 | * # define L_SET SEEK_SET |
---|
41 | */ |
---|
42 | #include <sys/types.h> |
---|
43 | #include <sys/stat.h> |
---|
44 | #include <sys/file.h> |
---|
45 | #include <errno.h> |
---|
46 | #include <stdlib.h> |
---|
47 | #include <string.h> |
---|
48 | #include <unistd.h> |
---|
49 | #include <fcntl.h> |
---|
50 | #ifndef HAVE_BCOPY |
---|
51 | # define bcopy(a,b,c) memmove(b,a,c) |
---|
52 | #endif /* not HAVE_BCOPY */ |
---|
53 | #include <Singular/links/ndbm.h> |
---|
54 | |
---|
55 | #define BYTESIZ 8 |
---|
56 | #undef setbit |
---|
57 | |
---|
58 | static void dbm_access(register DBM *db, long hash); |
---|
59 | static int getbit(register DBM *db); |
---|
60 | static void setbit(register DBM *db); |
---|
61 | static datum makdatum(char buf[PBLKSIZ], int n); |
---|
62 | static int finddatum(char buf[PBLKSIZ], datum item); |
---|
63 | static long dcalchash(datum item); |
---|
64 | static int delitem(char buf[PBLKSIZ], int n); |
---|
65 | static int additem(char buf[PBLKSIZ], datum item, datum item1); |
---|
66 | // extern int errno; |
---|
67 | extern "C" int singular_fstat(int fd, struct stat *buf); |
---|
68 | |
---|
69 | DBM * dbm_open(char *file, int flags, int mode) |
---|
70 | { |
---|
71 | struct stat statb; |
---|
72 | register DBM *db; |
---|
73 | |
---|
74 | if ((db = (DBM *)malloc(sizeof *db)) == 0) |
---|
75 | { |
---|
76 | errno = ENOMEM; |
---|
77 | return ((DBM *)0); |
---|
78 | } |
---|
79 | #ifdef MSDOS |
---|
80 | // default mode of open is ascii, we need binary mode. |
---|
81 | flags |= O_BINARY; |
---|
82 | #endif |
---|
83 | db->dbm_flags = (flags & 03) == O_RDONLY ? _DBM_RDONLY : 0; |
---|
84 | if ((flags & 03) == O_WRONLY) |
---|
85 | flags = (flags & ~03) | O_RDWR; |
---|
86 | strcpy(db->dbm_pagbuf, file); |
---|
87 | strcat(db->dbm_pagbuf, ".pag"); |
---|
88 | db->dbm_pagf = open(db->dbm_pagbuf, flags, mode); |
---|
89 | if (db->dbm_pagf < 0) |
---|
90 | goto bad; |
---|
91 | strcpy(db->dbm_pagbuf, file); |
---|
92 | strcat(db->dbm_pagbuf, ".dir"); |
---|
93 | db->dbm_dirf = open(db->dbm_pagbuf, flags, mode); |
---|
94 | if (db->dbm_dirf < 0) |
---|
95 | goto bad1; |
---|
96 | singular_fstat(db->dbm_dirf, &statb); |
---|
97 | db->dbm_maxbno = statb.st_size*BYTESIZ-1; |
---|
98 | db->dbm_pagbno = db->dbm_dirbno = -1; |
---|
99 | return (db); |
---|
100 | bad1: |
---|
101 | (void) close(db->dbm_pagf); |
---|
102 | bad: |
---|
103 | free((char *)db); |
---|
104 | return ((DBM *)0); |
---|
105 | } |
---|
106 | |
---|
107 | void dbm_close(DBM *db) |
---|
108 | { |
---|
109 | (void) close(db->dbm_dirf); |
---|
110 | (void) close(db->dbm_pagf); |
---|
111 | free((char *)db); |
---|
112 | } |
---|
113 | |
---|
114 | long dbm_forder(register DBM *db, datum key) |
---|
115 | { |
---|
116 | long hash; |
---|
117 | |
---|
118 | hash = dcalchash(key); |
---|
119 | for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1) |
---|
120 | { |
---|
121 | db->dbm_blkno = hash & db->dbm_hmask; |
---|
122 | db->dbm_bitno = db->dbm_blkno + db->dbm_hmask; |
---|
123 | if (getbit(db) == 0) |
---|
124 | break; |
---|
125 | } |
---|
126 | return (db->dbm_blkno); |
---|
127 | } |
---|
128 | |
---|
129 | datum dbm_fetch(register DBM *db, datum key) |
---|
130 | { |
---|
131 | register int i; |
---|
132 | datum item; |
---|
133 | |
---|
134 | if (dbm_error(db)) |
---|
135 | goto err; |
---|
136 | dbm_access(db, dcalchash(key)); |
---|
137 | if ((i = finddatum(db->dbm_pagbuf, key)) >= 0) |
---|
138 | { |
---|
139 | item = makdatum(db->dbm_pagbuf, i+1); |
---|
140 | if (item.dptr != NULL) |
---|
141 | return (item); |
---|
142 | } |
---|
143 | err: |
---|
144 | item.dptr = NULL; |
---|
145 | item.dsize = 0; |
---|
146 | return (item); |
---|
147 | } |
---|
148 | |
---|
149 | int dbm_delete(register DBM *db, datum key) |
---|
150 | { |
---|
151 | register int i; |
---|
152 | datum item; |
---|
153 | |
---|
154 | if (dbm_error(db)) |
---|
155 | return (-1); |
---|
156 | if (dbm_rdonly(db)) |
---|
157 | { |
---|
158 | errno = EPERM; |
---|
159 | return (-1); |
---|
160 | } |
---|
161 | dbm_access(db, dcalchash(key)); |
---|
162 | if ((i = finddatum(db->dbm_pagbuf, key)) < 0) |
---|
163 | return (-1); |
---|
164 | if (!delitem(db->dbm_pagbuf, i)) |
---|
165 | goto err; |
---|
166 | db->dbm_pagbno = db->dbm_blkno; |
---|
167 | (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET); |
---|
168 | if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) |
---|
169 | { |
---|
170 | err: |
---|
171 | db->dbm_flags |= _DBM_IOERR; |
---|
172 | return (-1); |
---|
173 | } |
---|
174 | return (0); |
---|
175 | } |
---|
176 | |
---|
177 | int dbm_store(register DBM *db, datum key, datum dat, int replace) |
---|
178 | { |
---|
179 | register int i; |
---|
180 | int ret; |
---|
181 | datum item, item1; |
---|
182 | char ovfbuf[PBLKSIZ]; |
---|
183 | |
---|
184 | if (dbm_error(db)) |
---|
185 | return (-1); |
---|
186 | if (dbm_rdonly(db)) |
---|
187 | { |
---|
188 | errno = EPERM; |
---|
189 | return (-1); |
---|
190 | } |
---|
191 | |
---|
192 | _loop: |
---|
193 | dbm_access(db, dcalchash(key)); |
---|
194 | if ((i = finddatum(db->dbm_pagbuf, key)) >= 0) |
---|
195 | { |
---|
196 | if (!replace) |
---|
197 | return (1); |
---|
198 | if (!delitem(db->dbm_pagbuf, i)) |
---|
199 | { |
---|
200 | db->dbm_flags |= _DBM_IOERR; |
---|
201 | return (-1); |
---|
202 | } |
---|
203 | } |
---|
204 | if (!additem(db->dbm_pagbuf, key, dat)) |
---|
205 | goto split; |
---|
206 | db->dbm_pagbno = db->dbm_blkno; |
---|
207 | (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET); |
---|
208 | if ( (ret=write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ)) != PBLKSIZ) |
---|
209 | { |
---|
210 | db->dbm_flags |= _DBM_IOERR; |
---|
211 | return (-1); |
---|
212 | } |
---|
213 | return (0); |
---|
214 | |
---|
215 | split: |
---|
216 | if (key.dsize+dat.dsize+3*sizeof(short) >= PBLKSIZ) |
---|
217 | { |
---|
218 | db->dbm_flags |= _DBM_IOERR; |
---|
219 | errno = ENOSPC; |
---|
220 | return (-1); |
---|
221 | } |
---|
222 | memset(ovfbuf, 0, PBLKSIZ); |
---|
223 | for (i=0;;) { |
---|
224 | item = makdatum(db->dbm_pagbuf, i); |
---|
225 | if (item.dptr == NULL) |
---|
226 | break; |
---|
227 | if (dcalchash(item) & (db->dbm_hmask+1)) |
---|
228 | { |
---|
229 | item1 = makdatum(db->dbm_pagbuf, i+1); |
---|
230 | if (item1.dptr == NULL) { |
---|
231 | fprintf(stderr, "ndbm: split not paired\n"); |
---|
232 | db->dbm_flags |= _DBM_IOERR; |
---|
233 | break; |
---|
234 | } |
---|
235 | if (!additem(ovfbuf, item, item1) || |
---|
236 | !delitem(db->dbm_pagbuf, i)) |
---|
237 | { |
---|
238 | db->dbm_flags |= _DBM_IOERR; |
---|
239 | return (-1); |
---|
240 | } |
---|
241 | continue; |
---|
242 | } |
---|
243 | i += 2; |
---|
244 | } |
---|
245 | db->dbm_pagbno = db->dbm_blkno; |
---|
246 | (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET); |
---|
247 | if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) |
---|
248 | { |
---|
249 | db->dbm_flags |= _DBM_IOERR; |
---|
250 | return (-1); |
---|
251 | } |
---|
252 | (void) lseek(db->dbm_pagf, (db->dbm_blkno+db->dbm_hmask+1)*PBLKSIZ, L_SET); |
---|
253 | if (write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ) |
---|
254 | { |
---|
255 | db->dbm_flags |= _DBM_IOERR; |
---|
256 | return (-1); |
---|
257 | } |
---|
258 | setbit(db); |
---|
259 | goto _loop; |
---|
260 | } |
---|
261 | |
---|
262 | datum dbm_firstkey(DBM *db) |
---|
263 | { |
---|
264 | |
---|
265 | db->dbm_blkptr = 0L; |
---|
266 | db->dbm_keyptr = 0; |
---|
267 | return (dbm_nextkey(db)); |
---|
268 | } |
---|
269 | |
---|
270 | datum dbm_nextkey(register DBM *db) |
---|
271 | { |
---|
272 | struct stat statb; |
---|
273 | datum item; |
---|
274 | |
---|
275 | if (dbm_error(db) |
---|
276 | || singular_fstat(db->dbm_pagf, &statb) < 0 |
---|
277 | ) |
---|
278 | goto err; |
---|
279 | statb.st_size /= PBLKSIZ; |
---|
280 | for (;;) |
---|
281 | { |
---|
282 | if (db->dbm_blkptr != db->dbm_pagbno) |
---|
283 | { |
---|
284 | db->dbm_pagbno = db->dbm_blkptr; |
---|
285 | (void) lseek(db->dbm_pagf, db->dbm_blkptr*PBLKSIZ, L_SET); |
---|
286 | if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) |
---|
287 | memset(db->dbm_pagbuf, 0, PBLKSIZ); |
---|
288 | #ifdef DEBUG |
---|
289 | else if (chkblk(db->dbm_pagbuf) < 0) |
---|
290 | db->dbm_flags |= _DBM_IOERR; |
---|
291 | #endif |
---|
292 | } |
---|
293 | short tmp; |
---|
294 | memcpy(&tmp, db->dbm_pagbuf, sizeof(short)); |
---|
295 | if (tmp != 0) |
---|
296 | { |
---|
297 | item = makdatum(db->dbm_pagbuf, db->dbm_keyptr); |
---|
298 | if (item.dptr != NULL) |
---|
299 | { |
---|
300 | db->dbm_keyptr += 2; |
---|
301 | return (item); |
---|
302 | } |
---|
303 | db->dbm_keyptr = 0; |
---|
304 | } |
---|
305 | if (++db->dbm_blkptr >= statb.st_size) |
---|
306 | break; |
---|
307 | } |
---|
308 | err: |
---|
309 | item.dptr = NULL; |
---|
310 | item.dsize = 0; |
---|
311 | return (item); |
---|
312 | } |
---|
313 | |
---|
314 | static void dbm_access(register DBM *db, long hash) |
---|
315 | { |
---|
316 | for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1) |
---|
317 | { |
---|
318 | db->dbm_blkno = hash & db->dbm_hmask; |
---|
319 | db->dbm_bitno = db->dbm_blkno + db->dbm_hmask; |
---|
320 | if (getbit(db) == 0) |
---|
321 | break; |
---|
322 | } |
---|
323 | if (db->dbm_blkno != db->dbm_pagbno) |
---|
324 | { |
---|
325 | db->dbm_pagbno = db->dbm_blkno; |
---|
326 | (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET); |
---|
327 | if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) |
---|
328 | memset(db->dbm_pagbuf, 0, PBLKSIZ); |
---|
329 | #ifdef DEBUG |
---|
330 | else if (chkblk(db->dbm_pagbuf) < 0) |
---|
331 | db->dbm_flags |= _DBM_IOERR; |
---|
332 | #endif |
---|
333 | } |
---|
334 | } |
---|
335 | |
---|
336 | static int getbit(register DBM *db) |
---|
337 | { |
---|
338 | long bn; |
---|
339 | register int b, i, n; |
---|
340 | |
---|
341 | |
---|
342 | if (db->dbm_bitno > db->dbm_maxbno) |
---|
343 | return (0); |
---|
344 | n = db->dbm_bitno % BYTESIZ; |
---|
345 | bn = db->dbm_bitno / BYTESIZ; |
---|
346 | i = bn % DBLKSIZ; |
---|
347 | b = bn / DBLKSIZ; |
---|
348 | if (b != db->dbm_dirbno) |
---|
349 | { |
---|
350 | db->dbm_dirbno = b; |
---|
351 | (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET); |
---|
352 | if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) |
---|
353 | memset(db->dbm_dirbuf, 0, DBLKSIZ); |
---|
354 | } |
---|
355 | return (db->dbm_dirbuf[i] & (1<<n)); |
---|
356 | } |
---|
357 | |
---|
358 | static void setbit(register DBM *db) |
---|
359 | { |
---|
360 | long bn; |
---|
361 | register int i, n, b; |
---|
362 | |
---|
363 | if (db->dbm_bitno > db->dbm_maxbno) |
---|
364 | db->dbm_maxbno = db->dbm_bitno; |
---|
365 | n = db->dbm_bitno % BYTESIZ; |
---|
366 | bn = db->dbm_bitno / BYTESIZ; |
---|
367 | i = bn % DBLKSIZ; |
---|
368 | b = bn / DBLKSIZ; |
---|
369 | if (b != db->dbm_dirbno) |
---|
370 | { |
---|
371 | db->dbm_dirbno = b; |
---|
372 | (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET); |
---|
373 | if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) |
---|
374 | memset(db->dbm_dirbuf, 0, DBLKSIZ); |
---|
375 | } |
---|
376 | db->dbm_dirbuf[i] |= 1<<n; |
---|
377 | db->dbm_dirbno = b; |
---|
378 | (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET); |
---|
379 | if (write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) |
---|
380 | db->dbm_flags |= _DBM_IOERR; |
---|
381 | } |
---|
382 | |
---|
383 | static datum makdatum(char buf[PBLKSIZ], int n) |
---|
384 | { |
---|
385 | register short *sp; |
---|
386 | register int t; |
---|
387 | datum item; |
---|
388 | |
---|
389 | sp = (short *)buf; |
---|
390 | if ((unsigned)n >= (unsigned)sp[0]) |
---|
391 | { |
---|
392 | item.dptr = NULL; |
---|
393 | item.dsize = 0; |
---|
394 | return (item); |
---|
395 | } |
---|
396 | t = PBLKSIZ; |
---|
397 | if (n > 0) |
---|
398 | t = sp[n]; |
---|
399 | item.dptr = buf+sp[n+1]; |
---|
400 | item.dsize = t - sp[n+1]; |
---|
401 | return (item); |
---|
402 | } |
---|
403 | |
---|
404 | static int finddatum(char buf[PBLKSIZ], datum item) |
---|
405 | { |
---|
406 | register short *sp; |
---|
407 | register int i, n, j; |
---|
408 | |
---|
409 | sp = (short *)buf; |
---|
410 | n = PBLKSIZ; |
---|
411 | for (i=0, j=sp[0]; i<j; i+=2, n = sp[i]) |
---|
412 | { |
---|
413 | n -= sp[i+1]; |
---|
414 | if (n != item.dsize) |
---|
415 | continue; |
---|
416 | if (n == 0 || memcmp(&buf[sp[i+1]], item.dptr, n) == 0) |
---|
417 | return (i); |
---|
418 | } |
---|
419 | return (-1); |
---|
420 | } |
---|
421 | |
---|
422 | static int hitab[16] |
---|
423 | /* ken's |
---|
424 | { |
---|
425 | 055,043,036,054,063,014,004,005, |
---|
426 | 010,064,077,000,035,027,025,071, |
---|
427 | }; |
---|
428 | */ |
---|
429 | = { 61, 57, 53, 49, 45, 41, 37, 33, |
---|
430 | 29, 25, 21, 17, 13, 9, 5, 1, |
---|
431 | }; |
---|
432 | static unsigned long hltab[64] |
---|
433 | = { |
---|
434 | 06100151277L,06106161736L,06452611562L,05001724107L, |
---|
435 | 02614772546L,04120731531L,04665262210L,07347467531L, |
---|
436 | 06735253126L,06042345173L,03072226605L,01464164730L, |
---|
437 | 03247435524L,07652510057L,01546775256L,05714532133L, |
---|
438 | 06173260402L,07517101630L,02431460343L,01743245566L, |
---|
439 | 00261675137L,02433103631L,03421772437L,04447707466L, |
---|
440 | 04435620103L,03757017115L,03641531772L,06767633246L, |
---|
441 | 02673230344L,00260612216L,04133454451L,00615531516L, |
---|
442 | 06137717526L,02574116560L,02304023373L,07061702261L, |
---|
443 | 05153031405L,05322056705L,07401116734L,06552375715L, |
---|
444 | 06165233473L,05311063631L,01212221723L,01052267235L, |
---|
445 | 06000615237L,01075222665L,06330216006L,04402355630L, |
---|
446 | 01451177262L,02000133436L,06025467062L,07121076461L, |
---|
447 | 03123433522L,01010635225L,01716177066L,05161746527L, |
---|
448 | 01736635071L,06243505026L,03637211610L,01756474365L, |
---|
449 | 04723077174L,03642763134L,05750130273L,03655541561L, |
---|
450 | }; |
---|
451 | |
---|
452 | static long dcalchash(datum item) |
---|
453 | { |
---|
454 | register int s, c, j; |
---|
455 | register char *cp; |
---|
456 | register unsigned long hashl; |
---|
457 | register unsigned int hashi; |
---|
458 | |
---|
459 | hashl = 0; |
---|
460 | hashi = 0; |
---|
461 | for (cp = item.dptr, s=item.dsize; --s >= 0; ) |
---|
462 | { |
---|
463 | c = *cp++; |
---|
464 | for (j=0; j<BYTESIZ; j+=4) |
---|
465 | { |
---|
466 | hashi += hitab[c&017]; |
---|
467 | hashl += hltab[hashi&63]; |
---|
468 | c >>= 4; |
---|
469 | } |
---|
470 | } |
---|
471 | return (long)(hashl); |
---|
472 | } |
---|
473 | |
---|
474 | /* |
---|
475 | * Delete pairs of items (n & n+1). |
---|
476 | */ |
---|
477 | static int delitem(char buf[PBLKSIZ], int n) |
---|
478 | { |
---|
479 | register short *sp, *sp1; |
---|
480 | register int i1, i2; |
---|
481 | |
---|
482 | sp = (short *)buf; |
---|
483 | i2 = sp[0]; |
---|
484 | if ((unsigned)n >= (unsigned)i2 || (n & 1)) |
---|
485 | return (0); |
---|
486 | if (n == i2-2) |
---|
487 | { |
---|
488 | sp[0] -= 2; |
---|
489 | return (1); |
---|
490 | } |
---|
491 | i1 = PBLKSIZ; |
---|
492 | if (n > 0) |
---|
493 | i1 = sp[n]; |
---|
494 | i1 -= sp[n+2]; |
---|
495 | if (i1 > 0) |
---|
496 | { |
---|
497 | i2 = sp[i2]; |
---|
498 | bcopy(&buf[i2], &buf[i2 + i1], sp[n+2] - i2); |
---|
499 | } |
---|
500 | sp[0] -= 2; |
---|
501 | for (sp1 = sp + sp[0], sp += n+1; sp <= sp1; sp++) |
---|
502 | sp[0] = sp[2] + i1; |
---|
503 | return (1); |
---|
504 | } |
---|
505 | |
---|
506 | /* |
---|
507 | * Add pairs of items (item & item1). |
---|
508 | */ |
---|
509 | static int additem(char buf[PBLKSIZ], datum item, datum item1) |
---|
510 | { |
---|
511 | register short *sp; |
---|
512 | register int i1, i2, tmp; |
---|
513 | |
---|
514 | sp = (short *)buf; |
---|
515 | i1 = PBLKSIZ; |
---|
516 | i2 = sp[0]; |
---|
517 | if (i2 > 0) |
---|
518 | i1 = sp[i2]; |
---|
519 | i1 -= item.dsize + item1.dsize; |
---|
520 | tmp = (i2+3) * sizeof(short); |
---|
521 | if (i1 <= tmp) return (0); |
---|
522 | sp[0] += 2; |
---|
523 | sp[++i2] = i1 + item1.dsize; |
---|
524 | bcopy(item.dptr, &buf[i1 + item1.dsize], item.dsize); |
---|
525 | sp[++i2] = i1; |
---|
526 | bcopy(item1.dptr, &buf[i1], item1.dsize); |
---|
527 | return (1); |
---|
528 | } |
---|
529 | |
---|
530 | #ifdef DEBUG |
---|
531 | static chkblk(char buf[PBLKSIZ]) |
---|
532 | { |
---|
533 | register short *sp; |
---|
534 | register t, i; |
---|
535 | |
---|
536 | sp = (short *)buf; |
---|
537 | t = PBLKSIZ; |
---|
538 | for (i=0; i<sp[0]; i++) |
---|
539 | { |
---|
540 | if (sp[i+1] > t) |
---|
541 | return (-1); |
---|
542 | t = sp[i+1]; |
---|
543 | } |
---|
544 | if (t < (sp[0]+1)*sizeof(short)) |
---|
545 | return (-1); |
---|
546 | return (0); |
---|
547 | } |
---|
548 | #endif |
---|
549 | |
---|
550 | #endif /* HAVE_DBM */ |
---|