From 98627d3a32e993ebdaa1598834f2057d9952c7e4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2019 15:26:35 +0200 Subject: io: remove Windows tmpfile() emulation Unused now. The old stream cache used it, but it was removed. On a side note, the demuxer cache uses mp_mkostemps(). It looks like our Windows open() emulation handles this correctly by using CREATE_NEW, so no functionality gets lost by the "new" approach. On the other hand, the demuxer cache does not set FILE_FLAG_DELETE_ON_CLOSE, but instead tries to delete the file after opening (POSIX style), which probably won't work on Windows. But I'm not sure how to make it use the DELETE_ON_CLOSE flag, so whatever. --- osdep/io.c | 35 ----------------------------------- osdep/io.h | 2 -- 2 files changed, 37 deletions(-) (limited to 'osdep') diff --git a/osdep/io.c b/osdep/io.c index f45b93a333..db61a705fd 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -632,41 +632,6 @@ char *mp_win32_getcwd(char *buf, size_t size) return buf; } -FILE *mp_tmpfile(void) -{ - // Reserve a file name in the format %TMP%\mpvXXXX.TMP - wchar_t tmp_path[MAX_PATH + 1]; - if (!GetTempPathW(MAX_PATH + 1, tmp_path)) - return NULL; - wchar_t tmp_name[MAX_PATH + 1]; - if (!GetTempFileNameW(tmp_path, L"mpv", 0, tmp_name)) - return NULL; - - // Create the file. FILE_ATTRIBUTE_TEMPORARY indicates the file will be - // short-lived. Windows should avoid flushing it to disk while there is - // sufficient cache. - HANDLE file = CreateFileW(tmp_name, GENERIC_READ | GENERIC_WRITE | DELETE, - FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, - FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); - if (file == INVALID_HANDLE_VALUE) { - DeleteFileW(tmp_name); - return NULL; - } - - int fd = _open_osfhandle((intptr_t)file, 0); - if (fd < 0) { - CloseHandle(file); - return NULL; - } - FILE *fp = fdopen(fd, "w+b"); - if (!fp) { - close(fd); - return NULL; - } - - return fp; -} - static char **utf8_environ; static void *utf8_environ_ctx; diff --git a/osdep/io.h b/osdep/io.h index 131f3e2fee..a1c65f18e9 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -104,7 +104,6 @@ struct dirent *mp_readdir(DIR *dir); int mp_closedir(DIR *dir); int mp_mkdir(const char *path, int mode); char *mp_win32_getcwd(char *buf, size_t size); -FILE *mp_tmpfile(void); char *mp_getenv(const char *name); off_t mp_lseek(int fd, off_t offset, int whence); @@ -161,7 +160,6 @@ void mp_globfree(mp_glob_t *pglob); #define closedir(...) mp_closedir(__VA_ARGS__) #define mkdir(...) mp_mkdir(__VA_ARGS__) #define getcwd(...) mp_win32_getcwd(__VA_ARGS__) -#define tmpfile(...) mp_tmpfile(__VA_ARGS__) #define getenv(...) mp_getenv(__VA_ARGS__) #undef lseek -- cgit v1.2.3