Created
April 4, 2013 09:37
-
-
Save mattyclarkson/5309098 to your computer and use it in GitHub Desktop.
A C++11 routine to create a safe temporary file name.
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
const constexpr SizeT junk = 'z' - 'a'; | |
Char buffer[L_tmpnam + junk] = {'\0'}; | |
// cppcheck-suppress obsoleteFunctionstmpnam | |
std::tmpnam(buffer); | |
SizeT len = std::strlen(buffer); | |
std::random_device rd; | |
for (SizeT i = len; i < (L_tmpnam + junk - 1); ++i) { | |
buffer[i] = std::max('a', std::min<Char>('z', | |
'a' + (i - len) + (rd() & 0xF))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment