summaryrefslogtreecommitdiff
path: root/include/al
diff options
context:
space:
mode:
Diffstat (limited to 'include/al')
-rw-r--r--include/al/lib.h14
-rw-r--r--include/al/str.h12
2 files changed, 25 insertions, 1 deletions
diff --git a/include/al/lib.h b/include/al/lib.h
index 81f6978..63a2f48 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
+#include <ctype.h>
void al_malloc_init(void);
void al_malloc_close(void);
@@ -44,10 +45,11 @@ void al_set_alloc(void *(*malloc_func)(size_t), void *(*calloc_func)(size_t, siz
#define al_memset memset
#define al_bzero bzero
#define al_strlen strlen
+#define al_sprintf sprintf
#ifdef _DEBUG_
#define al_assert assert
#else
-#define al_assert(expr) do { (void)sizeof(expr); } while (0)
+#define al_assert(expr) do { (void)sizeof(expr); } while (0) // NOLINT(bugprone-sizeof-expression)
#endif
#define al_alloc_object(type) (type *)al_calloc(1, sizeof(type))
@@ -148,6 +150,16 @@ static inline u32 al_u32_inc_wrap(u32 v)
return (v == UINT32_MAX) ? 0 : v + 1;
}
+static inline u32 al_u32_add_wrap(u32 v, u32 add)
+{
+ return (((u64)v + add) > UINT32_MAX) ? (add - (UINT32_MAX - v)) : v + add;
+}
+
+static inline u16 al_u16_add_wrap(u16 v, u16 add)
+{
+ return (((u32)v + add) > UINT16_MAX) ? (add - (UINT16_MAX - v)) : v + add;
+}
+
AL_UNUSED_FUNCTION_PUSH
extern size_t al_page_size;
diff --git a/include/al/str.h b/include/al/str.h
index 9ede09a..ed53c25 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -30,6 +30,11 @@ typedef struct {
AL_UNUSED_FUNCTION_PUSH
+static inline bool al_str_is_empty(str *s)
+{
+ return s->len == 0;
+}
+
static inline void al_str_free(str *s)
{
if (s->alloc > 0) al_free(s->data);
@@ -75,6 +80,13 @@ static inline void al_str_from(str *s, const char *c_str)
s->len = (u32)len;
}
+static inline void al_str_to_lower(str *s)
+{
+ for (u32 i = 0; i < s->len; i++) {
+ al_str_at(s, i) = tolower(al_str_at(s, i));
+ }
+}
+
// Returned c_str must be free'd by the user.
static inline char *al_str_to_c_str(str *s)
{