wez Mon Dec 9 11:14:28 2002 EDT
Modified files:
/php4 configure.in
/php4/main streams.c
Log:
Emulate fopencookie on *BSD systems.
Patch mostly from Melvyn Sopacua <[EMAIL PROTECTED]>
Index: php4/configure.in
diff -u php4/configure.in:1.404 php4/configure.in:1.405
--- php4/configure.in:1.404 Mon Dec 2 02:03:00 2002
+++ php4/configure.in Mon Dec 9 11:14:27 2002
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.404 2002/12/02 07:03:00 iliaa Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.405 2002/12/09 16:14:27 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.132 php4/main/streams.c:1.133
--- php4/main/streams.c:1.132 Mon Dec 9 05:38:35 2002
+++ php4/main/streams.c Mon Dec 9 11:14:28 2002
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.132 2002/12/09 10:38:35 wez Exp $ */
+/* $Id: streams.c,v 1.133 2002/12/09 16:14:28 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 */
@@ -1784,7 +1803,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;
@@ -1827,7 +1878,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,
@@ -1880,7 +1933,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