From 8665f7801837ac29f0171437e1c1cb7d6d51e410 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 24 May 2014 14:06:18 +0200 Subject: stream_file: readjust some windows ifdeffery Also sneak in some cosmetics. setmode() exists on Windows/msvcrt only, so there's no need for a config test. I couldn't reproduce the problem with seekable pipes on wine, so axe it. (I'm aware that it still could be an issue on real Windows.) --- stream/stream_file.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'stream') diff --git a/stream/stream_file.c b/stream/stream_file.c index a0ffc9114f..6b9c6d5471 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -91,9 +91,7 @@ static int control(stream_t *s, int cmd, void *arg) struct priv *p = s->priv; switch (cmd) { case STREAM_CTRL_GET_SIZE: { - off_t size; - - size = lseek(p->fd, 0, SEEK_END); + off_t size = lseek(p->fd, 0, SEEK_END); lseek(p->fd, s->pos, SEEK_SET); if (size != (off_t)-1) { *(int64_t *)arg = size; @@ -227,16 +225,13 @@ static int open_f(stream_t *stream) if (!write) { MP_INFO(stream, "Reading from stdin...\n"); fd = 0; -#if HAVE_SETMODE - setmode(fileno(stdin), O_BINARY); -#endif } else { - MP_INFO(stream, "Writing to stdout\n"); + MP_INFO(stream, "Writing to stdout...\n"); fd = 1; -#if HAVE_SETMODE - setmode(fileno(stdout), O_BINARY); -#endif } +#ifdef __MINGW32__ + setmode(fd, O_BINARY); +#endif priv->fd = fd; priv->close = false; } else { @@ -250,34 +245,25 @@ static int open_f(stream_t *stream) filename, strerror(errno)); return STREAM_ERROR; } -#ifndef __MINGW32__ struct stat st; if (fstat(fd, &st) == 0 && S_ISDIR(st.st_mode)) { MP_ERR(stream, "File is a directory: '%s'\n", filename); close(fd); return STREAM_ERROR; } -#endif priv->fd = fd; priv->close = true; } - int64_t len = lseek(fd, 0, SEEK_END); + off_t len = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); -#ifdef __MINGW32__ - // seeks on stdin incorrectly succeed on MinGW - if (fd == 0) - len = -1; -#endif - stream->type = STREAMTYPE_FILE; - stream->fast_skip = true; - if (len >= 0) { + if (len != (off_t)-1) { stream->seek = seek; stream->seekable = true; } - MP_VERBOSE(stream, "File size is %" PRId64 " bytes\n", len); - + stream->type = STREAMTYPE_FILE; + stream->fast_skip = true; stream->fill_buffer = fill_buffer; stream->write_buffer = write_buffer; stream->control = control; -- cgit v1.2.3