[flang] Add UNSIGNED (#113504)
[llvm-project.git] / lldb / tools / lldb-fuzzer / utils / TempFile.cpp
blobc5c16ec19df7a762672e4dc0c4a780b03c7b8230
1 //===-- TempFile.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/FileSystem.h"
10 #include <TempFile.h>
12 using namespace lldb_fuzzer;
13 using namespace llvm;
15 TempFile::~TempFile() {
16 if (!m_path.empty())
17 sys::fs::remove(m_path.str(), true);
20 std::unique_ptr<TempFile> TempFile::Create(uint8_t *data, size_t size) {
21 int fd;
22 std::unique_ptr<TempFile> temp_file = std::make_unique<TempFile>();
23 std::error_code ec = sys::fs::createTemporaryFile("lldb-fuzzer", "input", fd,
24 temp_file->m_path);
25 if (ec)
26 return nullptr;
28 raw_fd_ostream os(fd, true);
29 os.write(reinterpret_cast<const char *>(data), size);
30 os.close();
32 return temp_file;