summaryrefslogtreecommitdiff
path: root/ext/dba/dba.c
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-12-14 22:08:18 +0000
committerMarcus Boerger <helly@php.net>2003-12-14 22:08:18 +0000
commit43d06f50e0014e7a43c83276772e6a737b082dfa (patch)
tree830d5c05803b460af3f62883f12e025e04272dc0 /ext/dba/dba.c
parent620bf0c37f0fdc14304f026eb9fc9efb15eceebc (diff)
downloadphp-git-43d06f50e0014e7a43c83276772e6a737b082dfa.tar.gz
- Fix Bug #26304 Unexpected data loss when opening dba file
- Correct handling for flatfile handler
Diffstat (limited to 'ext/dba/dba.c')
-rw-r--r--ext/dba/dba.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/ext/dba/dba.c b/ext/dba/dba.c
index 72adca6f52..0e996cd3a1 100644
--- a/ext/dba/dba.c
+++ b/ext/dba/dba.c
@@ -648,15 +648,23 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
case 'c':
modenr = DBA_CREAT;
lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0;
- if (!lock_mode || !lock_dbf) {
- file_mode = "a+b";
+ if (lock_mode) {
+ if (lock_dbf) {
+ /* the create/append check will be done on the lock
+ * when the lib opens the file it is already created
+ */
+ file_mode = "r+b"; /* read & write, seek 0 */
+ lock_file_mode = "a+b"; /* append */
+ } else {
+ file_mode = "a+b"; /* append */
+ lock_file_mode = "w+b"; /* create/truncate */
+ }
} else {
- /* the create/append check will be done on the lock
- * when the lib opens the file it is already created
- */
- file_mode = "w+b";
- lock_file_mode = "a+b";
+ file_mode = "a+b";
}
+ /* In case of the 'a+b' append mode, the handler is responsible
+ * to handle any rewind problems (see flatfile handler).
+ */
break;
case 'n':
modenr = DBA_TRUNC;