blob: 59d05239aece3fb1fe0230f6a7139e7f0de4e94c [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynn6da6a452020-07-14 14:26:27 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Rob Hughesbdee4262020-01-07 17:05:24 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "Filesystem.hpp"
7
Rob Hughesbdee4262020-01-07 17:05:24 +00008namespace armnnUtils
9{
10namespace Filesystem
11{
12
Francis Murtagh532a29d2020-06-29 11:50:01 +010013/**
14 * @brief Construct a temporary file name.
15 *
16 * Given a specified file name construct a path to that file in the
17 * system temporary directory. If the file already exists it is deleted. This
18 * could throw filesystem_error exceptions.
19 *
20 * @param fileName the file name required in the temporary directory.
21 * @return path consisting of system temporary directory and file name.
22 */
23fs::path NamedTempFile(const char* fileName)
Rob Hughesbdee4262020-01-07 17:05:24 +000024{
Francis Murtagh532a29d2020-06-29 11:50:01 +010025 fs::path tmpDir = fs::temp_directory_path();
26 fs::path namedTempFile{tmpDir / fileName};
27 if (fs::exists(namedTempFile))
Rob Hughesbdee4262020-01-07 17:05:24 +000028 {
Francis Murtagh532a29d2020-06-29 11:50:01 +010029 fs::remove(namedTempFile);
Rob Hughesbdee4262020-01-07 17:05:24 +000030 }
Francis Murtagh532a29d2020-06-29 11:50:01 +010031 return namedTempFile;
Rob Hughesbdee4262020-01-07 17:05:24 +000032}
33
34}
35}