summaryrefslogtreecommitdiffstats
path: root/osdep/io.h
diff options
context:
space:
mode:
authorJames Ross-Gowan <rossy@jrg.systems>2017-10-23 21:01:45 +1100
committerJames Ross-Gowan <rossy@jrg.systems>2017-10-25 22:37:20 +1100
commit257a2b9646e845ef801588e871b9859d30ebf99a (patch)
tree7f9c3aec6ee54f9100ca191acd83e3a5cd0f4854 /osdep/io.h
parenta5b51f75dc049b0713f4bb77cae4cb9e39ae8d49 (diff)
downloadmpv-257a2b9646e845ef801588e871b9859d30ebf99a.tar.bz2
mpv-257a2b9646e845ef801588e871b9859d30ebf99a.tar.xz
win32: add more-POSIXy versions of open() and fstat()
Directory-opening never worked on Windows because MSVCRT's open() doesn't open directories and its fstat() doesn't recognise directory handles. These are just MSVCRT restrictions, and the Windows API itself has no problem with opening directories as file objects, so reimplement mpv's mp_open and mp_stat to use the Windows API directly. This should fix directory playback. This also populates the st_dev and st_ino fields of struct stat, so filesystem loop checking in demux_playlist.c should now work on Windows. Fixes #4711
Diffstat (limited to 'osdep/io.h')
-rw-r--r--osdep/io.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/osdep/io.h b/osdep/io.h
index 70ba5ac1ae..55173ea1d7 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -107,15 +107,25 @@ FILE *mp_tmpfile(void);
char *mp_getenv(const char *name);
off_t mp_lseek(int fd, off_t offset, int whence);
-// MinGW-w64 will define "stat" to something useless. Since this affects both
-// the type (struct stat) and the stat() function, it makes us harder to
-// override these separately.
-// Corresponds to struct _stat64 (copy & pasted, but using public types).
+// mp_stat types. MSVCRT's dev_t and ino_t are way too short to be unique.
+typedef uint64_t mp_dev_t_;
+#ifdef _WIN64
+typedef unsigned __int128 mp_ino_t_;
+#else
+// 32-bit Windows doesn't have a __int128-type, which means ReFS file IDs will
+// be truncated and might collide. This is probably not a problem because ReFS
+// is not available in consumer versions of Windows.
+typedef uint64_t mp_ino_t_;
+#endif
+#define dev_t mp_dev_t_
+#define ino_t mp_ino_t_
+
+// mp_stat uses a different structure to MSVCRT, with 64-bit inodes
struct mp_stat {
dev_t st_dev;
ino_t st_ino;
unsigned short st_mode;
- short st_nlink;
+ unsigned int st_nlink;
short st_uid;
short st_gid;
dev_t st_rdev;