fix buffer handling botch for logging "to" addresses to same
[unix-history] / usr / src / old / libndbm / dbm.c
CommitLineData
fea1cabb
JB
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
06c51eed 7#ifndef lint
ac2e7cc8 8static char sccsid[] = "@(#)dbm.c 5.3 (Berkeley) 85/08/15";
fea1cabb 9#endif not lint
06c51eed
RE
10
11#include "dbm.h"
12
13#define NODB ((DBM *)0)
14
15static DBM *cur_db = NODB;
16
17static char no_db[] = "dbm: no open database\n";
18
19dbminit(file)
20 char *file;
21{
22 if (cur_db != NODB)
23 dbm_close(cur_db);
24
25 cur_db = dbm_open(file, 2, 0);
26 if (cur_db == NODB) {
27 cur_db = dbm_open(file, 0, 0);
ac2e7cc8
RE
28 if (cur_db == NODB)
29 return (-1);
06c51eed
RE
30 }
31 return (0);
32}
33
34long
35forder(key)
36datum key;
37{
38 if (cur_db == NODB) {
39 printf(no_db);
40 return (0L);
41 }
42 return (dbm_forder(cur_db, key));
43}
44
45datum
46fetch(key)
47datum key;
48{
49 datum item;
50
51 if (cur_db == NODB) {
52 printf(no_db);
53 item.dptr = 0;
54 return (item);
55 }
56 return (dbm_fetch(cur_db, key));
57}
58
59delete(key)
60datum key;
61{
62 if (cur_db == NODB) {
63 printf(no_db);
64 return (-1);
65 }
66 if (dbm_rdonly(cur_db))
67 return (-1);
68 return (dbm_delete(cur_db, key));
69}
70
71store(key, dat)
72datum key, dat;
73{
74 if (cur_db == NODB) {
75 printf(no_db);
76 return (-1);
77 }
78 if (dbm_rdonly(cur_db))
79 return (-1);
80
81 return (dbm_store(cur_db, key, dat, DBM_REPLACE));
82}
83
84datum
85firstkey()
86{
87 datum item;
88
89 if (cur_db == NODB) {
90 printf(no_db);
91 item.dptr = 0;
92 return (item);
93 }
94 return (dbm_firstkey(cur_db));
95}
96
97datum
98nextkey(key)
99datum key;
100{
101 datum item;
102
103 if (cur_db == NODB) {
104 printf(no_db);
105 item.dptr = 0;
106 return (item);
107 }
108 return (dbm_nextkey(cur_db, key));
109}