summaryrefslogtreecommitdiff
path: root/include/al
diff options
context:
space:
mode:
Diffstat (limited to 'include/al')
-rw-r--r--include/al/lib.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/include/al/lib.h b/include/al/lib.h
index 4f03235..ac47896 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -75,7 +75,8 @@ void al_malloc_stats(size_t *current, size_t *peak, size_t *total);
#define al_memset memset
#define al_bzero bzero
#define al_strlen strlen
-#define al_strndup strndup
+// strndup is _POSIX_C_SOURCE >= 200809L.
+//#define al_strndup strndup
#define al_snprintf snprintf
#define al_vsnprintf vsnprintf
#define al_fflush fflush
@@ -103,6 +104,15 @@ static inline size_t al_strnlen(const char *s, size_t n)
return p ? (size_t)(p - s) : n;
}
+static inline char *al_strndup(const char *s, size_t n)
+{
+ size_t len = al_strnlen(s, n);
+ char *ret = al_malloc(len + 1);
+ al_memcpy(ret, s, len);
+ ret[len] = '\0';
+ return ret;
+}
+
static inline s32 al_printf(const char *fmt, ...)
{
#ifdef AL_FORCE_DISABLE_OUTPUT
@@ -229,8 +239,7 @@ AL_UNUSED_FUNCTION_POP
#define MAX_ALLOC_32 ((INT32_MAX - 1) / 4)
#endif
-// Once a growing allocation expands past this number,
-// only grow in multiples of it.
+// Once a growing allocation expands past this number, only grow in multiples of it.
extern u32 al_grow_step;
u32 al_default_growing_allocation(void **ptr, u32 prev_size, u32 size,