summaryrefslogtreecommitdiff
path: root/ext/dba
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-12-18 20:14:15 +0000
committerMarcus Boerger <helly@php.net>2003-12-18 20:14:15 +0000
commit0283b50316ed8fa20cb7df1f03459108a8e97943 (patch)
tree38cc755839c8b133e910f34821b55ac4ce3f5cc8 /ext/dba
parenta6dd097484bf5ced360ddfb81306fe477286fab9 (diff)
downloadphp-git-0283b50316ed8fa20cb7df1f03459108a8e97943.tar.gz
Centralize ability to drop APPEND flag. This probably fixes some ini file
issues.
Diffstat (limited to 'ext/dba')
-rw-r--r--ext/dba/dba.c21
-rw-r--r--ext/dba/dba_flatfile.c19
-rw-r--r--ext/dba/libinifile/inifile.c6
-rw-r--r--ext/dba/php_dba.h4
4 files changed, 24 insertions, 26 deletions
diff --git a/ext/dba/dba.c b/ext/dba/dba.c
index 0e996cd3a1..3a02dacf4f 100644
--- a/ext/dba/dba.c
+++ b/ext/dba/dba.c
@@ -248,10 +248,10 @@ static dba_handler handler[] = {
DBA_HND(db4, DBA_LOCK_ALL) /* No lock in lib */
#endif
#if DBA_INIFILE
- DBA_HND(inifile, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */
+ DBA_HND(inifile, DBA_STREAM_OPEN|DBA_LOCK_ALL|DBA_CAST_AS_FD) /* No lock in lib */
#endif
#if DBA_FLATFILE
- DBA_HND(flatfile, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */
+ DBA_HND(flatfile, DBA_STREAM_OPEN|DBA_LOCK_ALL|DBA_NO_APPEND) /* No lock in lib */
#endif
{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
@@ -802,6 +802,23 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
FREENOW;
RETURN_FALSE;
}
+ if (hptr->flags & (DBA_NO_APPEND|DBA_CAST_AS_FD)) {
+ /* Needed becasue some systems do not allow to write to the original
+ * file contents with O_APPEND being set.
+ */
+ if (SUCCESS != php_stream_cast(info->fp, PHP_STREAM_AS_FD, (void*)&info->fd, 1)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast stream");
+ dba_close(info TSRMLS_CC);
+ FREENOW;
+ RETURN_FALSE;
+#ifdef F_SETFL
+ } else if (modenr == DBA_CREAT) {
+ int flags = fcntl(info->fd, F_SETFL);
+ fcntl(info->fd, F_SETFL, flags & ~O_APPEND);
+#endif
+ }
+
+ }
}
if (error || hptr->open(info, &error TSRMLS_CC) != SUCCESS) {
diff --git a/ext/dba/dba_flatfile.c b/ext/dba/dba_flatfile.c
index 1ccaeb0c0c..feba2c8da8 100644
--- a/ext/dba/dba_flatfile.c
+++ b/ext/dba/dba_flatfile.c
@@ -41,25 +41,6 @@
DBA_OPEN_FUNC(flatfile)
{
- int fd;
-#ifdef F_SETFL
- int flags;
-#endif
-
- if (info->mode != DBA_READER) {
- if (SUCCESS != php_stream_cast(info->fp, PHP_STREAM_AS_FD, (void*)&fd, 1)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast stream");
- return FAILURE;
- }
-#ifdef F_SETFL
- /* Needed becasue some systems do not allow to write to the original
- * file contents with O_APPEND being set.
- */
- flags = fcntl(fd, F_SETFL);
- fcntl(fd, F_SETFL, flags & ~O_APPEND);
-#endif
- }
-
info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
memset(info->dbf, 0, sizeof(flatfile));
diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c
index 9a2ed58353..48fd46fde0 100644
--- a/ext/dba/libinifile/inifile.c
+++ b/ext/dba/libinifile/inifile.c
@@ -83,18 +83,14 @@ void inifile_line_free(line_type *ln)
inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC)
{
inifile *dba;
- int fd;
if (!readonly) {
if (!php_stream_truncate_supported(fp)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream");
return NULL;
}
- if (SUCCESS != php_stream_cast(fp, PHP_STREAM_AS_FD, (void*)&fd, 1)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast stream");
- return NULL;
- }
}
+
dba = pemalloc(sizeof(inifile), persistent);
memset(dba, 0, sizeof(inifile));
dba->fp = fp;
diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h
index bc13ea62dc..eb092a832a 100644
--- a/ext/dba/php_dba.h
+++ b/ext/dba/php_dba.h
@@ -43,6 +43,7 @@ typedef struct dba_info {
char *path;
dba_mode_t mode;
php_stream *fp; /* this is the database stream for builtin handlers */
+ int fd;
/* arg[cv] are only available when the dba_open handler is called! */
int argc;
zval ***argv;
@@ -64,6 +65,9 @@ typedef struct dba_info {
#define DBA_STREAM_OPEN (0x0010)
#define DBA_PERSISTENT (0x0020)
+#define DBA_CAST_AS_FD (0x0050)
+#define DBA_NO_APPEND (0x00D0)
+
extern zend_module_entry dba_module_entry;
#define dba_module_ptr &dba_module_entry