Compare commits

..

No commits in common. "d9b7e8edc0335eff6709b3d7de3d7dcc27830778" and "6beea7f8170385d1ea985c96198c6fbd6f2f9dbe" have entirely different histories.

10 changed files with 7 additions and 108 deletions

View File

@ -1,7 +1,6 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <luna/PathParser.h> #include <luna/PathParser.h>
#include <luna/Sort.h>
#include <luna/String.h> #include <luna/String.h>
#include <luna/Vector.h> #include <luna/Vector.h>
#include <os/Directory.h> #include <os/Directory.h>
@ -240,7 +239,6 @@ static Result<void> load_services()
auto dir = TRY(os::Directory::open("/etc/init")); auto dir = TRY(os::Directory::open("/etc/init"));
auto services = TRY(dir->list(os::Directory::Filter::ParentAndBase)); auto services = TRY(dir->list(os::Directory::Filter::ParentAndBase));
sort(services.begin(), services.end(), String::compare);
for (const auto& entry : services) for (const auto& entry : services)
{ {

View File

@ -1,3 +0,0 @@
Name=motd
Command=/bin/cat /etc/motd
Wait=true

View File

@ -1,2 +1 @@
Welcome to the Luna system! Hello, world!
Have a look around, you can run 'ls /bin' to list available commands.

View File

@ -35,16 +35,16 @@ extern "C"
#endif #endif
/* Return the absolute value of an integer. */ /* Return the absolute value of an integer. */
int abs(int); int abs(int v);
/* Return the absolute value of a long integer. */ /* Return the absolute value of a long integer. */
long labs(long); long labs(long v);
/* Return the absolute value of a long long integer. */ /* Return the absolute value of a long long integer. */
long long llabs(long long); long long llabs(long long v);
/* Return the result of dividing two integers, including the remainder. */ /* Return the result of dividing two integers, including the remainder. */
div_t div(int, int); div_t div(int num, int den);
/* Return the result of dividing two long integers, including the remainder. */ /* Return the result of dividing two long integers, including the remainder. */
ldiv_t ldiv(long, long); ldiv_t ldiv(long, long);
@ -62,7 +62,7 @@ extern "C"
void* realloc(void* ptr, size_t size); void* realloc(void* ptr, size_t size);
/* Free heap memory. */ /* Free heap memory. */
void free(void* ptr); void free(void*);
/* Abort the program without performing any normal cleanup. */ /* Abort the program without performing any normal cleanup. */
__noreturn void abort(); __noreturn void abort();
@ -115,9 +115,7 @@ extern "C"
/* Clear all environment variables. */ /* Clear all environment variables. */
int clearenv(void); int clearenv(void);
/* Sort an array of arbitrary elements using a comparison function. */ void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*)); void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
/* Convert a multibyte character string to a wide character string. */ /* Convert a multibyte character string to a wide character string. */

View File

@ -2,7 +2,6 @@
#include <limits.h> #include <limits.h>
#include <luna/Heap.h> #include <luna/Heap.h>
#include <luna/NumberParsing.h> #include <luna/NumberParsing.h>
#include <luna/Sort.h>
#include <luna/Utf8.h> #include <luna/Utf8.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/syscall.h> #include <sys/syscall.h>
@ -200,9 +199,4 @@ extern "C"
return status; return status;
} }
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*))
{
c_quicksort(base, nmemb, size, compar);
}
} }

View File

@ -5,7 +5,6 @@ file(GLOB HEADERS include/luna/*.h)
set(FREESTANDING_SOURCES set(FREESTANDING_SOURCES
${HEADERS} ${HEADERS}
src/Format.cpp src/Format.cpp
src/Sort.cpp
src/NumberParsing.cpp src/NumberParsing.cpp
src/CString.cpp src/CString.cpp
src/CPath.cpp src/CPath.cpp

View File

@ -1,26 +0,0 @@
#pragma once
#include <luna/Types.h>
typedef int (*compar_t)(const void*, const void*);
void c_quicksort(void* base, usize nmemb, usize size, compar_t compar);
template <typename T> void sort(T* base, usize nmemb, int (*compar)(const T*, const T*))
{
return c_quicksort(base, nmemb, sizeof(T), (compar_t)compar);
}
template <typename T> void sort(T* base, usize nmemb, compar_t compar)
{
return c_quicksort(base, nmemb, sizeof(T), compar);
}
template <typename T> void sort(T* begin, T* end, int (*compar)(const T*, const T*))
{
return c_quicksort(begin, end - begin, sizeof(T), (compar_t)compar);
}
template <typename T> void sort(T* begin, T* end, compar_t compar)
{
return c_quicksort(begin, end - begin, sizeof(T), compar);
}

View File

@ -65,8 +65,6 @@ class String
static Result<String> from_cstring(const char* str); static Result<String> from_cstring(const char* str);
static Result<String> from_string_view(StringView str); static Result<String> from_string_view(StringView str);
static int compare(const String* a, const String* b);
const char* chars() const const char* chars() const
{ {
return m_inline ? m_inline_storage : m_string; return m_inline ? m_inline_storage : m_string;

View File

@ -1,53 +0,0 @@
#include <luna/Alignment.h>
#include <luna/Sort.h>
static void swap_sized(void* ptr1, void* ptr2, usize size)
{
char* x = (char*)ptr1;
char* y = (char*)ptr2;
while (size--)
{
char t = *x;
*x = *y;
*y = t;
x += 1;
y += 1;
}
}
static usize partition(void* base, usize start, usize end, usize size, compar_t compar)
{
auto atindex = [&base, &size](usize index) { return offset_ptr(base, index * size); };
void* pivot = atindex(end);
usize i = (start - 1);
for (usize j = start; j <= end - 1; j++)
{
if (compar(atindex(j), pivot) < 0)
{
i++;
swap_sized(atindex(i), atindex(j), size);
}
}
swap_sized(atindex(i + 1), pivot, size);
return i + 1;
}
static void quicksort_impl(void* base, usize start, usize end, usize size, compar_t compar)
{
if (start < end)
{
usize pivot = partition(base, start, end, size, compar);
if ((end - start) < 2) return;
quicksort_impl(base, start, pivot - 1, size, compar);
quicksort_impl(base, pivot + 1, end, size, compar);
}
}
void c_quicksort(void* base, usize nmemb, usize size, compar_t compar)
{
quicksort_impl(base, 0, nmemb - 1, size, compar);
}

View File

@ -180,8 +180,3 @@ Result<String> String::join(const Vector<String>& vec, StringView delim)
return sb.string(); return sb.string();
} }
int String::compare(const String* a, const String* b)
{
return strcmp(a->chars(), b->chars());
}