wez             Mon Dec  9 11:22:06 2002 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4       configure.in 
    /php4/main  streams.c 
  Log:
  MFH: fopencookie for BSD patch
  
  
Index: php4/configure.in
diff -u php4/configure.in:1.396.2.9 php4/configure.in:1.396.2.10
--- php4/configure.in:1.396.2.9 Thu Dec  5 06:38:13 2002
+++ php4/configure.in   Mon Dec  9 11:22:05 2002
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.396.2.9 2002/12/05 11:38:13 helly Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.396.2.10 2002/12/09 16:22:05 wez Exp $ -*- sh -*-
 dnl ## Process this file with autoconf to produce a configure script.
 
 divert(1)
@@ -451,6 +451,7 @@
 crypt \
 flock \
 ftok \
+funopen \
 gai_strerror \
 gcvt \
 getlogin \
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.125.2.16 php4/main/streams.c:1.125.2.17
--- php4/main/streams.c:1.125.2.16      Mon Dec  9 05:34:32 2002
+++ php4/main/streams.c Mon Dec  9 11:22:06 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.125.2.16 2002/12/09 10:34:32 wez Exp $ */
+/* $Id: streams.c,v 1.125.2.17 2002/12/09 16:22:06 wez Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -72,6 +72,25 @@
 #endif
 /* }}} */
 
+/* Under BSD, emulate fopencookie using funopen */
+#if HAVE_FUNOPEN
+typedef struct {
+       int (*reader)(void *, char *, int);
+       int (*writer)(void *, const char *, int);
+       fpos_t (*seeker)(void *, fpos_t, int);
+       int (*closer)(void *);
+} COOKIE_IO_FUNCTIONS_T;
+
+FILE *fopencookie(void *cookie, const char *mode, COOKIE_IO_FUNCTIONS_T *funcs)
+{
+       return funopen(cookie, funcs->reader, funcs->writer, funcs->seeker, 
+funcs->closer);
+}
+# define HAVE_FOPENCOOKIE 1
+# define PHP_STREAM_COOKIE_FUNCTIONS   &stream_cookie_functions
+#elif HAVE_FOPENCOOKIE
+# define PHP_STREAM_COOKIE_FUNCTIONS   stream_cookie_functions
+#endif
+       
 static HashTable url_stream_wrappers_hash;
 static int le_stream = FAILURE; /* true global */
 static int le_pstream = FAILURE; /* true global */
@@ -1782,7 +1801,39 @@
 /* }}} */
 
 /* {{{ STDIO with fopencookie */
-#if HAVE_FOPENCOOKIE
+#if HAVE_FUNOPEN
+/* use our fopencookie emulation */
+static int stream_cookie_reader(void *cookie, char *buffer, int size)
+{
+       int ret;
+       TSRMLS_FETCH();
+       ret = php_stream_read((php_stream*)cookie, buffer, size);
+       return ret;
+}
+
+static int stream_cookie_writer(void *cookie, const char *buffer, int size)
+{
+       TSRMLS_FETCH();
+       return php_stream_write((php_stream *)cookie, (char *)buffer, size);
+}
+
+static fpos_t stream_cookie_seeker(void *cookie, off_t position, int whence)
+{
+       TSRMLS_FETCH();
+       return (fpos_t)php_stream_seek((php_stream *)cookie, position, whence);
+}
+
+static int stream_cookie_closer(void *cookie)
+{
+       php_stream *stream = (php_stream*)cookie;
+       TSRMLS_FETCH();
+
+       /* prevent recursion */
+       stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE;
+       return php_stream_close(stream);
+}
+
+#elif HAVE_FOPENCOOKIE
 static ssize_t stream_cookie_reader(void *cookie, char *buffer, size_t size)
 {
        ssize_t ret;
@@ -1825,7 +1876,9 @@
        stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE;
        return php_stream_close(stream);
 }
+#endif /* elif HAVE_FOPENCOOKIE */
 
+#if HAVE_FOPENCOOKIE
 static COOKIE_IO_FUNCTIONS_T stream_cookie_functions =
 {
        stream_cookie_reader, stream_cookie_writer,
@@ -1878,7 +1931,7 @@
                if (ret == NULL)
                        goto exit_success;
 
-               *ret = fopencookie(stream, stream->mode, stream_cookie_functions);
+               *ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS);
 
                if (*ret != NULL) {
                        off_t pos;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to