-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop using std::tmpnam in POSIX operating systems
- Loading branch information
1 parent
80e4f9b
commit 594dca6
Showing
4 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <Sand/Helpers.hpp> | ||
|
||
#include <Sand/filesystem.hpp> | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
using namespace Sand; | ||
|
||
bool Helpers::ends_with(const std::string &str, const std::string &ending) | ||
{ | ||
if (str.length() >= ending.length()) | ||
{ | ||
return str.compare(str.length() - ending.length(), ending.length(), ending) == 0; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool Helpers::starts_with(const std::string &str, const std::string &starting) | ||
{ | ||
if (str.length() >= starting.length()) | ||
{ | ||
return str.rfind(starting, 0) == 0; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
std::string Helpers::temporary_filename() | ||
{ | ||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) | ||
return std::tmpnam(nullptr); | ||
#else | ||
auto filename = fs::temp_directory_path().u8string() + "XXXXXXXXXXXXXXXX"; | ||
mkstemp(filename.data()); | ||
|
||
return filename; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters