forked from mia/Aegisub
Timestamp temporary files to reduce the chance of name collisions
This commit is contained in:
parent
b43f27396e
commit
decbf06de3
1 changed files with 9 additions and 2 deletions
|
@ -30,13 +30,20 @@
|
||||||
#include "libaegisub/log.h"
|
#include "libaegisub/log.h"
|
||||||
#include "libaegisub/util.h"
|
#include "libaegisub/util.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define snprintf sprintf_s
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::string make_temp_name(std::string const& filename) {
|
std::string make_temp_name(std::string const& filename) {
|
||||||
|
char tmp[1024];
|
||||||
|
snprintf(tmp, sizeof tmp, "_tmp_%lld", (long long)time(0));
|
||||||
|
|
||||||
std::string::size_type pos = filename.rfind('.');
|
std::string::size_type pos = filename.rfind('.');
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
return filename + "_tmp";
|
return filename + tmp;
|
||||||
|
|
||||||
return filename.substr(0, pos) + "_tmp" + filename.substr(pos);
|
return filename.substr(0, pos) + tmp + filename.substr(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue