summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fud_directory.hpp5
-rw-r--r--source/fud_directory.cpp7
-rw-r--r--source/fud_string.cpp12
-rw-r--r--test/test_directory.cpp8
4 files changed, 21 insertions, 11 deletions
diff --git a/include/fud_directory.hpp b/include/fud_directory.hpp
index 5a988dc..e6052c4 100644
--- a/include/fud_directory.hpp
+++ b/include/fud_directory.hpp
@@ -70,6 +70,7 @@ struct Stat;
/** \brief Simplified Directory Entry */
struct DirectoryEntry {
String name;
+ size_t inode;
size_t size;
size_t links;
time_t modificationTime;
@@ -97,6 +98,10 @@ class Directory {
Directory& operator=(const Directory& rhs) = delete;
Directory& operator=(Directory&& rhs);
+ constexpr const String& name() const {
+ return m_name;
+ }
+
constexpr FudStatus status() const
{
return m_status;
diff --git a/source/fud_directory.cpp b/source/fud_directory.cpp
index 99f3600..6df5bcc 100644
--- a/source/fud_directory.cpp
+++ b/source/fud_directory.cpp
@@ -29,7 +29,10 @@ struct Stat : public CStat {};
Result<DirectoryEntry, FudStatus> DirectoryEntry::fromStat(const String& name, const Stat& statBuffer)
{
using RetType = Result<DirectoryEntry, FudStatus>;
- static_assert(std::is_same_v<decltype(statBuffer.st_size), long>);
+ static_assert(std::is_same_v<decltype(statBuffer.st_ino), unsigned long>);
+ static_assert(sizeof(decltype(statBuffer.st_ino)) <= sizeof(size_t));
+
+ static_assert(std::is_same_v<decltype(statBuffer.st_size), signed long>);
static_assert(sizeof(decltype(statBuffer.st_size)) <= sizeof(size_t));
static_assert(std::is_same_v<decltype(statBuffer.st_nlink), unsigned long>);
@@ -71,7 +74,7 @@ Result<DirectoryEntry, FudStatus> DirectoryEntry::fromStat(const String& name, c
}
return RetType::okay(
- DirectoryEntry{name, size, static_cast<size_t>(statBuffer.st_nlink), statBuffer.st_mtime, entryType});
+ DirectoryEntry{name, statBuffer.st_ino, size, static_cast<size_t>(statBuffer.st_nlink), statBuffer.st_mtime, entryType});
}
Directory::Directory(String name) : m_name{name}
diff --git a/source/fud_string.cpp b/source/fud_string.cpp
index 52d6b8f..97acb52 100644
--- a/source/fud_string.cpp
+++ b/source/fud_string.cpp
@@ -16,6 +16,7 @@
*/
#include "fud_string.hpp"
+
#include "fud_assert.hpp"
namespace fud {
@@ -115,7 +116,8 @@ String& String::operator=(const String& rhs)
return *this;
}
-String& String::operator=(String&& rhs) {
+String& String::operator=(String&& rhs)
+{
m_length = rhs.m_length;
m_capacity = rhs.m_capacity;
if (rhs.isLarge()) {
@@ -287,7 +289,7 @@ String String::catenate(const String& rhs) const
auto* destPtr = output.data();
auto status = copyMem(destPtr, m_capacity, data(), length());
fudAssert(status == FudStatus::Success);
- status = copyMem(destPtr + length(), m_capacity, rhs.data(), rhs.length());
+ status = copyMem(destPtr + length(), output.m_capacity - length(), rhs.data(), rhs.length());
fudAssert(status == FudStatus::Success);
static_cast<void>(status);
fudAssert(output.nullTerminate() == FudStatus::Success);
@@ -295,7 +297,8 @@ String String::catenate(const String& rhs) const
return output;
}
-bool String::compare(const String& rhs) const {
+bool String::compare(const String& rhs) const
+{
if (!valid() || !rhs.valid()) {
return false;
}
@@ -304,8 +307,7 @@ bool String::compare(const String& rhs) const {
return false;
}
- if (isLarge() && data() == rhs.data())
- {
+ if (isLarge() && data() == rhs.data()) {
return true;
}
diff --git a/test/test_directory.cpp b/test/test_directory.cpp
index 45d0c77..3c43663 100644
--- a/test/test_directory.cpp
+++ b/test/test_directory.cpp
@@ -113,10 +113,10 @@ TEST(FudDirectory, Basic)
ASSERT_EQ(directory.errorCode(), 0);
const Array<DirectoryEntry, 4> expectedFiles{
- DirectoryEntry{String{"."}, 0, 2, 0, DirectoryEntryType::Directory},
- DirectoryEntry{String{".."}, 0, 1, 0, DirectoryEntryType::Directory},
- DirectoryEntry{files[0], files[0].size(), 1, 0, DirectoryEntryType::RegularFile},
- DirectoryEntry{files[1], files[1].size(), 1, 0, DirectoryEntryType::RegularFile},
+ DirectoryEntry{String{"."}, 0, 0, 2, 0, DirectoryEntryType::Directory},
+ DirectoryEntry{String{".."}, 0, 0, 1, 0, DirectoryEntryType::Directory},
+ DirectoryEntry{files[0], 0, files[0].size(), 1, 0, DirectoryEntryType::RegularFile},
+ DirectoryEntry{files[1], 0, files[1].size(), 1, 0, DirectoryEntryType::RegularFile},
};
ASSERT_TRUE(expectedFiles[0].name.compare(expectedFiles[0].name));