diff options
author | Elliott Hughes <enh@google.com> | 2015-06-03 15:22:11 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-06-05 13:28:44 -0700 |
commit | 8bdd4bbc1cca8b61eb3f2c8dd0335735fc84f4b0 (patch) | |
tree | 68b2537836bd5ebcb8078577a6d512cfaa9623e9 /fastboot | |
parent | 72ffc3c02a5546ab93ffcbb2a94193be651c3629 (diff) | |
download | system_core-8bdd4bbc1cca8b61eb3f2c8dd0335735fc84f4b0.zip system_core-8bdd4bbc1cca8b61eb3f2c8dd0335735fc84f4b0.tar.gz system_core-8bdd4bbc1cca8b61eb3f2c8dd0335735fc84f4b0.tar.bz2 |
Add a working Windows tmpfile(3) to fastboot.
Windows' tmpfile(3) implementation requires administrator rights because
it creates temporary files in the root directory. Write an alternative
that uses the user's temporary directory instead.
Bug: http://b/21558406
Change-Id: Ic9aece5c69429797a332a97681a76b76ac3551bf
(cherry picked from commit a26fbeeaa4298ea3bb09c53bdaefb6d968c6b72f)
Diffstat (limited to 'fastboot')
-rw-r--r-- | fastboot/fastboot.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 6724d05..be80cce 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -406,6 +406,35 @@ static void* unzip_file(ZipArchiveHandle zip, const char* entry_name, unsigned* return data; } +#if defined(_WIN32) + +// TODO: move this to somewhere it can be shared. + +#include <windows.h> + +// Windows' tmpfile(3) requires administrator rights because +// it creates temporary files in the root directory. +static FILE* win32_tmpfile() { + char temp_path[PATH_MAX]; + DWORD nchars = GetTempPath(sizeof(temp_path), temp_path); + if (nchars == 0 || nchars >= sizeof(temp_path)) { + fprintf(stderr, "GetTempPath failed, error %ld\n", GetLastError()); + return nullptr; + } + + char filename[PATH_MAX]; + if (GetTempFileName(temp_path, "fastboot", 0, filename) == 0) { + fprintf(stderr, "GetTempFileName failed, error %ld\n", GetLastError()); + return nullptr; + } + + return fopen(filename, "w+bTD"); +} + +#define tmpfile win32_tmpfile + +#endif + static int unzip_to_file(ZipArchiveHandle zip, char* entry_name) { FILE* fp = tmpfile(); if (fp == NULL) { |