1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <gdbm.h>
#include <fcntl.h>
typedef GDBM_FILE GDBM_File;
#define gdbm_new(dbtype,filename,flags,mode) \
gdbm_open(filename, 0, flags & O_CREAT ? GDBM_WRCREAT : GDBM_WRITER, \
mode, fatal)
typedef datum gdatum;
typedef struct gdbm_file_desc {
GDBM_File ptr;
SV* curkey;
} GDBM_FILE_DESC;
GDBM_FILE_DESC* GDBM_File_desc;
GDBM_FILE_DESC*
newGDBM_FILE_DESC(ptr)
void* ptr;
{
New(0, GDBM_File_desc, 1, GDBM_FILE_DESC);
GDBM_File_desc->ptr = ptr;
GDBM_File_desc->curkey = 0;
return GDBM_File_desc;
}
void
deleteGDBM_FILE_DESC()
{
sv_free(GDBM_File_desc->curkey);
Safefree(GDBM_File_desc);
}
typedef void (*FATALFUNC)();
static datum
get_current_key()
{
datum key;
key.dptr = SvPVn( GDBM_File_desc->curkey, key.dsize);
return key;
}
static void
set_current_key(sv)
SV *sv;
{
sv_free(GDBM_File_desc->curkey);
GDBM_File_desc->curkey = sv_ref(sv);
}
MODULE = GDBM_File PACKAGE = GDBM_File PREFIX = gdbm_
GDBM_File
gdbm_new(dbtype, filename, flags, mode)
char * dbtype
char * filename
int flags
int mode
GDBM_File
gdbm_open(name, block_size, read_write, mode, fatal_func = (FATALFUNC)fatal)
char * name
int block_size
int read_write
int mode
FATALFUNC fatal_func
void
gdbm_close(db)
GDBM_File db
CLEANUP:
deleteGDBM_FILE_DESC();
void
gdbm_DESTROY(db)
GDBM_File db
CODE:
gdbm_close(db);
deleteGDBM_FILE_DESC();
gdatum
gdbm_fetch(db, key)
GDBM_File db
datum key
int
gdbm_store(db, key, value, flags = GDBM_REPLACE)
GDBM_File db
datum key
datum value
int flags
int
gdbm_delete(db, key)
GDBM_File db
datum key
gdatum
gdbm_firstkey(db)
GDBM_File db
CLEANUP:
set_current_key(ST(0));
gdatum
gdbm_nextkey(db, key = get_current_key())
GDBM_File db
datum key
CLEANUP:
set_current_key(ST(0));
int
gdbm_reorganize(db)
GDBM_File db
|