Add cast to malloc to calm cc when system headers decalre int malloc()
[p5sagit/p5-mst-13.2.git] / ext / SDBM_File / sdbm / dbm.c
CommitLineData
463ee0b2 1/*
2 * Copyright (c) 1985 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18#ifndef lint
19static char sccsid[] = "@(#)dbm.c 5.4 (Berkeley) 5/24/89";
20#endif /* not lint */
21
22#include "dbm.h"
23
24#define NODB ((DBM *)0)
25
26static DBM *cur_db = NODB;
27
28static char no_db[] = "dbm: no open database\n";
29
30dbminit(file)
31 char *file;
32{
33 if (cur_db != NODB)
34 dbm_close(cur_db);
35
36 cur_db = dbm_open(file, 2, 0);
37 if (cur_db == NODB) {
38 cur_db = dbm_open(file, 0, 0);
39 if (cur_db == NODB)
40 return (-1);
41 }
42 return (0);
43}
44
45long
46forder(key)
47datum key;
48{
49 if (cur_db == NODB) {
50 printf(no_db);
51 return (0L);
52 }
53 return (dbm_forder(cur_db, key));
54}
55
56datum
57fetch(key)
58datum key;
59{
60 datum item;
61
62 if (cur_db == NODB) {
63 printf(no_db);
64 item.dptr = 0;
65 return (item);
66 }
67 return (dbm_fetch(cur_db, key));
68}
69
70delete(key)
71datum key;
72{
73 if (cur_db == NODB) {
74 printf(no_db);
75 return (-1);
76 }
77 if (dbm_rdonly(cur_db))
78 return (-1);
79 return (dbm_delete(cur_db, key));
80}
81
82store(key, dat)
83datum key, dat;
84{
85 if (cur_db == NODB) {
86 printf(no_db);
87 return (-1);
88 }
89 if (dbm_rdonly(cur_db))
90 return (-1);
91
92 return (dbm_store(cur_db, key, dat, DBM_REPLACE));
93}
94
95datum
96firstkey()
97{
98 datum item;
99
100 if (cur_db == NODB) {
101 printf(no_db);
102 item.dptr = 0;
103 return (item);
104 }
105 return (dbm_firstkey(cur_db));
106}
107
108datum
109nextkey(key)
110datum key;
111{
112 datum item;
113
114 if (cur_db == NODB) {
115 printf(no_db);
116 item.dptr = 0;
117 return (item);
118 }
119 return (dbm_nextkey(cur_db, key));
120}