Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ PHPAPI zend_result php_stream_open_for_zend_ex(zend_file_handle *handle, int mod
handle->filename = filename;
handle->opened_path = opened_path;
handle->handle.stream.handle = stream;
handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
handle->handle.stream.reader = (zend_stream_reader_t)php_stream_read;
handle->handle.stream.fsizer = php_zend_stream_fsizer;
handle->handle.stream.isatty = 0;
handle->handle.stream.closer = php_zend_stream_closer;
Expand Down
106 changes: 39 additions & 67 deletions main/php_streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ static zend_always_inline bool php_stream_zend_parse_arg_into_stream(
#define PHP_Z_PARAM_STREAM_OR_NULL(dest) PHP_Z_PARAM_STREAM_EX(dest, true)

PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);
#define php_stream_free_enclosed(stream_enclosed, close_options) _php_stream_free_enclosed((stream_enclosed), (close_options))
PHPAPI int _php_stream_free_enclosed(php_stream *stream_enclosed, int close_options);
PHPAPI int php_stream_free_enclosed(php_stream *stream_enclosed, int close_options);

PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream);
#define PHP_STREAM_PERSISTENT_SUCCESS 0 /* id exists */
Expand All @@ -352,91 +351,68 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream *
#define PHP_STREAM_FREE_CLOSE_CASTED (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PRESERVE_HANDLE)
#define PHP_STREAM_FREE_CLOSE_PERSISTENT (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PERSISTENT)

PHPAPI int _php_stream_free(php_stream *stream, int close_options);
#define php_stream_free(stream, close_options) _php_stream_free((stream), (close_options))
#define php_stream_close(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE)
#define php_stream_pclose(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE_PERSISTENT)
PHPAPI int php_stream_free(php_stream *stream, int close_options);
#define php_stream_close(stream) php_stream_free((stream), PHP_STREAM_FREE_CLOSE)
#define php_stream_pclose(stream) php_stream_free((stream), PHP_STREAM_FREE_CLOSE_PERSISTENT)

PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence);
#define php_stream_rewind(stream) _php_stream_seek((stream), 0L, SEEK_SET)
#define php_stream_seek(stream, offset, whence) _php_stream_seek((stream), (offset), (whence))
PHPAPI int php_stream_seek(php_stream *stream, zend_off_t offset, int whence);
#define php_stream_rewind(stream) php_stream_seek((stream), 0L, SEEK_SET)

PHPAPI zend_off_t _php_stream_tell(const php_stream *stream);
#define php_stream_tell(stream) _php_stream_tell((stream))
PHPAPI zend_off_t php_stream_tell(const php_stream *stream);

PHPAPI ssize_t _php_stream_read(php_stream *stream, char *buf, size_t count);
#define php_stream_read(stream, buf, count) _php_stream_read((stream), (buf), (count))
PHPAPI ssize_t php_stream_read(php_stream *stream, char *buf, size_t count);

PHPAPI zend_string *php_stream_read_to_str(php_stream *stream, size_t len);

PHPAPI ssize_t _php_stream_write(php_stream *stream, const char *buf, size_t count);
#define php_stream_write_string(stream, str) _php_stream_write(stream, str, strlen(str))
#define php_stream_write(stream, buf, count) _php_stream_write(stream, (buf), (count))
PHPAPI ssize_t php_stream_write(php_stream *stream, const char *buf, size_t count);
#define php_stream_write_string(stream, str) php_stream_write(stream, str, strlen(str))

PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size);
#define php_stream_fill_read_buffer(stream, size) _php_stream_fill_read_buffer((stream), (size))
PHPAPI zend_result php_stream_fill_read_buffer(php_stream *stream, size_t size);

