[vlc-commits] Win32: reimplement tmpfile()
Jean-Baptiste Kempf
git at videolan.org
Mon Feb 16 20:27:54 CET 2015
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Feb 16 19:17:10 2015 +0100| [3f08049ef7f3a963774590c0570d4b41cd777c65] | committer: Jean-Baptiste Kempf
Win32: reimplement tmpfile()
Because tmpfile() cannot be used if not admin on the machine on
Windows...
Close #13642
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3f08049ef7f3a963774590c0570d4b41cd777c65
---
include/vlc_fixups.h | 4 ++++
src/text/strings.c | 2 ++
src/win32/filesystem.c | 33 +++++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index cee1254..b949d24 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -369,4 +369,8 @@ struct addrinfo
#define nanf(tagp) NAN
#endif
+#ifdef _WIN32
+FILE *vlc_win32_tmpfile(void);
+#endif
+
#endif /* !LIBVLC_FIXUPS_H */
diff --git a/src/text/strings.c b/src/text/strings.c
index e0fd28c..5063e78 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -534,6 +534,8 @@ char *str_format_meta(input_thread_t *input, const char *s)
size_t len;
#ifdef HAVE_OPEN_MEMSTREAM
FILE *stream = open_memstream(&str, &len);
+#elif defined( _WIN32 )
+ FILE *stream = vlc_win32_tmpfile();
#else
FILE *stream = tmpfile();
#endif
diff --git a/src/win32/filesystem.c b/src/win32/filesystem.c
index f938147..7f29c8f 100644
--- a/src/win32/filesystem.c
+++ b/src/win32/filesystem.c
@@ -300,3 +300,36 @@ int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
return fd;
}
+
+FILE *vlc_win32_tmpfile(void)
+{
+ TCHAR tmp_path[MAX_PATH-14];
+ int i_ret = GetTempPath (MAX_PATH-14, tmp_path);
+ if (i_ret == 0)
+ return NULL;
+
+ TCHAR tmp_name[MAX_PATH];
+ i_ret = GetTempFileName(tmp_path, TEXT("VLC"), 0, tmp_name);
+ if (i_ret == 0)
+ return NULL;
+
+ HANDLE hFile = CreateFile(tmp_name,
+ GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ return NULL;
+
+ int fd = _open_osfhandle((intptr_t)hFile, 0);
+ if (fd == -1) {
+ CloseHandle(hFile);
+ return NULL;
+ }
+
+ FILE *stream = _fdopen(fd, "w+b");
+ if (stream == NULL) {
+ _close(fd);
+ return NULL;
+ }
+ return stream;
+}
+
More information about the vlc-commits
mailing list