183942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// Copyright 2014 The Android Open Source Project
283942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner//
383942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// This software is licensed under the terms of the GNU General Public
483942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// License version 2, as published by the Free Software Foundation, and
583942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// may be copied, distributed, and modified under those terms.
683942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner//
783942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// This program is distributed in the hope that it will be useful,
883942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// but WITHOUT ANY WARRANTY; without even the implied warranty of
983942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1083942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner// GNU General Public License for more details.
1183942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
1283942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#include "android/filesystems/testing/TestSupport.h"
1383942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
1483942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#include "android/base/EintrWrapper.h"
1583942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#include "android/base/Log.h"
1683942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
1783942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#include <stdlib.h>
1883942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
1983942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#ifdef _WIN32
2083942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#include <windows.h>
21257b04adee7b17300cc57281d1e72e56d499f326Vince Harron#else
22257b04adee7b17300cc57281d1e72e56d499f326Vince Harron#include <unistd.h>
2383942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#endif
2483942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
2583942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turnernamespace android {
2683942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turnernamespace testing {
2783942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
2883942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turnerstd::string CreateTempFilePath() {
2983942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#ifdef _WIN32
3083942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    char tempDir[MAX_PATH];
3183942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    DWORD ret = GetTempPath(MAX_PATH, tempDir);
3283942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    CHECK(ret > 0 && ret < MAX_PATH)
3383942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner            << "Could not get temporary directory path";
3483942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
3583942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    std::string result;
3683942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    result.resize(MAX_PATH);
3783942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    UINT ret2 = GetTempFileName(tempDir, "emulator-test-", 0,  &result[0]);
3883942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    CHECK(ret2 != ERROR_BUFFER_OVERFLOW) << "Could not create temporary file name";
3983942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    result.resize(::strlen(result.c_str()));
4083942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    return result;
4183942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#else
4283942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    std::string result("/tmp/emulator-test.XXXXXX");
4383942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    int ret = HANDLE_EINTR(mkstemp(&result[0]));
4483942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    PCHECK(ret >= 0) << "Could not create temporary filepath";
4583942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    ::close(ret);
4683942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner    return result;
4783942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner#endif
4883942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner}
4983942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner
5083942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner}  // namespace testing
5183942739a98f55db1e83ad39ddee6d294ad329f2David 'Digit' Turner}  // namespace android
52