From c80adac07772f5b3c7a6c31e3e05480252f84171 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 30 Aug 2014 20:03:31 +0200 Subject: cache_file: add a mode that creates a temporary file Since we have to be portable, our options for creating temporary files are somewhat limited. tmpfile() happens to be available everywhere, so use that. This function doesn't allow having a "visible" filename or location, so we use the magic string "TMP" for this. --- stream/cache_file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/cache_file.c b/stream/cache_file.c index af315b355a..7ecc0f9858 100644 --- a/stream/cache_file.c +++ b/stream/cache_file.c @@ -127,7 +127,8 @@ int stream_file_cache_init(stream_t *cache, stream_t *stream, if (!opts->file || !opts->file[0] || opts->file_max < 1) return 0; - FILE *file = fopen(opts->file, "wb+"); + bool use_anon_file = strcmp(opts->file, "TMP") == 0; + FILE *file = use_anon_file ? tmpfile() : fopen(opts->file, "wb+"); if (!file) { MP_ERR(cache, "can't open cache file '%s'\n", opts->file); return -1; -- cgit v1.2.3