Compare commits
2 Commits
55b430a4fd
...
32dc5473a5
Author | SHA1 | Date | |
---|---|---|---|
32dc5473a5 | |||
76f9bd8112 |
@ -45,7 +45,7 @@ namespace TmpFS
|
|||||||
{
|
{
|
||||||
for (const auto& entry : m_entries)
|
for (const auto& entry : m_entries)
|
||||||
{
|
{
|
||||||
if (!strcmp(name, entry.name)) return entry.inode;
|
if (!strcmp(name, entry.name.chars())) return entry.inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err(ENOENT);
|
return err(ENOENT);
|
||||||
@ -53,9 +53,7 @@ namespace TmpFS
|
|||||||
|
|
||||||
Result<void> DirInode::add_entry(SharedPtr<VFS::Inode> inode, const char* name)
|
Result<void> DirInode::add_entry(SharedPtr<VFS::Inode> inode, const char* name)
|
||||||
{
|
{
|
||||||
Entry entry;
|
Entry entry { inode, name };
|
||||||
entry.inode = inode;
|
|
||||||
strlcpy(entry.name, name, sizeof(entry.name));
|
|
||||||
|
|
||||||
TRY(m_entries.try_append(move(entry)));
|
TRY(m_entries.try_append(move(entry)));
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "fs/VFS.h"
|
#include "fs/VFS.h"
|
||||||
#include <luna/Atomic.h>
|
#include <luna/Atomic.h>
|
||||||
#include <luna/Badge.h>
|
#include <luna/Badge.h>
|
||||||
#include <luna/OwnedStringView.h>
|
#include <luna/StaticString.h>
|
||||||
#include <luna/Vector.h>
|
#include <luna/Vector.h>
|
||||||
|
|
||||||
namespace TmpFS
|
namespace TmpFS
|
||||||
@ -110,7 +110,7 @@ namespace TmpFS
|
|||||||
struct Entry
|
struct Entry
|
||||||
{
|
{
|
||||||
SharedPtr<VFS::Inode> inode;
|
SharedPtr<VFS::Inode> inode;
|
||||||
char name[128];
|
StaticString<128> name;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<Entry> m_entries;
|
Vector<Entry> m_entries;
|
||||||
|
52
luna/include/luna/StaticString.h
Normal file
52
luna/include/luna/StaticString.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <luna/CString.h>
|
||||||
|
#include <luna/Types.h>
|
||||||
|
|
||||||
|
template <usize Size> class StaticString
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StaticString() = default;
|
||||||
|
StaticString(const char* string)
|
||||||
|
{
|
||||||
|
adopt(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adopt(const char* string)
|
||||||
|
{
|
||||||
|
usize length = strlcpy(m_buffer, string, sizeof(m_buffer));
|
||||||
|
if (length > Size) { m_length = Size; }
|
||||||
|
else
|
||||||
|
m_length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
StaticString<Size>& operator=(const char* string)
|
||||||
|
{
|
||||||
|
adopt(string);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <usize OSize> StaticString<Size>& operator=(const StaticString<OSize>& string)
|
||||||
|
{
|
||||||
|
if constexpr (OSize == Size)
|
||||||
|
{
|
||||||
|
if (this == &string) return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
adopt(string.chars());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* chars() const
|
||||||
|
{
|
||||||
|
return m_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
usize length() const
|
||||||
|
{
|
||||||
|
return m_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char m_buffer[Size + 1];
|
||||||
|
usize m_length { 0 };
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user