This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix bad free in do_exec3()
[perl5.git] / ext / NDBM_File / NDBM_File.xs
CommitLineData
a0d0e21e
LW
1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4#include <ndbm.h>
5
9fe6733a
PM
6typedef struct {
7 DBM * dbp ;
8 SV * filter_fetch_key ;
9 SV * filter_store_key ;
10 SV * filter_fetch_value ;
11 SV * filter_store_value ;
12 int filtering ;
13 } NDBM_File_type;
14
15typedef NDBM_File_type * NDBM_File ;
16typedef datum datum_key ;
17typedef datum datum_value ;
18
049cc612 19MODULE = NDBM_File PACKAGE = NDBM_File PREFIX = ndbm_
a0d0e21e
LW
20
21NDBM_File
049cc612 22ndbm_TIEHASH(dbtype, filename, flags, mode)
a0d0e21e
LW
23 char * dbtype
24 char * filename
25 int flags
26 int mode
9fe6733a
PM
27 CODE:
28 {
29 DBM * dbp ;
30
31 RETVAL = NULL ;
8fa7f367 32 if ((dbp = dbm_open(filename, flags, mode))) {
9fe6733a
PM
33 RETVAL = (NDBM_File)safemalloc(sizeof(NDBM_File_type)) ;
34 Zero(RETVAL, 1, NDBM_File_type) ;
35 RETVAL->dbp = dbp ;
36 }
37
38 }
39 OUTPUT:
40 RETVAL
a0d0e21e
LW
41
42void
049cc612 43ndbm_DESTROY(db)
a0d0e21e
LW
44 NDBM_File db
45 CODE:
9fe6733a 46 dbm_close(db->dbp);
eb99164f 47 safefree(db);
a0d0e21e 48
049cc612 49#define ndbm_FETCH(db,key) dbm_fetch(db->dbp,key)
9fe6733a 50datum_value
049cc612 51ndbm_FETCH(db, key)
a0d0e21e 52 NDBM_File db
9fe6733a 53 datum_key key
a0d0e21e 54
049cc612 55#define ndbm_STORE(db,key,value,flags) dbm_store(db->dbp,key,value,flags)
a0d0e21e 56int
049cc612 57ndbm_STORE(db, key, value, flags = DBM_REPLACE)
a0d0e21e 58 NDBM_File db
9fe6733a
PM
59 datum_key key
60 datum_value value
a0d0e21e
LW
61 int flags
62 CLEANUP:
63 if (RETVAL) {
64 if (RETVAL < 0 && errno == EPERM)
65 croak("No write permission to ndbm file");
748a9306 66 croak("ndbm store returned %d, errno %d, key \"%s\"",
a0d0e21e 67 RETVAL,errno,key.dptr);
9fe6733a 68 dbm_clearerr(db->dbp);
a0d0e21e
LW
69 }
70
049cc612 71#define ndbm_DELETE(db,key) dbm_delete(db->dbp,key)
a0d0e21e 72int
049cc612 73ndbm_DELETE(db, key)
a0d0e21e 74 NDBM_File db
9fe6733a 75 datum_key key
a0d0e21e 76
049cc612 77#define ndbm_FIRSTKEY(db) dbm_firstkey(db->dbp)
9fe6733a 78datum_key
049cc612 79ndbm_FIRSTKEY(db)
a0d0e21e
LW
80 NDBM_File db
81
049cc612 82#define ndbm_NEXTKEY(db,key) dbm_nextkey(db->dbp)
9fe6733a 83datum_key
049cc612 84ndbm_NEXTKEY(db, key)
a0d0e21e 85 NDBM_File db
0bf2e707 86 datum_key key = NO_INIT
a0d0e21e 87
049cc612 88#define ndbm_error(db) dbm_error(db->dbp)
a0d0e21e 89int
049cc612 90ndbm_error(db)
a0d0e21e
LW
91 NDBM_File db
92
049cc612 93#define ndbm_clearerr(db) dbm_clearerr(db->dbp)
a0d0e21e 94void
049cc612 95ndbm_clearerr(db)
a0d0e21e
LW
96 NDBM_File db
97
9fe6733a 98
9fe6733a
PM
99SV *
100filter_fetch_key(db, code)
101 NDBM_File db
102 SV * code
103 SV * RETVAL = &PL_sv_undef ;
104 CODE:
6a31061a 105 DBM_setFilter(db->filter_fetch_key, code) ;
9fe6733a
PM
106
107SV *
108filter_store_key(db, code)
109 NDBM_File db
110 SV * code
111 SV * RETVAL = &PL_sv_undef ;
112 CODE:
6a31061a 113 DBM_setFilter(db->filter_store_key, code) ;
9fe6733a
PM
114
115SV *
116filter_fetch_value(db, code)
117 NDBM_File db
118 SV * code
119 SV * RETVAL = &PL_sv_undef ;
120 CODE:
6a31061a 121 DBM_setFilter(db->filter_fetch_value, code) ;
9fe6733a
PM
122
123SV *
124filter_store_value(db, code)
125 NDBM_File db
126 SV * code
127 SV * RETVAL = &PL_sv_undef ;
128 CODE:
6a31061a 129 DBM_setFilter(db->filter_store_value, code) ;
9fe6733a 130