From 08638224d5fecd4bcab6ab5263d1e25544d9d2fa Mon Sep 17 00:00:00 2001 From: Ivan Morozko Date: Mon, 8 Apr 2024 15:14:42 +0400 Subject: [PATCH] Avoid usage of deprecated tmpnam function Linker advises not to use tmpnam: ":(.text+0x2761): warning: the use of `tmpnam' is dangerous, better use `mkstemp' " Introduce function to get tmp file path based on current time. I.e we went from: "/tmp/filecQmvY8.pcap" to "/tmp/file1712574386700751477.pcap" --- autotest/autotest.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autotest/autotest.cpp b/autotest/autotest.cpp index 53cd151a..0879bd68 100644 --- a/autotest/autotest.cpp +++ b/autotest/autotest.cpp @@ -557,10 +557,18 @@ class pcap_expectation std::vector buffer; }; +static std::string +generate_temp_filepath(const std::filesystem::path& dir = std::filesystem::temp_directory_path()) +{ + auto time = std::chrono::system_clock::now().time_since_epoch().count(); + std::string filename = "file" + std::to_string(time); + return dir / filename; +} + void tAutotest::recvThread(std::string interfaceName, std::vector expectFilePaths) { - PcapDumper pcapDumper(std::tmpnam(nullptr) + std::string(".pcap")); + PcapDumper pcapDumper(generate_temp_filepath() + ".pcap"); std::vector expect_pcaps; for (const auto& expectFilePath : expectFilePaths)