From aa87c143cb369f1448f8d08086b5ef98998b4436 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 24 May 2014 14:06:13 +0200 Subject: stream: remove chaos related to writeable streams For some reason, we support writeable streams. (Only encoding uses that, and the use of it looks messy enough that I want to replace it with FILE or avio today.) It's a chaos: most streams do not actually check the mode parameter like they should. Simplify it, and let streams signal availability of write mode by setting a flag in the stream info struct. --- stream/stream.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 3ea4d475b7..baee62221f 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -289,6 +289,13 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying, s->path = talloc_strdup(s, path); s->source = underlying; s->allow_caching = true; + s->mode = flags & (STREAM_READ | STREAM_WRITE); + + if ((s->mode & STREAM_WRITE) && !sinfo->can_write) { + MP_ERR(s, "No write access implemented.\n"); + talloc_free(s); + return STREAM_ERROR; + } // Parse options if (sinfo->priv_size) { @@ -306,8 +313,7 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying, } } - s->mode = flags & (STREAM_READ | STREAM_WRITE); - int r = sinfo->open(s, s->mode); + int r = sinfo->open(s); if (r != STREAM_OK) { talloc_free(s); return r; -- cgit v1.2.3