summaryrefslogtreecommitdiff
path: root/main/streams/userspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams/userspace.c')
-rw-r--r--main/streams/userspace.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index bdd9b1b48e..de3e8591e6 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -588,14 +588,14 @@ PHP_FUNCTION(stream_wrapper_restore)
}
/* }}} */
-static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count)
+static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count)
{
zval func_name;
zval retval;
int call_result;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
zval args[1];
- size_t didwrite = 0;
+ ssize_t didwrite;
assert(us != NULL);
@@ -612,18 +612,21 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&func_name);
- didwrite = 0;
-
if (EG(exception)) {
- return 0;
+ return -1;
}
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
- convert_to_long(&retval);
- didwrite = Z_LVAL(retval);
- } else if (call_result == FAILURE) {
+ if (Z_TYPE(retval) == IS_FALSE) {
+ didwrite = -1;
+ } else {
+ convert_to_long(&retval);
+ didwrite = Z_LVAL(retval);
+ }
+ } else {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!",
us->wrapper->classname);
+ didwrite = -1;
}
/* don't allow strange buffer overruns due to bogus return */
@@ -639,7 +642,7 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t
return didwrite;
}
-static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count)
+static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count)
{
zval func_name;
zval retval;
@@ -669,6 +672,10 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count)
}
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ if (Z_TYPE(retval) == IS_FALSE) {
+ return -1;
+ }
+
if (!try_convert_to_string(&retval)) {
return -1;
}
@@ -1401,7 +1408,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i
}
-static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count)
+static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count)
{
zval func_name;
zval retval;
@@ -1412,7 +1419,7 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou
/* avoid problems if someone mis-uses the stream */
if (count != sizeof(php_stream_dirent))
- return 0;
+ return -1;
ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1);