summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-17 21:37:38 +0200
committerwm4 <wm4@nowhere>2014-10-17 21:43:18 +0200
commita7eb363ac1acb5566ce1af923d07c658361d5ad4 (patch)
treeb085c3658dae7e76d8d306031e50fd2b75953ed0 /osdep
parent0abe9b0e0af03199fbc48b41ff38b0e0fa137cf2 (diff)
downloadmpv-a7eb363ac1acb5566ce1af923d07c658361d5ad4.tar.bz2
mpv-a7eb363ac1acb5566ce1af923d07c658361d5ad4.tar.xz
win32: make lseek() fail on pipes
On MingGW seeking on pipes succeeds. This fix is quite similar to Gnulib's (lib/lseek.c).
Diffstat (limited to 'osdep')
-rw-r--r--osdep/io.c11
-rw-r--r--osdep/io.h8
2 files changed, 19 insertions, 0 deletions
diff --git a/osdep/io.c b/osdep/io.c
index 819cdcbf69..b93618400c 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -17,6 +17,7 @@
* You should have received a copy of the GNU General Public License along
* with mplayer2. If not, see <http://www.gnu.org/licenses/>.
*/
+#define MP_HIDE_IO_REPLACEMENTS
#include <unistd.h>
#include <errno.h>
@@ -395,4 +396,14 @@ char *mp_getenv(const char *name)
return NULL;
}
+off_t mp_lseek(int fd, off_t offset, int whence)
+{
+ HANDLE h = (HANDLE)_get_osfhandle(fd);
+ if (h != INVALID_HANDLE_VALUE && GetFileType(h) != FILE_TYPE_DISK) {
+ errno = ESPIPE;
+ return (off_t)-1;
+ }
+ return lseek(fd, offset, whence);
+}
+
#endif // __MINGW32__
diff --git a/osdep/io.h b/osdep/io.h
index ae3cdc1802..a24ad7c231 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -77,6 +77,7 @@ int mp_closedir(DIR *dir);
int mp_mkdir(const char *path, int mode);
FILE *mp_tmpfile(void);
char *mp_getenv(const char *name);
+off_t mp_lseek(int fd, off_t offset, int whence);
typedef struct {
size_t gl_pathc;
@@ -105,6 +106,13 @@ void mp_globfree(mp_glob_t *pglob);
#define tmpfile(...) mp_tmpfile(__VA_ARGS__)
#define getenv(...) mp_getenv(__VA_ARGS__)
+// Things MinGW defines as macros, and which we want to override only for the
+// user, and not io.c (which wants the original definition).
+#ifndef MP_HIDE_IO_REPLACEMENTS
+#undef lseek
+#define lseek(...) mp_lseek(__VA_ARGS__)
+#endif
+
#ifndef GLOB_NOMATCH
#define GLOB_NOMATCH 3
#endif