PHPAPI ssize_t _php_stream_printf(php_stream *stream, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
PHPAPI ssize_t php_stream_printf(php_stream *stream, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);

/* php_stream_printf macro & function require */
#define php_stream_printf _php_stream_printf
PHPAPI bool php_stream_eof(php_stream *stream);

PHPAPI bool _php_stream_eof(php_stream *stream);
#define php_stream_eof(stream) _php_stream_eof((stream))
PHPAPI int php_stream_getc(php_stream *stream);

PHPAPI int _php_stream_getc(php_stream *stream);
#define php_stream_getc(stream) _php_stream_getc((stream))
PHPAPI int php_stream_putc(php_stream *stream, int c);

PHPAPI int _php_stream_putc(php_stream *stream, int c);
#define php_stream_putc(stream, c) _php_stream_putc((stream), (c))
PHPAPI int php_stream_flush(php_stream *stream);

PHPAPI int _php_stream_flush(php_stream *stream, int closing);
#define php_stream_flush(stream) _php_stream_flush((stream), 0)
PHPAPI int php_stream_sync(php_stream *stream, bool data_only);

PHPAPI int _php_stream_sync(php_stream *stream, bool data_only);
#define php_stream_sync(stream, d) _php_stream_sync((stream), (d))
PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len);
#define php_stream_gets(stream, buf, maxlen) php_stream_get_line((stream), (buf), (maxlen), NULL)

PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len);
#define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL)

#define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen))
PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len);

/* Returns true if buffer has been appended, false on error */
PHPAPI bool _php_stream_puts(php_stream *stream, const char *buf);
#define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf))
PHPAPI bool php_stream_puts(php_stream *stream, const char *buf);

PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb);
#define php_stream_stat(stream, ssb) _php_stream_stat((stream), (ssb))
PHPAPI int php_stream_stat(php_stream *stream, php_stream_statbuf *ssb);

PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context);
#define php_stream_stat_path(path, ssb) _php_stream_stat_path((path), 0, (ssb), NULL)
#define php_stream_stat_path_ex(path, flags, ssb, context) _php_stream_stat_path((path), (flags), (ssb), (context))
PHPAPI int php_stream_stat_path_ex(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context);
#define php_stream_stat_path(path, ssb) php_stream_stat_path_ex((path), 0, (ssb), NULL)

PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context);
#define php_stream_mkdir(path, mode, options, context) _php_stream_mkdir(path, mode, options, context)
PHPAPI int php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context);

PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context);
#define php_stream_rmdir(path, options, context) _php_stream_rmdir(path, options, context)
PHPAPI int php_stream_rmdir(const char *path, int options, php_stream_context *context);

PHPAPI php_stream *_php_stream_opendir(const char *path, int options, php_stream_context *context STREAMS_DC);
#define php_stream_opendir(path, options, context) _php_stream_opendir((path), (options), (context) STREAMS_CC)
PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent);
#define php_stream_readdir(dirstream, dirent) _php_stream_readdir((dirstream), (dirent))
PHPAPI php_stream_dirent *php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent);
#define php_stream_closedir(dirstream) php_stream_close((dirstream))
#define php_stream_rewinddir(dirstream) php_stream_rewind((dirstream))

PHPAPI int php_stream_dirent_alphasort(const zend_string **a, const zend_string **b);
PHPAPI int php_stream_dirent_alphasortr(const zend_string **a, const zend_string **b);

PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], int flags, php_stream_context *context,
PHPAPI int php_stream_scandir(const char *dirname, zend_string **namelist[], php_stream_context *context,
int (*compare) (const zend_string **a, const zend_string **b));
#define php_stream_scandir(dirname, namelist, context, compare) _php_stream_scandir((dirname), (namelist), 0, (context), (compare))

PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam);
#define php_stream_set_option(stream, option, value, ptrvalue) _php_stream_set_option((stream), (option), (value), (ptrvalue))
PHPAPI int php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam);

#define php_stream_set_chunk_size(stream, size) _php_stream_set_option((stream), PHP_STREAM_OPTION_SET_CHUNK_SIZE, (size), NULL)
#define php_stream_set_chunk_size(stream, size) php_stream_set_option((stream), PHP_STREAM_OPTION_SET_CHUNK_SIZE, (size), NULL)

END_EXTERN_C()

Expand Down Expand Up @@ -475,8 +451,8 @@ END_EXTERN_C()
/* whether or not locking is supported */
#define PHP_STREAM_LOCK_SUPPORTED 1

#define php_stream_supports_lock(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED) == 0 ? 1 : 0)
#define php_stream_lock(stream, mode) _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL)
#define php_stream_supports_lock(stream) (php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED) == 0 ? 1 : 0)
#define php_stream_lock(stream, mode) php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL)

