diff --git a/AK/AKString.h b/AK/AKString.h index 742913167d8..7784c9252f9 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -59,7 +59,7 @@ public: { } - String(const char* cstring, ssize_t length, ShouldChomp shouldChomp = NoChomp) + String(const char* cstring, int length, ShouldChomp shouldChomp = NoChomp) : m_impl(StringImpl::create(cstring, length, shouldChomp)) { } @@ -118,9 +118,9 @@ public: bool is_null() const { return !m_impl; } bool is_empty() const { return length() == 0; } - ssize_t length() const { return m_impl ? m_impl->length() : 0; } + int length() const { return m_impl ? m_impl->length() : 0; } const char* characters() const { return m_impl ? m_impl->characters() : nullptr; } - char operator[](ssize_t i) const + char operator[](int i) const { ASSERT(m_impl); return (*m_impl)[i]; diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index c472e940224..1f866ed5e54 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -100,12 +100,12 @@ public: return *this; } - static ByteBuffer create_uninitialized(ssize_t size) { return ByteBuffer(ByteBufferImpl::create_uninitialized(size)); } - static ByteBuffer create_zeroed(ssize_t size) { return ByteBuffer(ByteBufferImpl::create_zeroed(size)); } - static ByteBuffer copy(const void* data, ssize_t size) { return ByteBuffer(ByteBufferImpl::copy(data, size)); } - static ByteBuffer wrap(const void* data, ssize_t size) { return ByteBuffer(ByteBufferImpl::wrap(data, size)); } - static ByteBuffer wrap(void* data, ssize_t size) { return ByteBuffer(ByteBufferImpl::wrap(data, size)); } - static ByteBuffer adopt(void* data, ssize_t size) { return ByteBuffer(ByteBufferImpl::adopt(data, size)); } + static ByteBuffer create_uninitialized(int size) { return ByteBuffer(ByteBufferImpl::create_uninitialized(size)); } + static ByteBuffer create_zeroed(int size) { return ByteBuffer(ByteBufferImpl::create_zeroed(size)); } + static ByteBuffer copy(const void* data, int size) { return ByteBuffer(ByteBufferImpl::copy(data, size)); } + static ByteBuffer wrap(const void* data, int size) { return ByteBuffer(ByteBufferImpl::wrap(data, size)); } + static ByteBuffer wrap(void* data, int size) { return ByteBuffer(ByteBufferImpl::wrap(data, size)); } + static ByteBuffer adopt(void* data, int size) { return ByteBuffer(ByteBufferImpl::adopt(data, size)); } ~ByteBuffer() { clear(); } void clear() { m_impl = nullptr; } @@ -114,18 +114,18 @@ public: bool operator!() const { return is_null(); } bool is_null() const { return m_impl == nullptr; } - byte& operator[](ssize_t i) + byte& operator[](int i) { ASSERT(m_impl); return (*m_impl)[i]; } - byte operator[](ssize_t i) const + byte operator[](int i) const { ASSERT(m_impl); return (*m_impl)[i]; } bool is_empty() const { return !m_impl || m_impl->is_empty(); } - ssize_t size() const { return m_impl ? m_impl->size() : 0; } + int size() const { return m_impl ? m_impl->size() : 0; } byte* data() { return pointer(); } const byte* data() const { return pointer(); } @@ -133,8 +133,8 @@ public: byte* pointer() { return m_impl ? m_impl->pointer() : nullptr; } const byte* pointer() const { return m_impl ? m_impl->pointer() : nullptr; } - byte* offset_pointer(ssize_t offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } - const byte* offset_pointer(ssize_t offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } + byte* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } + const byte* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; } const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; } @@ -147,13 +147,13 @@ public: } // NOTE: trim() does not reallocate. - void trim(ssize_t size) + void trim(int size) { if (m_impl) m_impl->trim(size); } - ByteBuffer slice(ssize_t offset, ssize_t size) const + ByteBuffer slice(int offset, int size) const { if (is_null()) return {}; @@ -164,7 +164,7 @@ public: return copy(offset_pointer(offset), size); } - void grow(ssize_t size) + void grow(int size) { if (!m_impl) m_impl = ByteBufferImpl::create_uninitialized(size); @@ -204,7 +204,7 @@ inline ByteBufferImpl::ByteBufferImpl(const void* data, int size, ConstructionMo m_owned = true; } -inline ByteBufferImpl::ByteBufferImpl(void* data, ssize_t size, ConstructionMode mode) +inline ByteBufferImpl::ByteBufferImpl(void* data, int size, ConstructionMode mode) : m_data(static_cast(data)) , m_size(size) { @@ -215,7 +215,7 @@ inline ByteBufferImpl::ByteBufferImpl(void* data, ssize_t size, ConstructionMode } } -inline void ByteBufferImpl::grow(ssize_t size) +inline void ByteBufferImpl::grow(int size) { ASSERT(size > m_size); ASSERT(m_owned); diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index 0088b550cef..087eb34d437 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -1,11 +1,15 @@ #pragma once #include -#include +#include static constexpr const char* printf_hex_digits = "0123456789abcdef"; +#ifdef __serenity__ extern "C" size_t strlen(const char*); +#else +#include +#endif template [[gnu::always_inline]] inline int print_hex(PutChFunc putch, char*& bufptr, T number, byte fields) @@ -174,7 +178,7 @@ template } template -[[gnu::always_inline]] inline int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap) +[[gnu::always_inline]] inline int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, va_list ap) { const char* p; diff --git a/AK/String.cpp b/AK/String.cpp index d0ca1b49095..fce8006e4d6 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -1,7 +1,7 @@ #include "AKString.h" #include "StdLibExtras.h" #include "StringBuilder.h" -#include +#include namespace AK { @@ -78,17 +78,17 @@ Vector String::split_limit(const char separator, int limit) const return {}; Vector v; - ssize_t substart = 0; - for (ssize_t i = 0; i < length() && (v.size() + 1) != limit; ++i) { + int substart = 0; + for (int i = 0; i < length() && (v.size() + 1) != limit; ++i) { char ch = characters()[i]; if (ch == separator) { - ssize_t sublen = i - substart; + int sublen = i - substart; if (sublen != 0) v.append(substring(substart, sublen)); substart = i + 1; } } - ssize_t taillen = length() - substart; + int taillen = length() - substart; if (taillen != 0) v.append(substring(substart, taillen)); if (characters()[length() - 1] == separator) @@ -102,17 +102,17 @@ Vector String::split_view(const char separator) const return {}; Vector v; - ssize_t substart = 0; - for (ssize_t i = 0; i < length(); ++i) { + int substart = 0; + for (int i = 0; i < length(); ++i) { char ch = characters()[i]; if (ch == separator) { - ssize_t sublen = i - substart; + int sublen = i - substart; if (sublen != 0) v.append(substring_view(substart, sublen)); substart = i + 1; } } - ssize_t taillen = length() - substart; + int taillen = length() - substart; if (taillen != 0) v.append(substring_view(substart, taillen)); if (characters()[length() - 1] == separator) @@ -131,7 +131,7 @@ int String::to_int(bool& ok) const { bool negative = false; int value = 0; - ssize_t i = 0; + int i = 0; if (is_null()) { ok = false; @@ -158,7 +158,7 @@ int String::to_int(bool& ok) const unsigned String::to_uint(bool& ok) const { unsigned value = 0; - for (ssize_t i = 0; i < length(); ++i) { + for (int i = 0; i < length(); ++i) { if (characters()[i] < '0' || characters()[i] > '9') { ok = false; return 0; diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 6ba5754c73f..429bb5771b1 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -1,17 +1,17 @@ #include #include #include -#include +#include namespace AK { -inline void StringBuilder::will_append(ssize_t size) +inline void StringBuilder::will_append(int size) { if ((m_length + size) > m_buffer.size()) - m_buffer.grow(max((ssize_t)16, m_buffer.size() * 2 + size)); + m_buffer.grow(max((int)16, m_buffer.size() * 2 + size)); } -StringBuilder::StringBuilder(ssize_t initial_capacity) +StringBuilder::StringBuilder(int initial_capacity) { m_buffer.grow(initial_capacity); } @@ -25,7 +25,7 @@ void StringBuilder::append(const StringView& str) m_length += str.length(); } -void StringBuilder::append(const char* characters, ssize_t length) +void StringBuilder::append(const char* characters, int length) { if (!length) return; diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 65bc8e2c072..744c71ef4b2 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -2,18 +2,18 @@ #include "AKString.h" #include "Vector.h" -#include +#include namespace AK { class StringBuilder { public: - explicit StringBuilder(ssize_t initial_capacity = 16); + explicit StringBuilder(int initial_capacity = 16); ~StringBuilder() {} void append(const StringView&); void append(char); - void append(const char*, ssize_t); + void append(const char*, int); void appendf(const char*, ...); void appendvf(const char*, va_list); @@ -21,10 +21,10 @@ public: ByteBuffer to_byte_buffer(); private: - void will_append(ssize_t); + void will_append(int); ByteBuffer m_buffer; - ssize_t m_length { 0 }; + int m_length { 0 }; }; } diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 2799e237d6d..0130cb90bad 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -3,6 +3,10 @@ #include "StdLibExtras.h" #include "kmalloc.h" +#ifndef __serenity__ +#include +#endif + //#define DEBUG_STRINGIMPL #ifdef DEBUG_STRINGIMPL diff --git a/AK/Vector.h b/AK/Vector.h index c1b9c5622f0..12131ae9584 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -4,6 +4,10 @@ #include #include +#ifndef __serenity__ +#include +#endif + namespace AK { template