summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array.c2
-rw-r--r--src/log.c38
2 files changed, 15 insertions, 25 deletions
diff --git a/src/array.c b/src/array.c
index e95b1a9..9b61cd9 100644
--- a/src/array.c
+++ b/src/array.c
@@ -24,9 +24,9 @@
do { \
al_array_init(dest); \
al_array_reserve(dest, (src).size); \
+ (dest).size = (src).size; \
al_memcpy(&al_array_at(dest, 0), &al_array_at(src, 0), \
al_array_item_size(dest) * (dest).size); \
- (dest).size = (src).size; \
} while (0)
#define al_array_push(arr, item) \
diff --git a/src/log.c b/src/log.c
index 9a738df..5c41248 100644
--- a/src/log.c
+++ b/src/log.c
@@ -13,8 +13,8 @@ static s32 al_print_default(void *userdata, char *s)
return ret;
}
-__al_thread s32 (*_al_print)(void *, char *) = al_print_default;
-__al_thread void *_al_log_userdata = NULL;
+static s32 (*_al_print)(void *, char *) = al_print_default;
+static void *_al_log_userdata = NULL;
void al_set_print(s32 (*print_func)(void *, char *), void *userdata)
{
@@ -22,11 +22,10 @@ void al_set_print(s32 (*print_func)(void *, char *), void *userdata)
_al_log_userdata = userdata;
}
-static char *get_buffer(const char *level, const char *section, const char *fmt,
- const char *name, const s32 line, const char *func, va_list args)
+static char *get_buffer(const char *level, const char *section, const char *fmt, const char *name,
+ const s32 line, const char *func, va_list args)
{
char *buffer = al_calloc(1, AL_LOG_MESSAGE_SIZE + 1);
- al_memset(buffer, 0, AL_LOG_MESSAGE_SIZE);
s32 prefix = snprintf(buffer, AL_LOG_MESSAGE_SIZE, AL_LOG_TEMPLATE, name, line, func, level, section);
prefix += vsnprintf(buffer + prefix, AL_LOG_MESSAGE_SIZE - prefix, fmt, args);
buffer[strcspn(buffer, "\r\n")] = '\0';
@@ -36,15 +35,8 @@ static char *get_buffer(const char *level, const char *section, const char *fmt,
void al_set_print(s32 (*print_func)(void *, char *), void *userdata) { (void)print_func; (void)userdata; }
#endif
-s32 _al_log_nop(const char *section, const char *fmt, ...)
-{
- (void)section;
- (void)fmt;
- return 0;
-}
-
-s32 _al_log(const char *level, const char *section, const char *name, const s32 line,
- const char *func, const char *fmt, ...)
+s32 _al_log(const char *level, const char *section, const char *name,
+ const s32 line, const char *func, const char *fmt, ...)
{
#if AL_FORCE_DISABLE_OUTPUT
return 0;
@@ -52,10 +44,9 @@ s32 _al_log(const char *level, const char *section, const char *name, const s32
va_list args;
va_start(args, fmt);
#if AL_LOG_SKIP
- s32 ret = printf(AL_LOG_TEMPLATE, name, line, func, level, section);
- ret += vprintf(fmt, args);
- size_t cspn = strcspn(fmt, "\r\n");
- if (cspn == strlen(fmt)) ret += printf("\n");
+ s32 ret = al_printf(AL_LOG_TEMPLATE, name, line, func, level, section);
+ ret += al_vprintf(fmt, args);
+ if (strcspn(fmt, "\r\n") == al_strlen(fmt)) ret += al_printf("\n");
#else
char *buffer = get_buffer(level, section, fmt, name, line, func, args);
#endif
@@ -68,17 +59,16 @@ s32 _al_log(const char *level, const char *section, const char *name, const s32
#endif
}
-s32 _al_logv(const char *level, const char *section, const char *name, const s32 line,
- const char *func, const char *fmt, va_list args)
+s32 _al_logv(const char *level, const char *section, const char *name,
+ const s32 line, const char *func, const char *fmt, va_list args)
{
#if AL_FORCE_DISABLE_OUTPUT
return 0;
#else
#if AL_LOG_SKIP
- s32 ret = printf(AL_LOG_TEMPLATE, name, line, func, level, section);
- ret += vprintf(fmt, args);
- size_t cspn = strcspn(fmt, "\r\n");
- if (cspn == strlen(fmt)) ret += printf("\n");
+ s32 ret = al_printf(AL_LOG_TEMPLATE, name, line, func, level, section);
+ ret += al_vprintf(fmt, args);
+ if (strcspn(fmt, "\r\n") == al_strlen(fmt)) ret += al_printf("\n");
#else
char *buffer = get_buffer(level, section, fmt, name, line, func, args);
#endif