/* option code used by the php_stream_xport_XXX api */
#define PHP_STREAM_OPTION_XPORT_API 7 /* see php_stream_transport.h */
Expand All @@ -487,15 +463,14 @@ END_EXTERN_C()
#define PHP_STREAM_TRUNCATE_SUPPORTED 0
#define PHP_STREAM_TRUNCATE_SET_SIZE 1 /* ptrparam is a pointer to a size_t */

#define php_stream_truncate_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SUPPORTED, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
#define php_stream_truncate_supported(stream) (php_stream_set_option((stream), PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SUPPORTED, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)

BEGIN_EXTERN_C()
PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize);
#define php_stream_truncate_set_size(stream, size) _php_stream_truncate_set_size((stream), (size))
PHPAPI int php_stream_truncate_set_size(php_stream *stream, size_t newsize);
END_EXTERN_C()

#define PHP_STREAM_OPTION_META_DATA_API 11 /* ptrparam is a zval* to which to add metadata information */
#define php_stream_populate_meta_data(stream, zv) (_php_stream_set_option((stream), PHP_STREAM_OPTION_META_DATA_API, 0, zv) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
#define php_stream_populate_meta_data(stream, zv) (php_stream_set_option((stream), PHP_STREAM_OPTION_META_DATA_API, 0, zv) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)

/* Check if the stream is still "live"; for sockets/pipes this means the socket
* is still connected; for files, this does not really have meaning */
Expand All @@ -510,7 +485,7 @@ END_EXTERN_C()
#define PHP_STREAM_SYNC_FSYNC 1
#define PHP_STREAM_SYNC_FDSYNC 2

#define php_stream_sync_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_SYNC_API, PHP_STREAM_SYNC_SUPPORTED, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
#define php_stream_sync_supported(stream) (php_stream_set_option((stream), PHP_STREAM_OPTION_SYNC_API, PHP_STREAM_SYNC_SUPPORTED, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)


#define PHP_STREAM_OPTION_RETURN_OK 0 /* option set OK */
Expand Down Expand Up @@ -564,11 +539,10 @@ END_EXTERN_C()
#define PHP_STREAM_CAST_INTERNAL 0x20000000 /* stream cast for internal use */
#define PHP_STREAM_CAST_MASK (PHP_STREAM_CAST_TRY_HARD | PHP_STREAM_CAST_RELEASE | PHP_STREAM_CAST_INTERNAL)
BEGIN_EXTERN_C()
PHPAPI zend_result _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err);
PHPAPI zend_result php_stream_cast(php_stream *stream, int castas, void **ret, int show_err);
END_EXTERN_C()
/* use this to check if a stream can be cast into another form */
#define php_stream_can_cast(stream, as) _php_stream_cast((stream), (as), NULL, 0)
#define php_stream_cast(stream, as, ret, show_err) _php_stream_cast((stream), (as), (ret), (show_err))
#define php_stream_can_cast(stream, as) php_stream_cast((stream), (as), NULL, 0)

/* use this to check if a stream is of a particular type:
* PHPAPI int php_stream_is(php_stream *stream, php_stream_ops *ops); */
Expand Down Expand Up @@ -660,11 +634,9 @@ PHPAPI php_stream_make_seekable_status _php_stream_make_seekable(php_stream *ori
#define php_stream_make_seekable(origstream, newstream, flags) _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_CC)

/* Give other modules access to the url_stream_wrappers_hash and stream_filters_hash */
PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(void);
#define php_stream_get_url_stream_wrappers_hash() _php_stream_get_url_stream_wrappers_hash()
PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash(void);
PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void);
PHPAPI HashTable *_php_get_stream_filters_hash(void);
#define php_get_stream_filters_hash() _php_get_stream_filters_hash()
PHPAPI HashTable *php_get_stream_filters_hash(void);
PHPAPI HashTable *php_get_stream_filters_hash_global(void);
extern const php_stream_wrapper_ops *php_stream_user_wrapper_ops;

Expand Down
2 changes: 1 addition & 1 deletion main/streams/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *resul
}
/* }}} */
/* {{{ php_stream_cast */
PHPAPI zend_result _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err)
PHPAPI zend_result php_stream_cast(php_stream *stream, int castas, void **ret, int show_err)
{
int flags = castas & PHP_STREAM_CAST_MASK;
castas &= ~PHP_STREAM_CAST_MASK;
Expand Down
8 changes: 4 additions & 4 deletions main/streams/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PHPAPI HashTable *php_get_stream_filters_hash_global(void)
}

