diff options
author | Jack Lloyd <[email protected]> | 2018-04-11 09:10:11 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-04-11 09:10:11 -0400 |
commit | 76cab9774d7dd2f6623260d06b035911f84e0631 (patch) | |
tree | 570ef32a7854419ee6306fa87abd614227fd79f3 /src/tests/tests.cpp | |
parent | 80441df8ba159282e24f4a6059bc58f2a41e11cc (diff) |
Move mkstemp to Test::temp_file_name
Diffstat (limited to 'src/tests/tests.cpp')
-rw-r--r-- | src/tests/tests.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 01fc25f32..e51496ab9 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -23,6 +23,11 @@ #include <botan/point_gfp.h> #endif +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) + #include <stdlib.h> + #include <unistd.h> +#endif + namespace Botan_Tests { Test::Registration::Registration(const std::string& name, Test* test) @@ -495,6 +500,33 @@ Test* Test::get_test(const std::string& test_name) return nullptr; } +//static +std::string Test::temp_file_name(const std::string& basename) + { + // TODO add a --tmp-dir option to the tests to specify where these files go + +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) + + // POSIX only calls for 6 'X' chars but OpenBSD allows arbitrary amount + std::string mkstemp_basename = "/tmp/" + basename + ".XXXXXXXXXX"; + + int fd = ::mkstemp(&mkstemp_basename[0]); + + // error + if(fd < 0) + { + return ""; + } + + ::close(fd); + + return mkstemp_basename; +#else + // For now just create the temp in the current working directory + return basename; +#endif + } + std::string Test::read_data_file(const std::string& path) { const std::string fsname = Test::data_file(path); |