From f63193f58f7214ef3a4f82be045f8a3cfd14b8ac Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:07:07 +0200 Subject: stream: remove fd member Stream implementations could set this to a unix file descriptor. The generic stream code could use it as fallback for a few things. This was confusing and insane. In most cases, the stream implementations defined all callbacks, so setting the fd member didn't have any advantages, other than avoiding defining a private struct to store it. It appears that even if the stream implementation used close() on the fd (or something equivalent), stream.c would close() it a second time (and on windows, even would call closesocket()), which should be proof for the insanity of this code. For stream_file.c, additionally make sure we don't close stdin or stdout if "-" is used as filename. For stream_vcd.c, remove the control() code. This code most likely didn't make the slightest sense, because it used a different type for stream->priv. It also leaked memory. Maybe it worked, but it's incorrect and insignificant anyway, so kill it. This code was added with commit 9521c19 (svn commit 31019). Untested for all protocols other than stream_file.c. --- stream/stream.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index ead4a55b3d..1e53b75c4e 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -315,13 +315,7 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len) int orig_len = len; s->buf_pos = s->buf_len = 0; // we will retry even if we already reached EOF previously. - if (s->fill_buffer) { - len = s->fill_buffer(s, buf, len); - } else if (s->fd >= 0) { - len = read(s->fd, buf, len); - } else { - len = 0; - } + len = s->fill_buffer ? s->fill_buffer(s, buf, len) : -1; if (len < 0) len = 0; if (len == 0) { @@ -590,8 +584,6 @@ static stream_t *new_stream(size_t min_size) min_size = FFMAX(min_size, TOTAL_BUFFER_SIZE); stream_t *s = talloc_size(NULL, sizeof(stream_t) + min_size); memset(s, 0, sizeof(stream_t)); - - s->fd = -2; return s; } @@ -604,9 +596,6 @@ void free_stream(stream_t *s) if (s->close) s->close(s); - if (s->fd > 0) { - close(s->fd); - } free_stream(s->uncached_stream); talloc_free(s); } -- cgit v1.2.3