/* Normal hash selection/retrieval call */
PHPAPI HashTable *_php_get_stream_filters_hash(void)
PHPAPI HashTable *php_get_stream_filters_hash(void)
{
return (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ PHPAPI void php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_str
filter->chain = chain;
}

PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter)
PHPAPI void php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter)
{
php_stream_filter_prepend_ex(chain, filter);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ PHPAPI zend_result php_stream_filter_append_ex(php_stream_filter_chain *chain, p
return SUCCESS;
}

PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter)
PHPAPI void php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter)
{
if (php_stream_filter_append_ex(chain, filter) != SUCCESS) {
if (chain->head == filter) {
Expand All @@ -447,7 +447,7 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream
}
}

PHPAPI zend_result _php_stream_filter_flush(php_stream_filter *filter, bool finish)
PHPAPI zend_result php_stream_filter_flush(php_stream_filter *filter, bool finish)
{
php_stream_bucket_brigade brig_a = { NULL, NULL }, brig_b = { NULL, NULL }, *inp = &brig_a, *outp = &brig_b, *brig_temp;
php_stream_bucket *bucket;
Expand Down
4 changes: 2 additions & 2 deletions main/streams/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
return NULL;
}

PHPAPI int _php_stream_mmap_unmap(php_stream *stream)
PHPAPI int php_stream_mmap_unmap(php_stream *stream)
{
return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK;
}

PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)
PHPAPI int php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)
{
int ret = 1;

Expand Down
9 changes: 3 additions & 6 deletions main/streams/php_stream_filter_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ struct _php_stream_filter {

/* stack filter onto a stream */
BEGIN_EXTERN_C()
PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter);
PHPAPI void php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter);
PHPAPI void php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter);
PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter);
PHPAPI void php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter);
PHPAPI zend_result php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter);
PHPAPI zend_result _php_stream_filter_flush(php_stream_filter *filter, bool finish);
PHPAPI zend_result php_stream_filter_flush(php_stream_filter *filter, bool finish);
PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, bool call_dtor);
PHPAPI void php_stream_filter_free(php_stream_filter *filter);
PHPAPI php_stream_filter *_php_stream_filter_alloc(const php_stream_filter_ops *fops,
Expand All @@ -153,9 +153,6 @@ END_EXTERN_C()
_php_stream_filter_alloc((fops), (thisptr), (persistent), (rseek), (wseek) STREAMS_CC)
#define php_stream_filter_alloc_rel(fops, thisptr, persistent, rseek, wseek) \
_php_stream_filter_alloc((fops), (thisptr), (persistent), (rseek), (wseek) STREAMS_REL_CC)
#define php_stream_filter_prepend(chain, filter) _php_stream_filter_prepend((chain), (filter))
#define php_stream_filter_append(chain, filter) _php_stream_filter_append((chain), (filter))
#define php_stream_filter_flush(filter, finish) _php_stream_filter_flush((filter), (finish))

#define php_stream_is_filtered(stream) ((stream)->readfilters.head || (stream)->writefilters.head)

Expand Down
8 changes: 3 additions & 5 deletions main/streams/php_stream_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct {

#define PHP_STREAM_MMAP_MAX (512 * 1024 * 1024)

#define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL) == 0 ? 1 : 0)
#define php_stream_mmap_supported(stream) (php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL) == 0 ? 1 : 0)

/* Returns 1 if the stream in its current state can be memory mapped,
* 0 otherwise */
Expand All @@ -67,9 +67,7 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
#define php_stream_mmap_range(stream, offset, length, mode, mapped_len) _php_stream_mmap_range((stream), (offset), (length), (mode), (mapped_len))

/* un-maps the last mapped range */
PHPAPI int _php_stream_mmap_unmap(php_stream *stream);
#define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream))
PHPAPI int php_stream_mmap_unmap(php_stream *stream);

PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden);
#define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden))
PHPAPI int php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden);
END_EXTERN_C()
Loading
Loading