summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-24 14:06:18 +0200
committerwm4 <wm4@nowhere>2014-05-24 16:17:52 +0200
commit8665f7801837ac29f0171437e1c1cb7d6d51e410 (patch)
tree16b5a8aa7f1527630d58fb6690d57c0d58172ecb /stream
parentaa87c143cb369f1448f8d08086b5ef98998b4436 (diff)
downloadmpv-8665f7801837ac29f0171437e1c1cb7d6d51e410.tar.bz2
mpv-8665f7801837ac29f0171437e1c1cb7d6d51e410.tar.xz
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.)
Diffstat (limited to 'stream')
-rw-r--r--stream/stream_file.c32
1 files changed, 9 insertions, 23 deletions
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;