summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/al/lib.h14
-rw-r--r--include/al/str.h12
-rw-r--r--meson.build10
-rwxr-xr-xscripts/line_count.sh2
-rw-r--r--src/log.c2
5 files changed, 36 insertions, 4 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)
{
diff --git a/meson.build b/meson.build
index 6e5ac71..a47d3eb 100644
--- a/meson.build
+++ b/meson.build
@@ -31,11 +31,17 @@ endif
c89atomic = subproject('c89atomic').get_variable('c89atomic')
-alabaster_src = ['src/lib.c', 'src/str.c', 'src/log.c', 'src/ring_buffer.c']
+alabaster_src = [
+ 'src/lib.c',
+ 'src/str.c',
+ 'src/log.c',
+ 'src/ring_buffer.c'
+]
alabaster_inc = include_directories('include')
+alabaster_deps = [c89atomic]
alabaster = declare_dependency(include_directories: alabaster_inc,
- dependencies: [c89atomic], sources: alabaster_src,
+ dependencies: alabaster_deps, sources: alabaster_src,
compile_args: alabaster_args)
if get_option('build-tests') and not meson.is_subproject()
diff --git a/scripts/line_count.sh b/scripts/line_count.sh
new file mode 100755
index 0000000..aadb675
--- /dev/null
+++ b/scripts/line_count.sh
@@ -0,0 +1,2 @@
+#! /usr/bin/env sh
+find ./src ./include -type f | xargs wc -l
diff --git a/src/log.c b/src/log.c
index 0444ed6..ca9266d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,6 +1,6 @@
#include "../include/al/log.h"
-#define AL_LOG_SKIP 1
+#define AL_LOG_SKIP 0
#define AL_LOG_MESSAGE_SIZE 511
#define AL_LOG_TEMPLATE "%s:%d %s(): %s -> (%s) "