]> granicus.if.org Git - php/commitdiff
Centralize ability to drop APPEND flag. This probably fixes some ini file
authorMarcus Boerger <helly@php.net>
Thu, 18 Dec 2003 20:14:15 +0000 (20:14 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 18 Dec 2003 20:14:15 +0000 (20:14 +0000)
issues.

ext/dba/dba.c
ext/dba/dba_flatfile.c
ext/dba/libinifile/inifile.c
ext/dba/php_dba.h

index 0e996cd3a188b6ecedfe433984815b3519760217..3a02dacf4fb5de1653026b309dc275c6c03b4af6 100644 (file)
@@ -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) {
index 1ccaeb0c0ce1845434119759e69496b35702c4ab..feba2c8da8143cb540afe65c6989435809be0172 100644 (file)
 
 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));
 
index 9a2ed583539914940ce0a8d96bb68031cce11b3a..48fd46fde0d295ba5682b7772fda31b0e0ed440c 100644 (file)
@@ -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;
index bc13ea62dca2722c116174cf2302f8d739ba8e26..eb092a832ad073d7adf836e80facbe67ca30ab6d 100644 (file)
@@ -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