diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-11-02 20:45:02 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-11-02 20:45:02 -0500 |
commit | e8422002f84dc4313894a5b3136c44a9005081fd (patch) | |
tree | b41633d9f759306fe9c7c01e209780222b47f5df /include/fud_c_string.hpp | |
parent | 6c7fd1db481ff10a16ecab958c6542784fa60b9c (diff) |
Allocator deallocate is void rather than returning FudStatus.
Diffstat (limited to 'include/fud_c_string.hpp')
-rw-r--r-- | include/fud_c_string.hpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/include/fud_c_string.hpp b/include/fud_c_string.hpp index d55ba30..a1ab51a 100644 --- a/include/fud_c_string.hpp +++ b/include/fud_c_string.hpp @@ -20,14 +20,17 @@ #include <climits> #include <cstddef> +#include <limits> #include <sys/types.h> namespace fud { +constexpr ssize_t MAX_C_STRING_LENGTH = std::numeric_limits<ssize_t>::max() - 1; + constexpr ssize_t cStringLength(const char* str, size_t maxLength) { - if (str == nullptr || maxLength > (SSIZE_MAX - 1)) { + if (str == nullptr || maxLength > MAX_C_STRING_LENGTH) { return -1; } @@ -46,13 +49,14 @@ constexpr ssize_t cStringLength(const char* str, size_t maxLength) constexpr ssize_t cStringLength(const char* str) { - constexpr auto maxLength = SSIZE_MAX - 1; - return cStringLength(str, maxLength); + return cStringLength(str, MAX_C_STRING_LENGTH); } constexpr ssize_t cStringLength(const char8_t* str, size_t maxLength) { - if (str == nullptr || maxLength > (SSIZE_MAX - 1)) { + // Cannot cast str to const char* without breaking constexpr + // return cStringLength(reinterpret_cast<const char*>(str), maxLength); + if (str == nullptr || maxLength > MAX_C_STRING_LENGTH) { return -1; } @@ -71,8 +75,7 @@ constexpr ssize_t cStringLength(const char8_t* str, size_t maxLength) constexpr ssize_t cStringLength(const char8_t* str) { - constexpr auto maxLength = SSIZE_MAX - 1; - return cStringLength(str, maxLength); + return cStringLength(str, MAX_C_STRING_LENGTH); } } // namespace fud |