TempFile.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/core/utils/FileSystemUtils.h>
  6. #include <aws/core/platform/FileSystem.h>
  7. namespace Aws
  8. {
  9. namespace Utils
  10. {
  11. static Aws::String ComputeTempFileName(const char* prefix, const char* suffix)
  12. {
  13. Aws::String prefixStr;
  14. if (prefix)
  15. {
  16. prefixStr = prefix;
  17. }
  18. Aws::String suffixStr;
  19. if (suffix)
  20. {
  21. suffixStr = suffix;
  22. }
  23. return prefixStr + Aws::FileSystem::CreateTempFilePath() + suffixStr;
  24. }
  25. TempFile::TempFile(const char* prefix, const char* suffix, std::ios_base::openmode openFlags) :
  26. FStreamWithFileName(ComputeTempFileName(prefix, suffix).c_str(), openFlags)
  27. {
  28. }
  29. TempFile::TempFile(const char* prefix, std::ios_base::openmode openFlags) :
  30. FStreamWithFileName(ComputeTempFileName(prefix, nullptr).c_str(), openFlags)
  31. {
  32. }
  33. TempFile::TempFile(std::ios_base::openmode openFlags) :
  34. FStreamWithFileName(ComputeTempFileName(nullptr, nullptr).c_str(), openFlags)
  35. {
  36. }
  37. TempFile::~TempFile()
  38. {
  39. Aws::FileSystem::RemoveFileIfExists(m_fileName.c_str());
  40. }
  41. }
  42. }