Compare commits

..

No commits in common. "0fad179485770d29a7bbcfe573f69fb74d41085e" and "1d6a39c92495803b653656d6d35f3db19696832c" have entirely different histories.

25 changed files with 63 additions and 76 deletions

View File

@ -1,5 +1,6 @@
#include <os/ArgumentParser.h>
#include <os/File.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>

View File

@ -1,11 +1,12 @@
#include <errno.h>
#include <fcntl.h>
#include <luna/PathParser.h>
#include <luna/String.h>
#include <luna/Vector.h>
#include <os/Directory.h>
#include <os/File.h>
#include <os/Process.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,8 +1,9 @@
#include <fcntl.h>
#include <os/ArgumentParser.h>
#include <os/Directory.h>
#include <os/File.h>
#include <os/FileSystem.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
@ -38,13 +39,11 @@ Result<int> luna_main(int argc, char** argv)
files = TRY(dir->list(filter));
}
else if (os::FileSystem::exists(pathname))
else
{
auto str = TRY(String::from_string_view(pathname));
TRY(files.try_append(move(str)));
}
else
return err(ENOENT);
if (!long_list)
{

View File

@ -1,10 +1,11 @@
#include <errno.h>
#include <luna/String.h>
#include <luna/Vector.h>
#include <os/ArgumentParser.h>
#include <os/File.h>
#include <os/FileSystem.h>
#include <os/Process.h>
#include <errno.h>
#include <pwd.h>
#include <stddef.h>
#include <stdio.h>

View File

@ -37,13 +37,13 @@ Result<void> InitRD::populate_vfs()
{
if (entry.type == TarStream::EntryType::RegularFile)
{
auto file = TRY(VFS::create_file(entry.name.chars(), Credentials {}));
auto file = TRY(VFS::create_file(entry.name, Credentials {}));
file->write(entry.data(), 0, entry.size);
file->chmod(entry.mode & (mode_t)~S_IFMT);
}
else if (entry.type == TarStream::EntryType::Directory)
{
TRY(vfs_create_dir_if_not_exists(entry.name.chars(), entry.mode));
TRY(vfs_create_dir_if_not_exists(entry.name, entry.mode));
}
}

View File

@ -1,6 +1,7 @@
#include <errno.h>
#include <luna/ScopeGuard.h>
#include <luna/Vector.h>
#include <errno.h>
#include <stdlib.h>
extern "C" char** environ;

View File

@ -1,3 +1,4 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <bits/errno-return.h>
#include <fcntl.h>
#include <luna/Format.h>

View File

@ -1,3 +1,4 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <errno.h>
#include <limits.h>
#include <luna/Heap.h>

View File

@ -1,3 +1,4 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <luna/SystemError.h>
#include <string.h>
@ -6,8 +7,6 @@ extern "C"
// All other string functions are defined in luna/CString.cpp, so the same definitions can be used by both kernel
// and userspace.
extern "C++" const char* error_string(int);
char* strerror(int errnum)
{
return const_cast<char*>(error_string(errnum));

View File

@ -1,3 +1,4 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <bits/errno-return.h>
#include <luna/Heap.h>
#include <sys/mman.h>

View File

@ -1,3 +1,4 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <bits/errno-return.h>
#include <luna/Check.h>
#include <luna/Format.h>

View File

@ -1,7 +1,8 @@
#include <bits/errno-return.h>
#include <fcntl.h>
#include <luna/StringBuilder.h>
#include <luna/Vector.h>
#include <bits/errno-return.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>

View File

@ -1,4 +1,5 @@
#pragma once
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <luna/Check.h>
#include <luna/Move.h>
#include <luna/Option.h>
@ -6,8 +7,6 @@
#include <luna/SystemError.h>
#include <luna/Types.h>
extern const char* error_string(int error);
struct Error
{
Error(int err)

View File

@ -9,53 +9,35 @@ class String
typedef const char* ConstIterator;
public:
/* Constructs a String, which will take ownership of the given c-string. To create a String that makes its own
* internal copy of the passed string, use String::from_cstring(). */
String(char* c_str);
/* Constructs a String with precalculated length, which will take ownership of the given c-string. To create a
* String that makes its own internal copy of the passed string, use String::from_cstring(). */
String(char* c_str, usize length);
/* Constructs an empty String. */
String();
String(String&&);
/* Implicit copying is disabled for Strings, as copy constructors cannot use value-based error handling. To copy a
* string, please use the clone() method. */
String(const String&) = delete;
String& operator=(String&&);
/* Implicit copying is disabled for Strings, as copy constructors cannot use value-based error handling. To copy a
* string, please use the clone() method. */
String& operator=(const String&) = delete;
~String();
/* Creates a copy of this String and returns it. */
Result<String> clone() const;
/* Creates a copy of a specific segment of this String and returns it. */
Result<String> substring(usize begin, usize size) const;
/* Splits a String with a delimiter. */
Result<Vector<String>> split(StringView delim) const
{
return view().split(delim);
}
/* Splits a String into two parts with a delimiter. */
Result<Vector<String>> split_once(char delim) const
{
return view().split_once(delim);
}
/* Creates a single String consisting of a list of strings separated by a delimiter. */
static Result<String> join(const Vector<String>& vec, StringView delim);
/* Removes all trailing characters contained in delim. */
void trim(StringView delim);
static Result<String> format(const String& fmt, ...);
@ -63,7 +45,10 @@ class String
static Result<String> vformat(StringView fmt, va_list ap);
static Result<String> from_cstring(const char* str);
static Result<String> from_string_view(StringView str);
static Result<String> from_string_view(StringView str)
{
return from_cstring(str.chars());
}
const char* chars() const
{

View File

@ -43,8 +43,6 @@ class StringView
Result<Vector<String>> split(StringView delim) const;
Result<Vector<String>> split_once(char delim) const;
static StringView from_fixed_size_cstring(const char* string, usize max);
Result<usize> to_uint() const;
Iterator begin() const

View File

@ -53,3 +53,14 @@
#define EISCONN 106 // Transport endpoint is already connected
#define ETIMEDOUT 110 // Connection timed out
#define EALREADY 114 // Operation already in progress
#if defined(IN_MOON) || defined(USE_FREESTANDING) || defined(_LUNA_SYSTEM_ERROR_EXTENSIONS) || defined(_LUNA_SOURCE)
// This one is Luna-specific.
#define EFIXME 342 // Functionality not yet implemented
#ifndef _LUNA_SOURCE
const char* error_string(int error);
const char* error_name(int error);
#endif
#endif

View File

@ -1,6 +1,5 @@
#pragma once
#include <luna/Result.h>
#include <luna/String.h>
#include <luna/Types.h>
#include <sys/types.h>
@ -10,13 +9,12 @@ class TarStream
enum class EntryType
{
RegularFile,
Directory,
Unimplemented,
Directory
};
struct Entry
{
String name;
char name[257];
usize size;
mode_t mode;
EntryType type;

View File

@ -145,23 +145,19 @@ Result<String> String::vformat(StringView fmt, va_list ap)
Result<String> String::from_cstring(const char* str)
{
return from_string_view(StringView { str });
}
Result<String> String::from_string_view(StringView str)
{
if (str.length() < sizeof(m_inline_storage))
usize len = strlen(str);
if (len < sizeof(m_inline_storage))
{
String result;
result.m_inline = true;
result.m_length = str.length();
strncpy(result.m_inline_storage, str.chars(), sizeof(m_inline_storage));
result.m_length = len;
strncpy(result.m_inline_storage, str, sizeof(m_inline_storage));
return result;
}
char* const dup = strndup(str.chars(), str.length());
char* const dup = strdup(str);
if (!dup) return err(ENOMEM);
return String { dup, str.length() };
return String { dup };
}
Result<String> String::join(const Vector<String>& vec, StringView delim)

View File

@ -120,10 +120,5 @@ Result<usize> StringView::to_uint() const
Result<String> StringView::to_string()
{
return String::from_string_view(*this);
}
StringView StringView::from_fixed_size_cstring(const char* string, usize max)
{
return { string, strnlen(string, max) };
return String::from_cstring(m_string);
}

View File

@ -1,3 +1,4 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <luna/SystemError.h>
const char* error_string(int error)
@ -56,6 +57,7 @@ const char* error_string(int error)
case EISCONN: return "Transport endpoint is already connected";
case ETIMEDOUT: return "Connection timed out";
case EALREADY: return "Operation already in progress";
case EFIXME: return "Functionality not yet implemented";
default: return "Unknown error";
}
}

View File

@ -1,8 +1,8 @@
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <luna/Alignment.h>
#include <luna/Alloc.h>
#include <luna/CString.h>
#include <luna/NumberParsing.h>
#include <luna/StringBuilder.h>
#include <luna/TarStream.h>
TarStream::TarStream(void* base, usize size) : m_base(base), m_pos(base), m_size(size)
@ -52,19 +52,11 @@ Result<TarStream::Entry> TarStream::parse_header(const TarStream::TarHeader* hdr
case '\0':
case '0': entry.type = EntryType::RegularFile; break;
case '5': entry.type = EntryType::Directory; break;
default: entry.type = EntryType::Unimplemented; break;
default: return err(EFIXME);
}
if (!strlen(hdr->prefix))
entry.name = TRY(String::from_string_view(StringView::from_fixed_size_cstring(hdr->name, sizeof(hdr->name))));
else
{
StringBuilder sb;
TRY(sb.add(StringView::from_fixed_size_cstring(hdr->prefix, sizeof(hdr->prefix))));
TRY(sb.add('/'));
TRY(sb.add(StringView::from_fixed_size_cstring(hdr->name, sizeof(hdr->name))));
entry.name = TRY(sb.string());
}
if (!strlen(hdr->prefix)) { strlcpy(entry.name, hdr->name, 101); }
else { return err(EFIXME); }
if (entry.size)
{

View File

@ -1,7 +1,8 @@
#include <errno.h>
#include <fcntl.h>
#include <luna/CString.h>
#include <os/Directory.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <unistd.h>

View File

@ -1,9 +1,10 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <luna/String.h>
#include <os/Directory.h>
#include <os/FileSystem.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
#include <sys/stat.h>

View File

@ -1,5 +1,6 @@
#include <errno.h>
#include <os/Main.h>
#include <errno.h>
#include <stdio.h>
int g_argc;

View File

@ -1,5 +1,6 @@
#include <errno.h>
#include <os/Process.h>
#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>