php-internal-docs
8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
dba_flatfile.c
Go to the documentation of this file.
1
/*
2
+----------------------------------------------------------------------+
3
| Copyright (c) The PHP Group |
4
+----------------------------------------------------------------------+
5
| This source file is subject to version 3.01 of the PHP license, |
6
| that is bundled with this package in the file LICENSE, and is |
7
| available through the world-wide-web at the following url: |
8
| https://www.php.net/license/3_01.txt |
9
| If you did not receive a copy of the PHP license and are unable to |
10
| obtain it through the world-wide-web, please send a note to |
11
| license@php.net so we can mail you a copy immediately. |
12
+----------------------------------------------------------------------+
13
| Author: Marcus Boerger <helly@php.net> |
14
+----------------------------------------------------------------------+
15
*/
16
17
#ifdef HAVE_CONFIG_H
18
#include <config.h>
19
#endif
20
21
#include "
php.h
"
22
23
#ifdef DBA_FLATFILE
24
#include "
php_flatfile.h
"
25
26
#include "
libflatfile/flatfile.h
"
27
28
#ifdef HAVE_UNISTD_H
29
#include <
unistd.h
>
30
#endif
31
#include <sys/types.h>
32
#include <sys/stat.h>
33
#include <fcntl.h>
34
35
DBA_OPEN_FUNC(
flatfile
)
36
{
37
info->dbf =
pemalloc
(
sizeof
(
flatfile
), info->flags&DBA_PERSISTENT);
38
memset
(info->dbf, 0,
sizeof
(
flatfile
));
39
40
((
flatfile
*)info->dbf)->fp = info->fp;
41
42
return
SUCCESS
;
43
}
44
45
DBA_CLOSE_FUNC(
flatfile
)
46
{
47
flatfile
*dba = info->dbf;
48
49
if
(dba->
nextkey
.
dptr
) {
50
efree
(dba->
nextkey
.
dptr
);
51
}
52
pefree
(dba, info->flags&DBA_PERSISTENT);
53
}
54
55
DBA_FETCH_FUNC(
flatfile
)
56
{
57
flatfile
*dba = info->dbf;
58
datum
gval
;
59
datum
gkey
;
60
zend_string
*fetched_val =
NULL
;
61
62
gkey
.dptr =
ZSTR_VAL
(
key
);
63
gkey
.dsize =
ZSTR_LEN
(
key
);
64
65
gval
=
flatfile_fetch
(dba,
gkey
);
66
if
(
gval
.dptr) {
67
fetched_val = zend_string_init(
gval
.dptr,
gval
.dsize,
/* persistent */
false
);
68
efree
(
gval
.dptr);
69
}
70
return
fetched_val;
71
}
72
73
DBA_UPDATE_FUNC(
flatfile
)
74
{
75
flatfile
*dba = info->dbf;
76
datum
gval
;
77
datum
gkey
;
78
79
gkey
.dptr =
ZSTR_VAL
(
key
);
80
gkey
.dsize =
ZSTR_LEN
(
key
);
81
gval
.dptr =
ZSTR_VAL
(
val
);
82
gval
.dsize =
ZSTR_LEN
(
val
);
83
84
switch
(
flatfile_store
(dba,
gkey
,
gval
,
mode
==1 ?
FLATFILE_INSERT
:
FLATFILE_REPLACE
)) {
85
case
0:
86
return
SUCCESS
;
87
case
1:
88
return
FAILURE
;
89
case
-1:
90
// TODO Check when this happens and confirm this can even happen
91
php_error_docref
(
NULL
,
E_WARNING
,
"Operation not possible"
);
92
return
FAILURE
;
93
default
:
94
// TODO Convert this to an assertion failure
95
php_error_docref
(
NULL
,
E_WARNING
,
"Unknown return value"
);
96
return
FAILURE
;
97
}
98
}
99
100
DBA_EXISTS_FUNC(
flatfile
)
101
{
102
flatfile
*dba = info->dbf;
103
datum
gval
;
104
datum
gkey
;
105
106
gkey
.dptr =
ZSTR_VAL
(
key
);
107
gkey
.dsize =
ZSTR_LEN
(
key
);
108
gval
=
flatfile_fetch
(dba,
gkey
);
109
if
(
gval
.dptr) {
110
efree
(
gval
.dptr);
111
return
SUCCESS
;
112
}
113
return
FAILURE
;
114
}
115
116
DBA_DELETE_FUNC(
flatfile
)
117
{
118
flatfile
*dba = info->dbf;
119
datum
gkey
;
120
121
gkey
.dptr =
ZSTR_VAL
(
key
);
122
gkey
.dsize =
ZSTR_LEN
(
key
);
123
return
(
flatfile_delete
(dba,
gkey
) == -1 ?
FAILURE
:
SUCCESS
);
124
}
125
126
DBA_FIRSTKEY_FUNC(
flatfile
)
127
{
128
flatfile
*dba = info->dbf;
129
130
if
(dba->
nextkey
.
dptr
) {
131
efree
(dba->
nextkey
.
dptr
);
132
}
133
dba->
nextkey
=
flatfile_firstkey
(dba);
134
if
(dba->
nextkey
.
dptr
) {
135
return
zend_string_init(dba->
nextkey
.
dptr
, dba->
nextkey
.
dsize
,
/* persistent */
false
);
136
}
137
return
NULL
;
138
}
139
140
DBA_NEXTKEY_FUNC(
flatfile
)
141
{
142
flatfile
*dba = info->dbf;
143
144
if
(!dba->
nextkey
.
dptr
) {
145
return
NULL
;
146
}
147
148
if
(dba->
nextkey
.
dptr
) {
149
efree
(dba->
nextkey
.
dptr
);
150
}
151
dba->
nextkey
=
flatfile_nextkey
(dba);
152
if
(dba->
nextkey
.
dptr
) {
153
return
zend_string_init(dba->
nextkey
.
dptr
, dba->
nextkey
.
dsize
,
/* persistent */
false
);
154
}
155
return
NULL
;
156
}
157
158
DBA_OPTIMIZE_FUNC(
flatfile
)
159
{
160
/* dummy */
161
return
SUCCESS
;
162
}
163
164
DBA_SYNC_FUNC(
flatfile
)
165
{
166
/* dummy */
167
return
SUCCESS
;
168
}
169
170
DBA_INFO_FUNC(
flatfile
)
171
{
172
return
estrdup
(
flatfile_version
());
173
}
174
175
#endif
memset
memset(ptr, 0, type->size)
val
zval * val
Definition
ffi.c:4262
flatfile_delete
int flatfile_delete(flatfile *dba, datum key_datum)
Definition
flatfile.c:101
flatfile_fetch
datum flatfile_fetch(flatfile *dba, datum key_datum)
Definition
flatfile.c:82
flatfile_firstkey
datum flatfile_firstkey(flatfile *dba)
Definition
flatfile.c:194
flatfile_nextkey
datum flatfile_nextkey(flatfile *dba)
Definition
flatfile.c:236
flatfile_store
int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode)
Definition
flatfile.c:47
flatfile_version
const char * flatfile_version(void)
Definition
flatfile.c:279
flatfile.h
FLATFILE_REPLACE
#define FLATFILE_REPLACE
Definition
flatfile.h:34
FLATFILE_INSERT
#define FLATFILE_INSERT
Definition
flatfile.h:33
mode
char * mode
Definition
func_interceptors.c:282
NULL
#define NULL
Definition
gdcache.h:45
SUCCESS
#define SUCCESS
Definition
hash_sha3.c:261
php_error_docref
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition
main.c:1173
gval
#define gval(n)
Definition
minilua.c:766
gkey
#define gkey(n)
Definition
minilua.c:765
php.h
php_flatfile.h
key
unsigned char key[REFLECTION_KEY_LEN]
Definition
php_reflection.c:63
datum
Definition
flatfile.h:20
datum::dptr
char * dptr
Definition
flatfile.h:21
datum::dsize
size_t dsize
Definition
flatfile.h:22
flatfile
Definition
flatfile.h:25
flatfile::nextkey
datum nextkey
Definition
flatfile.h:30
unistd.h
efree
#define efree(ptr)
Definition
zend_alloc.h:155
estrdup
#define estrdup(s)
Definition
zend_alloc.h:164
pefree
#define pefree(ptr, persistent)
Definition
zend_alloc.h:191
pemalloc
#define pemalloc(size, persistent)
Definition
zend_alloc.h:189
E_WARNING
#define E_WARNING
Definition
zend_errors.h:24
zend_string
struct _zend_string zend_string
Definition
zend_map_ptr.h:24
ZSTR_VAL
#define ZSTR_VAL(zstr)
Definition
zend_string.h:68
ZSTR_LEN
#define ZSTR_LEN(zstr)
Definition
zend_string.h:69
FAILURE
@ FAILURE
Definition
zend_types.h:61
ext
dba
dba_flatfile.c
Generated on Sat Aug 23 2025 01:46:06 for php-internal-docs by
1.13.2