2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 of the PHP license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.php.net/license/3_0.txt. |
11
| If you did not receive a copy of the PHP license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@php.net so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Author: Marcus Boerger <helly@php.net> |
16
+----------------------------------------------------------------------+
19
/* $Id: dba_flatfile.c,v 1.18 2004/01/08 08:14:39 andi Exp $ */
28
#include "php_flatfile.h"
30
#include "libflatfile/flatfile.h"
35
#include <sys/types.h>
39
#define FLATFILE_DATA flatfile *dba = info->dbf
40
#define FLATFILE_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen
42
DBA_OPEN_FUNC(flatfile)
44
info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
45
memset(info->dbf, 0, sizeof(flatfile));
47
((flatfile*)info->dbf)->fp = info->fp;
52
DBA_CLOSE_FUNC(flatfile)
56
if (dba->nextkey.dptr) {
57
efree(dba->nextkey.dptr);
59
pefree(dba, info->flags&DBA_PERSISTENT);
62
DBA_FETCH_FUNC(flatfile)
70
gval = flatfile_fetch(dba, gkey TSRMLS_CC);
75
new = estrndup(gval.dptr, gval.dsize);
81
DBA_UPDATE_FUNC(flatfile)
87
gval.dptr = (char *) val;
90
switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
92
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
98
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
103
DBA_EXISTS_FUNC(flatfile)
109
gval = flatfile_fetch(dba, gkey TSRMLS_CC);
117
DBA_DELETE_FUNC(flatfile)
121
return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS);
124
DBA_FIRSTKEY_FUNC(flatfile)
128
if (dba->nextkey.dptr) {
129
efree(dba->nextkey.dptr);
131
dba->nextkey = flatfile_firstkey(dba TSRMLS_CC);
132
if (dba->nextkey.dptr) {
134
*newlen = dba->nextkey.dsize;
136
return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
141
DBA_NEXTKEY_FUNC(flatfile)
145
if (!dba->nextkey.dptr) {
149
if (dba->nextkey.dptr) {
150
efree(dba->nextkey.dptr);
152
dba->nextkey = flatfile_nextkey(dba TSRMLS_CC);
153
if (dba->nextkey.dptr) {
155
*newlen = dba->nextkey.dsize;
157
return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
162
DBA_OPTIMIZE_FUNC(flatfile)
168
DBA_SYNC_FUNC(flatfile)
174
DBA_INFO_FUNC(flatfile)
176
return estrdup(flatfile_version());
186
* vim600: sw=4 ts=4 fdm=marker