summaryrefslogtreecommitdiff
path: root/main/streams
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2003-02-24 21:40:23 +0000
committerWez Furlong <wez@php.net>2003-02-24 21:40:23 +0000
commit088e2692c3d1e680fd3d9306c4adb417e761acff (patch)
tree35d276f141492b5a78779d8d95c58f7fce174dde /main/streams
parent4474f9225a599d3f4cd3674e777d40a531d3c63b (diff)
downloadphp-git-088e2692c3d1e680fd3d9306c4adb417e761acff.tar.gz
MFB: Bunch of streams related fixes.
Diffstat (limited to 'main/streams')
-rw-r--r--main/streams/cast.c7
-rw-r--r--main/streams/plain_wrapper.c14
-rwxr-xr-xmain/streams/streams.c22
3 files changed, 27 insertions, 16 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c
index 66acd141a3..aa6e6d12b2 100644
--- a/main/streams/cast.c
+++ b/main/streams/cast.c
@@ -208,7 +208,12 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
return FAILURE;
#endif
- if (flags & PHP_STREAM_CAST_TRY_HARD) {
+ if (!php_stream_is_filtered(stream) && stream->ops->cast && stream->ops->cast(stream, castas, NULL TSRMLS_CC) == SUCCESS) {
+ if (FAILURE == stream->ops->cast(stream, castas, ret TSRMLS_CC)) {
+ return FAILURE;
+ }
+ goto exit_success;
+ } else if (flags & PHP_STREAM_CAST_TRY_HARD) {
php_stream *newstream;
newstream = php_stream_fopen_tmpfile();
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index d45e6a1098..cf85586d78 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -603,7 +603,7 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char
DIR *dir = NULL;
php_stream *stream = NULL;
- if (php_check_open_basedir(path TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
}
@@ -637,7 +637,7 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, ch
return php_stream_fopen_with_path_rel(path, mode, PG(include_path), opened_path, options);
}
- if (php_check_open_basedir(path TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
}
@@ -702,7 +702,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char
}
- if (php_check_open_basedir(filename TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
return NULL;
}
@@ -722,7 +722,7 @@ not_relative_path:
/* Absolute path open */
if (IS_ABSOLUTE_PATH(filename, filename_length)) {
- if (php_check_open_basedir(filename TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
return NULL;
}
@@ -748,7 +748,7 @@ not_relative_path:
free(cwd);
- if (php_check_open_basedir(trypath TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(trypath TSRMLS_CC)) {
return NULL;
}
if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) {
@@ -764,7 +764,7 @@ not_relative_path:
if (!path || (path && !*path)) {
- if (php_check_open_basedir(path TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
}
@@ -809,7 +809,7 @@ not_relative_path:
}
snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
- if (php_check_open_basedir(trypath TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(trypath TSRMLS_CC)) {
stream = NULL;
goto stream_done;
}
diff --git a/main/streams/streams.c b/main/streams/streams.c
index ae33818b79..e798684d18 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -801,6 +801,16 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size
{
size_t didwrite = 0, towrite, justwrote;
+ /* if we have a seekable stream we need to ensure that data is written at the
+ * current stream->position. This means invalidating the read buffer and then
+ * performing a low-level seek */
+ if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
+ stream->readpos = stream->writepos = 0;
+
+ stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC);
+ }
+
+
while (count > 0) {
towrite = count;
if (towrite > stream->chunk_size)
@@ -817,8 +827,6 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size
* buffered from fifos and sockets */
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && !php_stream_is_filtered(stream)) {
stream->position += justwrote;
- stream->writepos = 0;
- stream->readpos = 0;
}
} else {
break;
@@ -947,10 +955,6 @@ PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC)
PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC)
{
- /* not moving anywhere */
- if ((offset == 0 && whence == SEEK_CUR) || (offset == stream->position && whence == SEEK_SET))
- return 0;
-
/* handle the case where we are in the buffer */
if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
switch(whence) {
@@ -974,8 +978,6 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_
}
}
- /* invalidate the buffer contents */
- stream->readpos = stream->writepos = 0;
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
int ret;
@@ -995,6 +997,10 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_
if (((stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) || ret == 0) {
if (ret == 0)
stream->eof = 0;
+
+ /* invalidate the buffer contents */
+ stream->readpos = stream->writepos = 0;
+
return ret;
}
/* else the stream has decided that it can't support seeking after all;