diff --git a/main/php_streams.h b/main/php_streams.h index 37e1f3e01b01..54baead30fe3 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -341,10 +341,14 @@ static zend_always_inline bool php_stream_zend_parse_arg_into_stream( PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed); 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 */ -#define PHP_STREAM_PERSISTENT_FAILURE 1 /* id exists but is not a stream! */ -#define PHP_STREAM_PERSISTENT_NOT_EXIST 2 /* id does not exist */ + +C23_ENUM(php_stream_persistent_status, uint8_t) { + PHP_STREAM_PERSISTENT_SUCCESS = 0, /* id exists */ + PHP_STREAM_PERSISTENT_FAILURE = 1, /* id exists but is not a stream! */ + PHP_STREAM_PERSISTENT_NOT_EXIST = 2, /* id does not exist */ +}; + +PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id, php_stream **stream); #define PHP_STREAM_FREE_CALL_DTOR 1 /* call ops->close */ #define PHP_STREAM_FREE_RELEASE_STREAM 2 /* pefree(stream) */ diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index ccf38ca0d543..376936607919 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1220,6 +1220,9 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen case PHP_STREAM_PERSISTENT_FAILURE: efree(persistent_id); return ret; + case PHP_STREAM_PERSISTENT_NOT_EXIST: + /* Fallthrough to open new stream */ + break; } } #ifdef PHP_WIN32 diff --git a/main/streams/streams.c b/main/streams/streams.c index 8175c666daba..3e948add11fd 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -105,7 +105,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos return orig; } -PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream) +PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id, php_stream **stream) { zend_resource *le; @@ -250,8 +250,8 @@ static int php_stream_flush_ex(php_stream *stream, bool closing); PHPAPI int php_stream_free(php_stream *stream, int close_options) /* {{{ */ { int ret = 1; - int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; - int release_cast = 1; + bool preserve_handle = (close_options & PHP_STREAM_FREE_PRESERVE_HANDLE) ? true : false; + bool release_cast = true; php_stream_context *context; /* During shutdown resources may be released before other resources still holding them. @@ -270,7 +270,7 @@ PHPAPI int php_stream_free(php_stream *stream, int close_options) /* {{{ */ if ((stream->flags & PHP_STREAM_FLAG_NO_CLOSE) || ((stream->flags & PHP_STREAM_FLAG_NO_RSCR_DTOR_CLOSE) && (close_options & PHP_STREAM_FREE_RSRC_DTOR))) { - preserve_handle = 1; + preserve_handle = true; } #if STREAM_DEBUG @@ -322,7 +322,7 @@ PHPAPI int php_stream_free(php_stream *stream, int close_options) /* {{{ */ return 0; } /* otherwise, make sure that we don't close the FILE* from a cast */ - release_cast = 0; + release_cast = false; } #if STREAM_DEBUG @@ -372,7 +372,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov php_io_poll_stream_notify_close(stream); } - ret = stream->ops->close(stream, preserve_handle ? 0 : 1); + ret = stream->ops->close(stream, !preserve_handle); if (!ret) { ret = flush_result; } @@ -866,11 +866,11 @@ PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t avail = 0; size_t current_buf_size = 0; size_t total_copied = 0; - int grow_mode = 0; + bool grow_mode = false; char *bufstart = buf; if (buf == NULL) { - grow_mode = 1; + grow_mode = true; } else if (maxlen == 0) { return NULL; } @@ -895,14 +895,14 @@ PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t cpysz = 0; char *readptr; const char *eol; - int done = 0; + bool done = false; readptr = (char*)stream->readbuf + stream->readpos; eol = php_stream_locate_eol(stream, NULL); if (eol) { cpysz = eol - readptr + 1; - done = 1; + done = true; } else { cpysz = avail; } @@ -924,7 +924,7 @@ PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, } else { if (cpysz >= maxlen - 1) { cpysz = maxlen - 1; - done = 1; + done = true; } } diff --git a/main/streams/transports.c b/main/streams/transports.c index a1410aa4a0e4..f8f74c606144 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -84,7 +84,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in /* fall through */ case PHP_STREAM_PERSISTENT_FAILURE: - default: + case PHP_STREAM_PERSISTENT_NOT_EXIST: /* failed; get a new one */ ; }