issues.
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 }
};
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) {
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));
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;
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;
#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