Remove unused Utility::CreateTempFile()

This commit is contained in:
Alexander A. Klimov 2022-08-01 17:50:17 +02:00
parent b92fe23469
commit 0367c9e099
2 changed files with 0 additions and 42 deletions

View File

@ -1783,46 +1783,6 @@ String Utility::ValidateUTF8(const String& input)
return String(std::move(output));
}
String Utility::CreateTempFile(const String& path, int mode, std::fstream& fp)
{
std::vector<char> targetPath(path.Begin(), path.End());
targetPath.push_back('\0');
int fd;
#ifndef _WIN32
fd = mkstemp(&targetPath[0]);
#else /* _WIN32 */
fd = MksTemp(&targetPath[0]);
#endif /*_WIN32*/
if (fd < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("mkstemp")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path));
}
try {
fp.open(&targetPath[0], std::ios_base::trunc | std::ios_base::out);
} catch (const std::fstream::failure&) {
close(fd);
throw;
}
close(fd);
String resultPath = String(targetPath.begin(), targetPath.end() - 1);
if (chmod(resultPath.CStr(), mode) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("chmod")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(resultPath));
}
return resultPath;
}
#ifdef _WIN32
/* mkstemp extracted from libc/sysdeps/posix/tempname.c. Copyright
* (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc.

View File

@ -132,8 +132,6 @@ public:
static String ValidateUTF8(const String& input);
static String CreateTempFile(const String& path, int mode, std::fstream& fp);
#ifdef _WIN32
static int MksTemp(char *tmpl);
#endif /* _WIN32 */