Skip to content

Commit d60678c

Browse files
committed
Added unlink function
1 parent 0699caf commit d60678c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/include/cpputils2/file/file.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
namespace CppUtils2
1010
{
1111

12+
inline Result unlink(const std::string &path)
13+
{
14+
auto ret = std::remove(path.c_str());
15+
if (ret == 0)
16+
{
17+
return Result::RET_OK;
18+
}
19+
return Result::RET_ERROR;
20+
}
21+
1222
inline bool file_exists(const std::string &name)
1323
{
1424
std::ifstream f(name.c_str());

src/test/cpputils2_tests.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ namespace
120120

121121
TEST(ExampleFutex, TestShared)
122122
{
123-
CppUtils2::SharedFutex futex("/test_futex");
123+
if (CppUtils2::file_exists("/dev/shm/test_futex"))
124+
{
125+
CppUtils2::unlink("/dev/shm/test_futex");
126+
}
127+
128+
CppUtils2::Shm shm("/test_futex");
129+
shm.allocate(sizeof(int32_t));
130+
void *ptr = shm.get_raw_ptr();
131+
132+
CppUtils2::SharedFutex futex;
133+
futex.init("/test_futex");
124134
futex.lock();
125135
futex.unlock();
126136

0 commit comments

Comments
 (0)