Compare commits
3 Commits
345e13965e
...
59765aa334
Author | SHA1 | Date | |
---|---|---|---|
59765aa334 | |||
42a2c2af49 | |||
e56075fb46 |
@ -6,9 +6,9 @@
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include <cpuid.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Check.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/SystemError.h>
|
||||
#include <luna/Types.h>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "arch/MMU.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/SystemError.h>
|
||||
|
||||
#pragma GCC push_options
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "thread/Thread.h"
|
||||
#include <luna/String.h>
|
||||
#include <luna/CString.h>
|
||||
|
||||
bool is_in_kernel(Registers* regs)
|
||||
{
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include "boot/bootboot.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "video/Framebuffer.h"
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/String.h>
|
||||
|
||||
extern const BOOTBOOT bootboot;
|
||||
|
||||
|
@ -6,10 +6,10 @@
|
||||
#include "memory/MemoryManager.h"
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/LinkedList.h>
|
||||
#include <luna/SafeArithmetic.h>
|
||||
#include <luna/ScopeGuard.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/SystemError.h>
|
||||
|
||||
namespace std
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include "memory/MemoryMap.h"
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/Bitmap.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/ScopeGuard.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/SystemError.h>
|
||||
#include <luna/Types.h>
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "video/TextConsole.h"
|
||||
#include "boot/bootboot.h"
|
||||
#include "video/Framebuffer.h"
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Format.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/String.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
extern const BOOTBOOT bootboot;
|
||||
|
@ -3,7 +3,7 @@
|
||||
set(FREESTANDING_SOURCES
|
||||
src/Format.cpp
|
||||
src/NumberParsing.cpp
|
||||
src/String.cpp
|
||||
src/CString.cpp
|
||||
src/Units.cpp
|
||||
src/SystemError.cpp
|
||||
src/Bitmap.cpp
|
||||
|
@ -8,4 +8,6 @@ extern "C"
|
||||
int memcmp(const void* a, const void* b, usize n);
|
||||
void* memmove(void* dest, const void* src, usize n);
|
||||
usize strlen(const char* str);
|
||||
|
||||
char* strdup(const char* str);
|
||||
}
|
@ -22,6 +22,12 @@ class OwnedStringView
|
||||
return m_length;
|
||||
}
|
||||
|
||||
const char& operator[](usize index) const
|
||||
{
|
||||
expect(index < m_length, "OwnedStringView: index out of range");
|
||||
return m_string[index];
|
||||
}
|
||||
|
||||
private:
|
||||
char* m_string{nullptr};
|
||||
usize m_length{0};
|
||||
|
@ -7,7 +7,7 @@
|
||||
[[nodiscard]] void* raw_malloc(usize size)
|
||||
{
|
||||
#ifdef USE_FREESTANDING
|
||||
char* const rc = new char[size];
|
||||
char* const rc = new (std::nothrow) char[size];
|
||||
return (void*)rc;
|
||||
#else
|
||||
return malloc(size);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <luna/Bitmap.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Check.h>
|
||||
#include <luna/String.h>
|
||||
|
||||
Bitmap::Bitmap()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <luna/String.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/CString.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -44,4 +45,16 @@ extern "C"
|
||||
;
|
||||
return (usize)(i - str);
|
||||
}
|
||||
|
||||
char* strdup(const char* str)
|
||||
{
|
||||
const usize len = strlen(str);
|
||||
|
||||
char* dest = (char*)raw_malloc(len + 1);
|
||||
if (!dest) return nullptr;
|
||||
|
||||
memcpy(dest, str, len + 1);
|
||||
|
||||
return dest;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/OwnedStringView.h>
|
||||
#include <luna/String.h>
|
||||
|
||||
OwnedStringView::OwnedStringView()
|
||||
{
|
||||
@ -23,14 +23,14 @@ OwnedStringView::OwnedStringView(char* c_str)
|
||||
|
||||
OwnedStringView::~OwnedStringView()
|
||||
{
|
||||
if (m_string) destroy_array(m_string);
|
||||
if (m_string) raw_free(m_string);
|
||||
}
|
||||
|
||||
Result<OwnedStringView> OwnedStringView::clone() const
|
||||
{
|
||||
char* buf = TRY(make_array<char>(m_length + 1));
|
||||
char* const c_str = strdup(m_string);
|
||||
|
||||
memcpy(buf, m_string, m_length + 1);
|
||||
if (!c_str) return err(ENOMEM);
|
||||
|
||||
return OwnedStringView{buf};
|
||||
return OwnedStringView{c_str};
|
||||
}
|
Loading…
Reference in New Issue
Block a user