summaryrefslogtreecommitdiff
path: root/ext/standard/streamsfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/streamsfuncs.c')
-rw-r--r--ext/standard/streamsfuncs.c283
1 files changed, 122 insertions, 161 deletions
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index d7bacf5bd5..c0d950a18c 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -49,8 +47,7 @@ static php_stream_context *decode_context_param(zval *contextresource);
/* Streams based network functions */
#if HAVE_SOCKETPAIR
-/* {{{ proto array stream_socket_pair(int domain, int type, int protocol)
- Creates a pair of connected, indistinguishable socket streams */
+/* {{{ Creates a pair of connected, indistinguishable socket streams */
PHP_FUNCTION(stream_socket_pair)
{
zend_long domain, type, protocol;
@@ -61,11 +58,11 @@ PHP_FUNCTION(stream_socket_pair)
Z_PARAM_LONG(domain)
Z_PARAM_LONG(type)
Z_PARAM_LONG(protocol)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
if (0 != socketpair((int)domain, (int)type, (int)protocol, pair)) {
char errbuf[256];
- php_error_docref(NULL, E_WARNING, "failed to create sockets: [%d]: %s",
+ php_error_docref(NULL, E_WARNING, "Failed to create sockets: [%d]: %s",
php_socket_errno(), php_socket_strerror(php_socket_errno(), errbuf, sizeof(errbuf)));
RETURN_FALSE;
}
@@ -86,8 +83,7 @@ PHP_FUNCTION(stream_socket_pair)
/* }}} */
#endif
-/* {{{ proto resource stream_socket_client(string remoteaddress [, int &errcode [, string &errstring [, double timeout [, int flags [, resource context]]]]])
- Open a client connection to a remote address */
+/* {{{ Open a client connection to a remote address */
PHP_FUNCTION(stream_socket_client)
{
zend_string *host;
@@ -111,8 +107,8 @@ PHP_FUNCTION(stream_socket_client)
Z_PARAM_ZVAL(zerrstr)
Z_PARAM_DOUBLE(timeout)
Z_PARAM_LONG(flags)
- Z_PARAM_RESOURCE(zcontext)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ Z_PARAM_RESOURCE_OR_NULL(zcontext)
+ ZEND_PARSE_PARAMETERS_END();
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
@@ -146,7 +142,7 @@ PHP_FUNCTION(stream_socket_client)
/* host might contain binary characters */
zend_string *quoted_host = php_addslashes(host);
- php_error_docref(NULL, E_WARNING, "unable to connect to %s (%s)", ZSTR_VAL(quoted_host), errstr == NULL ? "Unknown error" : ZSTR_VAL(errstr));
+ php_error_docref(NULL, E_WARNING, "Unable to connect to %s (%s)", ZSTR_VAL(quoted_host), errstr == NULL ? "Unknown error" : ZSTR_VAL(errstr));
zend_string_release_ex(quoted_host, 0);
}
@@ -175,8 +171,7 @@ PHP_FUNCTION(stream_socket_client)
}
/* }}} */
-/* {{{ proto resource stream_socket_server(string localaddress [, int &errcode [, string &errstring [, int flags [, resource context]]]])
- Create a server socket bound to localaddress */
+/* {{{ Create a server socket bound to localaddress */
PHP_FUNCTION(stream_socket_server)
{
char *host;
@@ -196,8 +191,8 @@ PHP_FUNCTION(stream_socket_server)
Z_PARAM_ZVAL(zerrno)
Z_PARAM_ZVAL(zerrstr)
Z_PARAM_LONG(flags)
- Z_PARAM_RESOURCE(zcontext)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ Z_PARAM_RESOURCE_OR_NULL(zcontext)
+ ZEND_PARSE_PARAMETERS_END();
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
@@ -217,7 +212,7 @@ PHP_FUNCTION(stream_socket_server)
NULL, NULL, context, &errstr, &err);
if (stream == NULL) {
- php_error_docref(NULL, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : ZSTR_VAL(errstr));
+ php_error_docref(NULL, E_WARNING, "Unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : ZSTR_VAL(errstr));
}
if (stream == NULL) {
@@ -240,8 +235,7 @@ PHP_FUNCTION(stream_socket_server)
}
/* }}} */
-/* {{{ proto resource stream_socket_accept(resource serverstream, [ double timeout [, string &peername ]])
- Accept a client connection from a server socket */
+/* {{{ Accept a client connection from a server socket */
PHP_FUNCTION(stream_socket_accept)
{
double timeout = (double)FG(default_socket_timeout);
@@ -258,7 +252,7 @@ PHP_FUNCTION(stream_socket_accept)
Z_PARAM_OPTIONAL
Z_PARAM_DOUBLE(timeout)
Z_PARAM_ZVAL(zpeername)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
@@ -286,7 +280,7 @@ PHP_FUNCTION(stream_socket_accept)
if (peername) {
zend_string_release(peername);
}
- php_error_docref(NULL, E_WARNING, "accept failed: %s", errstr ? ZSTR_VAL(errstr) : "Unknown error");
+ php_error_docref(NULL, E_WARNING, "Accept failed: %s", errstr ? ZSTR_VAL(errstr) : "Unknown error");
RETVAL_FALSE;
}
@@ -296,8 +290,7 @@ PHP_FUNCTION(stream_socket_accept)
}
/* }}} */
-/* {{{ proto string stream_socket_get_name(resource stream, bool want_peer)
- Returns either the locally bound or remote name for a socket stream */
+/* {{{ Returns either the locally bound or remote name for a socket stream */
PHP_FUNCTION(stream_socket_get_name)
{
php_stream *stream;
@@ -308,7 +301,7 @@ PHP_FUNCTION(stream_socket_get_name)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zstream)
Z_PARAM_BOOL(want_peer)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
@@ -328,8 +321,7 @@ PHP_FUNCTION(stream_socket_get_name)
}
/* }}} */
-/* {{{ proto int stream_socket_sendto(resource stream, string data [, int flags [, string target_addr]])
- Send data to a socket stream. If target_addr is specified it must be in dotted quad (or [ipv6]) format */
+/* {{{ Send data to a socket stream. If target_addr is specified it must be in dotted quad (or [ipv6]) format */
PHP_FUNCTION(stream_socket_sendto)
{
php_stream *stream;
@@ -346,7 +338,7 @@ PHP_FUNCTION(stream_socket_sendto)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(flags)
Z_PARAM_STRING(target_addr, target_addr_len)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
if (target_addr_len) {
@@ -361,8 +353,7 @@ PHP_FUNCTION(stream_socket_sendto)
}
/* }}} */
-/* {{{ proto string stream_socket_recvfrom(resource stream, int amount [, int flags [, string &remote_addr]])
- Receives data from a socket stream */
+/* {{{ Receives data from a socket stream */
PHP_FUNCTION(stream_socket_recvfrom)
{
php_stream *stream;
@@ -379,7 +370,7 @@ PHP_FUNCTION(stream_socket_recvfrom)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(flags)
Z_PARAM_ZVAL(zremote)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
@@ -388,8 +379,8 @@ PHP_FUNCTION(stream_socket_recvfrom)
}
if (to_read <= 0) {
- php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be greater than 0");
+ RETURN_THROWS();
}
read_buf = zend_string_alloc(to_read, 0);
@@ -412,8 +403,7 @@ PHP_FUNCTION(stream_socket_recvfrom)
}
/* }}} */
-/* {{{ proto string stream_get_contents(resource source [, int maxlen [, int offset]])
- Reads all remaining bytes (or up to maxlen bytes) from a stream and returns them as a string. */
+/* {{{ Reads all remaining bytes (or up to maxlen bytes) from a stream and returns them as a string. */
PHP_FUNCTION(stream_get_contents)
{
php_stream *stream;
@@ -427,7 +417,7 @@ PHP_FUNCTION(stream_get_contents)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(maxlen)
Z_PARAM_LONG(desiredpos)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zsrc);
@@ -463,8 +453,7 @@ PHP_FUNCTION(stream_get_contents)
}
/* }}} */
-/* {{{ proto int stream_copy_to_stream(resource source, resource dest [, int maxlen [, int pos]])
- Reads up to maxlen bytes from source stream and writes them to dest stream. */
+/* {{{ Reads up to maxlen bytes from source stream and writes them to dest stream. */
PHP_FUNCTION(stream_copy_to_stream)
{
php_stream *src, *dest;
@@ -479,7 +468,7 @@ PHP_FUNCTION(stream_copy_to_stream)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(maxlen)
Z_PARAM_LONG(pos)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(src, zsrc);
php_stream_from_zval(dest, zdest);
@@ -498,8 +487,7 @@ PHP_FUNCTION(stream_copy_to_stream)
}
/* }}} */
-/* {{{ proto array stream_get_meta_data(resource fp)
- Retrieves header/meta data from streams/file pointers */
+/* {{{ Retrieves header/meta data from streams/file pointers */
PHP_FUNCTION(stream_get_meta_data)
{
zval *zstream;
@@ -555,16 +543,13 @@ PHP_FUNCTION(stream_get_meta_data)
}
/* }}} */
-/* {{{ proto array stream_get_transports()
- Retrieves list of registered socket transports */
+/* {{{ Retrieves list of registered socket transports */
PHP_FUNCTION(stream_get_transports)
{
HashTable *stream_xport_hash;
zend_string *stream_xport;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_NONE();
if ((stream_xport_hash = php_stream_xport_get_hash())) {
array_init(return_value);
@@ -577,16 +562,13 @@ PHP_FUNCTION(stream_get_transports)
}
/* }}} */
-/* {{{ proto array stream_get_wrappers()
- Retrieves list of registered stream wrappers */
+/* {{{ Retrieves list of registered stream wrappers */
PHP_FUNCTION(stream_get_wrappers)
{
HashTable *url_stream_wrappers_hash;
zend_string *stream_protocol;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_NONE();
if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
array_init(return_value);
@@ -741,8 +723,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array)
}
/* }}} */
-/* {{{ proto int stream_select(array &read_streams, array &write_streams, array &except_streams, int tv_sec[, int tv_usec])
- Runs the select() system call on the sets of streams with a timeout specified by tv_sec and tv_usec */
+/* {{{ Runs the select() system call on the sets of streams with a timeout specified by tv_sec and tv_usec */
PHP_FUNCTION(stream_select)
{
zval *r_array, *w_array, *e_array;
@@ -758,7 +739,7 @@ PHP_FUNCTION(stream_select)
Z_PARAM_ARRAY_EX2(r_array, 1, 1, 0)
Z_PARAM_ARRAY_EX2(w_array, 1, 1, 0)
Z_PARAM_ARRAY_EX2(e_array, 1, 1, 0)
- Z_PARAM_LONG_EX(sec, secnull, 1, 0)
+ Z_PARAM_LONG_OR_NULL(sec, secnull)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(usec)
ZEND_PARSE_PARAMETERS_END();
@@ -789,8 +770,8 @@ PHP_FUNCTION(stream_select)
}
if (!sets) {
- php_error_docref(NULL, E_WARNING, "No stream arrays were passed");
- RETURN_FALSE;
+ zend_value_error("No stream arrays were passed");
+ RETURN_THROWS();
}
PHP_SAFE_MAX_FD(max_fd, max_set_count);
@@ -798,11 +779,11 @@ PHP_FUNCTION(stream_select)
/* If seconds is not set to null, build the timeval, else we wait indefinitely */
if (!secnull) {
if (sec < 0) {
- php_error_docref(NULL, E_WARNING, "The seconds parameter must be greater than 0");
- RETURN_FALSE;
+ zend_argument_value_error(4, "must be greater than or equal to 0");
+ RETURN_THROWS();
} else if (usec < 0) {
- php_error_docref(NULL, E_WARNING, "The microseconds parameter must be greater than 0");
- RETURN_FALSE;
+ zend_argument_value_error(4, "must be greater than or equal to 0");
+ RETURN_THROWS();
}
/* Windows, Solaris and BSD do not like microsecond values which are >= 1 sec */
@@ -832,7 +813,7 @@ PHP_FUNCTION(stream_select)
retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p);
if (retval == -1) {
- php_error_docref(NULL, E_WARNING, "unable to select [%d]: %s (max_fd=%d)",
+ php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=%d)",
errno, strerror(errno), max_fd);
RETURN_FALSE;
}
@@ -865,8 +846,8 @@ static void user_space_stream_notifier(php_stream_context *context, int notifyco
ZVAL_LONG(&zvs[4], bytes_sofar);
ZVAL_LONG(&zvs[5], bytes_max);
- if (FAILURE == call_user_function_ex(NULL, NULL, callback, &retval, 6, zvs, 0, NULL)) {
- php_error_docref(NULL, E_WARNING, "failed to call user notifier");
+ if (FAILURE == call_user_function(NULL, NULL, callback, &retval, 6, zvs)) {
+ php_error_docref(NULL, E_WARNING, "Failed to call user notifier");
}
for (i = 0; i < 6; i++) {
zval_ptr_dtor(&zvs[i]);
@@ -897,7 +878,8 @@ static int parse_context_options(php_stream_context *context, zval *options)
}
} ZEND_HASH_FOREACH_END();
} else {
- php_error_docref(NULL, E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value");
+ zend_value_error("Options should have the form [\"wrappername\"][\"optionname\"] = $value");
+ return FAILURE;
}
} ZEND_HASH_FOREACH_END();
@@ -923,9 +905,10 @@ static int parse_context_params(php_stream_context *context, zval *params)
}
if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(params), "options", sizeof("options")-1))) {
if (Z_TYPE_P(tmp) == IS_ARRAY) {
- parse_context_options(context, tmp);
+ return parse_context_options(context, tmp);
} else {
- php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
+ zend_type_error("Invalid stream/context parameter");
+ return FAILURE;
}
}
@@ -962,8 +945,7 @@ static php_stream_context *decode_context_param(zval *contextresource)
}
/* }}} */
-/* {{{ proto array stream_context_get_options(resource context|resource stream)
- Retrieve options for a stream/wrapper/context */
+/* {{{ Retrieve options for a stream/wrapper/context */
PHP_FUNCTION(stream_context_get_options)
{
zval *zcontext;
@@ -971,20 +953,19 @@ PHP_FUNCTION(stream_context_get_options)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zcontext)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
context = decode_context_param(zcontext);
if (!context) {
- php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
- RETURN_FALSE;
+ zend_argument_type_error(1, "must be a valid stream/context");
+ RETURN_THROWS();
}
ZVAL_COPY(return_value, &context->options);
}
/* }}} */
-/* {{{ proto bool stream_context_set_option(resource context|resource stream, string wrappername, string optionname, mixed value)
- Set an option for a wrapper */
+/* {{{ Set an option for a wrapper */
PHP_FUNCTION(stream_context_set_option)
{
zval *zcontext = NULL;
@@ -996,12 +977,12 @@ PHP_FUNCTION(stream_context_set_option)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zcontext)
Z_PARAM_ARRAY(options)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
/* figure out where the context is coming from exactly */
if (!(context = decode_context_param(zcontext))) {
- php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
- RETURN_FALSE;
+ zend_argument_type_error(1, "must be a valid stream/context");
+ RETURN_THROWS();
}
RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
@@ -1015,12 +996,12 @@ PHP_FUNCTION(stream_context_set_option)
Z_PARAM_STRING(wrappername, wrapperlen)
Z_PARAM_STRING(optionname, optionlen)
Z_PARAM_ZVAL(zvalue)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
/* figure out where the context is coming from exactly */
if (!(context = decode_context_param(zcontext))) {
- php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
- RETURN_FALSE;
+ zend_argument_type_error(1, "must be a valid stream/context");
+ RETURN_THROWS();
}
RETURN_BOOL(php_stream_context_set_option(context, wrappername, optionname, zvalue) == SUCCESS);
@@ -1028,8 +1009,7 @@ PHP_FUNCTION(stream_context_set_option)
}
/* }}} */
-/* {{{ proto bool stream_context_set_params(resource context|resource stream, array options)
- Set parameters for a file context */
+/* {{{ Set parameters for a file context */
PHP_FUNCTION(stream_context_set_params)
{
zval *params, *zcontext;
@@ -1038,20 +1018,19 @@ PHP_FUNCTION(stream_context_set_params)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zcontext)
Z_PARAM_ARRAY(params)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
context = decode_context_param(zcontext);
if (!context) {
- php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
- RETURN_FALSE;
+ zend_argument_type_error(1, "must be a valid stream/context");
+ RETURN_THROWS();
}
RETVAL_BOOL(parse_context_params(context, params) == SUCCESS);
}
/* }}} */
-/* {{{ proto array stream_context_get_params(resource context|resource stream)
- Get parameters of a file context */
+/* {{{ Get parameters of a file context */
PHP_FUNCTION(stream_context_get_params)
{
zval *zcontext;
@@ -1059,12 +1038,12 @@ PHP_FUNCTION(stream_context_get_params)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zcontext)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
context = decode_context_param(zcontext);
if (!context) {
- php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
- RETURN_FALSE;
+ zend_argument_type_error(1, "must be a valid stream/context");
+ RETURN_THROWS();
}
array_init(return_value);
@@ -1077,8 +1056,7 @@ PHP_FUNCTION(stream_context_get_params)
}
/* }}} */
-/* {{{ proto resource stream_context_get_default([array options])
- Get a handle on the default file/stream context and optionally set parameters */
+/* {{{ Get a handle on the default file/stream context and optionally set parameters */
PHP_FUNCTION(stream_context_get_default)
{
zval *params = NULL;
@@ -1087,7 +1065,7 @@ PHP_FUNCTION(stream_context_get_default)
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY(params)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
if (FG(default_context) == NULL) {
FG(default_context) = php_stream_context_alloc();
@@ -1095,15 +1073,16 @@ PHP_FUNCTION(stream_context_get_default)
context = FG(default_context);
if (params) {
- parse_context_options(context, params);
+ if (parse_context_options(context, params) == FAILURE) {
+ RETURN_THROWS();
+ }
}
php_stream_context_to_zval(context, return_value);
}
/* }}} */
-/* {{{ proto resource stream_context_set_default(array options)
- Set default file/stream context, returns the context as a resource */
+/* {{{ Set default file/stream context, returns the context as a resource */
PHP_FUNCTION(stream_context_set_default)
{
zval *options = NULL;
@@ -1118,14 +1097,15 @@ PHP_FUNCTION(stream_context_set_default)
}
context = FG(default_context);
- parse_context_options(context, options);
+ if (parse_context_options(context, options) == FAILURE) {
+ RETURN_THROWS();
+ }
php_stream_context_to_zval(context, return_value);
}
/* }}} */
-/* {{{ proto resource stream_context_create([array options[, array params]])
- Create a file context and optionally set parameters */
+/* {{{ Create a file context and optionally set parameters */
PHP_FUNCTION(stream_context_create)
{
zval *options = NULL, *params = NULL;
@@ -1133,9 +1113,9 @@ PHP_FUNCTION(stream_context_create)
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
- Z_PARAM_ARRAY_EX(options, 1, 0)
- Z_PARAM_ARRAY_EX(params, 1, 0)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ Z_PARAM_ARRAY_OR_NULL(options)
+ Z_PARAM_ARRAY_OR_NULL(params)
+ ZEND_PARSE_PARAMETERS_END();
context = php_stream_context_alloc();
@@ -1169,7 +1149,7 @@ static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(read_write)
Z_PARAM_ZVAL(filterparams)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
@@ -1231,24 +1211,21 @@ static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS)
}
/* }}} */
-/* {{{ proto resource stream_filter_prepend(resource stream, string filtername[, int read_write[, string filterparams]])
- Prepend a filter to a stream */
+/* {{{ Prepend a filter to a stream */
PHP_FUNCTION(stream_filter_prepend)
{
apply_filter_to_stream(0, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
-/* {{{ proto resource stream_filter_append(resource stream, string filtername[, int read_write[, string filterparams]])
- Append a filter to a stream */
+/* {{{ Append a filter to a stream */
PHP_FUNCTION(stream_filter_append)
{
apply_filter_to_stream(1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
-/* {{{ proto bool stream_filter_remove(resource stream_filter)
- Flushes any data in the filter's internal buffer, removes it from the chain, and frees the resource */
+/* {{{ Flushes any data in the filter's internal buffer, removes it from the chain, and frees the resource */
PHP_FUNCTION(stream_filter_remove)
{
zval *zfilter;
@@ -1256,12 +1233,11 @@ PHP_FUNCTION(stream_filter_remove)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zfilter)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
- filter = zend_fetch_resource(Z_RES_P(zfilter), NULL, php_file_le_stream_filter());
+ filter = zend_fetch_resource(Z_RES_P(zfilter), "stream filter", php_file_le_stream_filter());
if (!filter) {
- php_error_docref(NULL, E_WARNING, "Invalid resource given, not a stream filter");
- RETURN_FALSE;
+ RETURN_THROWS();
}
if (php_stream_filter_flush(filter, 1) == FAILURE) {
@@ -1279,8 +1255,7 @@ PHP_FUNCTION(stream_filter_remove)
}
/* }}} */
-/* {{{ proto string stream_get_line(resource stream, int maxlen [, string ending])
- Read up to maxlen bytes from a stream or until the ending string is found */
+/* {{{ Read up to maxlen bytes from a stream or until the ending string is found */
PHP_FUNCTION(stream_get_line)
{
char *str = NULL;
@@ -1295,11 +1270,11 @@ PHP_FUNCTION(stream_get_line)
Z_PARAM_LONG(max_length)
Z_PARAM_OPTIONAL
Z_PARAM_STRING(str, str_len)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
if (max_length < 0) {
- php_error_docref(NULL, E_WARNING, "The maximum allowed length must be greater than or equal to zero");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be greater than or equal to 0");
+ RETURN_THROWS();
}
if (!max_length) {
max_length = PHP_SOCK_CHUNK_SIZE;
@@ -1316,8 +1291,7 @@ PHP_FUNCTION(stream_get_line)
/* }}} */
-/* {{{ proto bool stream_set_blocking(resource socket, bool mode)
- Set blocking/non-blocking mode on a socket or stream */
+/* {{{ Set blocking/non-blocking mode on a socket or stream */
PHP_FUNCTION(stream_set_blocking)
{
zval *zstream;
@@ -1340,8 +1314,7 @@ PHP_FUNCTION(stream_set_blocking)
/* }}} */
-/* {{{ proto bool stream_set_timeout(resource stream, int seconds [, int microseconds])
- Set timeout on stream read to seconds + microseonds */
+/* {{{ Set timeout on stream read to seconds + microseonds */
#if HAVE_SYS_TIME_H || defined(PHP_WIN32)
PHP_FUNCTION(stream_set_timeout)
{
@@ -1389,8 +1362,7 @@ PHP_FUNCTION(stream_set_timeout)
#endif /* HAVE_SYS_TIME_H || defined(PHP_WIN32) */
/* }}} */
-/* {{{ proto int stream_set_write_buffer(resource fp, int buffer)
- Set file write buffer */
+/* {{{ Set file write buffer */
PHP_FUNCTION(stream_set_write_buffer)
{
zval *arg1;
@@ -1402,7 +1374,7 @@ PHP_FUNCTION(stream_set_write_buffer)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(arg1)
Z_PARAM_LONG(arg2)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, arg1);
@@ -1419,8 +1391,7 @@ PHP_FUNCTION(stream_set_write_buffer)
}
/* }}} */
-/* {{{ proto int stream_set_chunk_size(resource fp, int chunk_size)
- Set the stream chunk size */
+/* {{{ Set the stream chunk size */
PHP_FUNCTION(stream_set_chunk_size)
{
int ret;
@@ -1431,19 +1402,19 @@ PHP_FUNCTION(stream_set_chunk_size)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zstream)
Z_PARAM_LONG(csize)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
if (csize <= 0) {
- php_error_docref(NULL, E_WARNING, "The chunk size must be a positive integer, given " ZEND_LONG_FMT, csize);
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be greater than 0");
+ RETURN_THROWS();
}
/* stream.chunk_size is actually a size_t, but php_stream_set_option
* can only use an int to accept the new value and return the old one.
* In any case, values larger than INT_MAX for a chunk size make no sense.
*/
if (csize > INT_MAX) {
- php_error_docref(NULL, E_WARNING, "The chunk size cannot be larger than %d", INT_MAX);
- RETURN_FALSE;
+ zend_argument_value_error(2, "is too large");
+ RETURN_THROWS();
}
php_stream_from_zval(stream, zstream);
@@ -1454,8 +1425,7 @@ PHP_FUNCTION(stream_set_chunk_size)
}
/* }}} */
-/* {{{ proto int stream_set_read_buffer(resource fp, int buffer)
- Set file read buffer */
+/* {{{ Set file read buffer */
PHP_FUNCTION(stream_set_read_buffer)
{
zval *arg1;
@@ -1467,7 +1437,7 @@ PHP_FUNCTION(stream_set_read_buffer)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(arg1)
Z_PARAM_LONG(arg2)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, arg1);
@@ -1484,8 +1454,7 @@ PHP_FUNCTION(stream_set_read_buffer)
}
/* }}} */
-/* {{{ proto int stream_socket_enable_crypto(resource stream, bool enable [, int cryptokind [, resource sessionstream]])
- Enable or disable a specific kind of crypto on the stream */
+/* {{{ Enable or disable a specific kind of crypto on the stream */
PHP_FUNCTION(stream_socket_enable_crypto)
{
zend_long cryptokind = 0;
@@ -1498,9 +1467,9 @@ PHP_FUNCTION(stream_socket_enable_crypto)
Z_PARAM_RESOURCE(zstream)
Z_PARAM_BOOL(enable)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG_EX(cryptokind, cryptokindnull, 1, 0)
- Z_PARAM_RESOURCE(zsessstream)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ Z_PARAM_LONG_OR_NULL(cryptokind, cryptokindnull)
+ Z_PARAM_RESOURCE_OR_NULL(zsessstream)
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
@@ -1509,8 +1478,8 @@ PHP_FUNCTION(stream_socket_enable_crypto)
zval *val;
if (!GET_CTX_OPT(stream, "ssl", "crypto_method", val)) {
- php_error_docref(NULL, E_WARNING, "When enabling encryption you must specify the crypto type");
- RETURN_FALSE;
+ zend_argument_value_error(3, "must be specified when enabling encryption");
+ RETURN_THROWS();
}
cryptokind = Z_LVAL_P(val);
@@ -1539,8 +1508,7 @@ PHP_FUNCTION(stream_socket_enable_crypto)
}
/* }}} */
-/* {{{ proto string stream_resolve_include_path(string filename)
-Determine what file will be opened by calls to fopen() with a relative path */
+/* {{{ Determine what file will be opened by calls to fopen() with a relative path */
PHP_FUNCTION(stream_resolve_include_path)
{
char *filename;
@@ -1560,8 +1528,7 @@ PHP_FUNCTION(stream_resolve_include_path)
}
/* }}} */
-/* {{{ proto bool stream_is_local(resource stream|string url) U
-*/
+/* {{{ */
PHP_FUNCTION(stream_is_local)
{
zval *zstream;
@@ -1570,7 +1537,7 @@ PHP_FUNCTION(stream_is_local)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL(zstream)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
if (Z_TYPE_P(zstream) == IS_RESOURCE) {
php_stream_from_zval(stream, zstream);
@@ -1580,7 +1547,7 @@ PHP_FUNCTION(stream_is_local)
wrapper = stream->wrapper;
} else {
if (!try_convert_to_string(zstream)) {
- return;
+ RETURN_THROWS();
}
wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, 0);
@@ -1594,8 +1561,7 @@ PHP_FUNCTION(stream_is_local)
}
/* }}} */
-/* {{{ proto bool stream_supports_lock(resource stream)
- Tells whether the stream supports locking through flock(). */
+/* {{{ Tells whether the stream supports locking through flock(). */
PHP_FUNCTION(stream_supports_lock)
{
php_stream *stream;
@@ -1603,7 +1569,7 @@ PHP_FUNCTION(stream_supports_lock)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zsrc)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zsrc);
@@ -1614,9 +1580,7 @@ PHP_FUNCTION(stream_supports_lock)
RETURN_TRUE;
}
-/* {{{ proto bool stream_isatty(resource stream)
-Check if a stream is a TTY.
-*/
+/* {{{ Check if a stream is a TTY. */
PHP_FUNCTION(stream_isatty)
{
zval *zsrc;
@@ -1625,7 +1589,7 @@ PHP_FUNCTION(stream_isatty)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zsrc)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zsrc);
@@ -1652,8 +1616,7 @@ PHP_FUNCTION(stream_isatty)
}
#ifdef PHP_WIN32
-/* {{{ proto bool sapi_windows_vt100_support(resource stream[, bool enable])
- Get or set VT100 support for the specified stream associated to an
+/* {{{ Get or set VT100 support for the specified stream associated to an
output buffer of a Windows console.
*/
PHP_FUNCTION(sapi_windows_vt100_support)
@@ -1669,7 +1632,7 @@ PHP_FUNCTION(sapi_windows_vt100_support)
Z_PARAM_RESOURCE(zsrc)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(enable)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zsrc);
@@ -1680,12 +1643,11 @@ PHP_FUNCTION(sapi_windows_vt100_support)
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0);
}
else {
- zend_internal_type_error(
- ZEND_ARG_USES_STRICT_TYPES(),
+ zend_type_error(
"%s() was not able to analyze the specified stream",
get_active_function_name()
);
- RETURN_FALSE;
+ RETURN_THROWS();
}
/* Check if the file descriptor is a console */
@@ -1715,8 +1677,7 @@ PHP_FUNCTION(sapi_windows_vt100_support)
#endif
#ifdef HAVE_SHUTDOWN
-/* {{{ proto int stream_socket_shutdown(resource stream, int how)
- causes all or part of a full-duplex connection on the socket associated
+/* {{{ causes all or part of a full-duplex connection on the socket associated
with stream to be shut down. If how is SHUT_RD, further receptions will
be disallowed. If how is SHUT_WR, further transmissions will be disallowed.
If how is SHUT_RDWR, further receptions and transmissions will be
@@ -1730,7 +1691,7 @@ PHP_FUNCTION(stream_socket_shutdown)
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zstream)
Z_PARAM_LONG(how)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ ZEND_PARSE_PARAMETERS_END();
if (how != STREAM_SHUT_RD &&
how != STREAM_SHUT_WR &&