Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libs/crossplatform/include/CrossPlatform.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -30,6 +30,8 @@

#define _popen popen
#define _pclose pclose
// localtime_r has inverted arguments as localtime_s, therfore define with parameters
#define localtime_s(tm_ptr, time_ptr) localtime_r((time_ptr), (tm_ptr))

/* Windows defines */
#define MAX_PATH 260
Expand Down
39 changes: 31 additions & 8 deletions libs/crossplatform/test/src/UnitTests.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "CrossPlatform.h"
#include "CrossPlatformUtils.h"
#include "RteFsUtils.h"
#include "gtest/gtest.h"

using namespace std;


TEST(CrossPlatformUnitTests, localtime_s)
{
// 24.02.2026 10:00:00 local time
std::tm reference{};
reference.tm_year = 2026 - 1900; // years since 1900
reference.tm_mon = 1; // February (0-based)
reference.tm_mday = 24;
reference.tm_hour = 10;
reference.tm_min = 0;
reference.tm_sec = 0;
reference.tm_isdst = -1; // let system determine DST

// Convert to time_t (interpreted as local time)
std::time_t t = std::mktime(&reference);
ASSERT_NE(t, static_cast<std::time_t>(-1));

// Convert back using localtime_s
std::tm result{};
localtime_s(&result, &t);
EXPECT_EQ(result.tm_year, 2026 - 1900);
EXPECT_EQ(result.tm_mon, 1);
EXPECT_EQ(result.tm_mday, 24);
EXPECT_EQ(result.tm_hour, 10);
EXPECT_EQ(result.tm_min, 0);
EXPECT_EQ(result.tm_sec, 0);
}

TEST(CrossPlatformUnitTests, GetEnv_Empty) {
string value = CrossPlatformUtils::GetEnv("");
EXPECT_TRUE(value.empty());
Expand Down Expand Up @@ -87,15 +115,10 @@ TEST(CrossPlatformUnitTests, GetRegistryString) {
EXPECT_TRUE(!CrossPlatformUtils::GetRegistryString("HKEY_CURRENT_USER\\Environment\\Temp").empty());
EXPECT_TRUE(!CrossPlatformUtils::GetRegistryString("Environment\\Temp").empty());

EXPECT_EQ(CrossPlatformUtils::GetRegistryString("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir"), "C:\\Program Files\\Common Files");
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir"), "C:\\Program Files\\Common Files");

// fall-back to environment variable
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("PATH"), CrossPlatformUtils::GetEnv("PATH"));

} else {
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("PATH"), CrossPlatformUtils::GetEnv("PATH"));
}
// for all platforms: use environment variable
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("PATH"), CrossPlatformUtils::GetEnv("PATH"));
}

TEST(CrossPlatformUnitTests, GetLongPathRegStatus) {
Expand Down
5 changes: 1 addition & 4 deletions libs/rtefsutils/src/RteFsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "RteFsUtils.h"

#include "CrossPlatform.h"
#include "CrossPlatformUtils.h"
#include "RteUtils.h"
#include "WildCards.h"
Expand Down Expand Up @@ -927,11 +928,7 @@ std::string RteFsUtils::FileTimeToString(const fs::file_time_type& timeStamp) {
timeStamp - fs::file_time_type::clock::now() + std::chrono::system_clock::now());
std::time_t t = std::chrono::system_clock::to_time_t(sctp);
std::tm tm{};
#if defined(_WIN32)
localtime_s(&tm, &t); // Windows secure version
#else
localtime_r(&t, &tm); // POSIX thread-safe version
#endif
std::ostringstream oss;
oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S");
strTime = oss.str();
Expand Down
Loading