$split = parse_url($path);
$this->varname = $split["host"];
- $this->position = 0;
+
+ if (strchr($mode, 'a'))
+ $this->position = strlen($GLOBALS[$this->varname]);
+ else
+ $this->position = 0;
return true;
}
if ($fail_count == 0) {
echo "FGETS: OK\n";
}
+
+/* One final test to see if the position is respected when opened for append */
+$fp = fopen("test://lyrics", "a+");
+rewind($fp);
+var_dump(ftell($fp));
+$data = fgets($fp);
+fclose($fp);
+echo $data . "\n";
+
?>
--EXPECT--
Not Registered
Registered
SEEK: OK
FGETS: OK
+int(0)
+...and the road becomes my bride
stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
- if (stream && self->is_pipe) {
- stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
+ if (stream) {
+ if (self->is_pipe) {
+ stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
+ } else {
+ stream->position = ftell(file);
+ }
}
return stream;
}
}
}
+
+ if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a')) {
+ fpos_t newpos = 0;
+
+ /* if opened for append, we need to revise our idea of the initial file position */
+ if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) {
+ stream->position = newpos;
+ }
+ }
+
if (stream == NULL && (options & REPORT_ERRORS)) {
display_wrapper_errors(wrapper, path, "failed to create stream" TSRMLS_CC);
}