summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-08-25 19:39:56 -0400
committerAndrew Opalach <andrew@akon.city> 2026-08-25 19:39:56 -0400
commit8ebcc1fa354fac87771caa88ee67600412bbcb57 (patch)
tree3413702b92b225bf59e733d250b599bef6781078 /src/common.c
parent87a93623126c41cdfdbdb62878efb3f1d33b819e (diff)
downloadlibnaunet-8ebcc1fa354fac87771caa88ee67600412bbcb57.tar.gz
libnaunet-8ebcc1fa354fac87771caa88ee67600412bbcb57.tar.bz2
libnaunet-8ebcc1fa354fac87771caa88ee67600412bbcb57.zip
Global temp path, android build fixes
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/common.c b/src/common.c
index d0bd863..4358945 100644
--- a/src/common.c
+++ b/src/common.c
@@ -7,13 +7,23 @@
#else
#include <unistd.h>
#endif
+#ifdef NAUNET_ON_ANDROID
+#include <android/log.h>
+#endif
#include "util/timer/timer.h"
#include "util/thread/thread.h"
#include "common.h"
-#ifndef NAUNET_ON_WINDOWS
+#ifdef NAUNET_ON_WINDOWS
+static char temp_directory[MAX_PATH + 1];
+#else
+static char temp_directory[PATH_MAX];
+#endif
+str nn_temp_directory;
+
+#if !defined NAUNET_ON_WINDOWS && !defined NAUNET_ON_ANDROID
#define RESET "\033[0m"
static inline const char *get_color_for_level(u8 level)
{
@@ -37,11 +47,15 @@ s32 al_print_default(void *userdata, u8 level, char *message)
{
(void)userdata;
s32 ret = 0;
-#ifdef NAUNET_ON_WINDOWS
+#if defined NAUNET_ON_ANDROID
+ (void)level;
+ __android_log_print(ANDROID_LOG_DEBUG, APPLICATION_NAME, "%*.*s", 0, AL_LOG_MESSAGE_SIZE, message);
+ ret = al_strnlen(message, AL_LOG_MESSAGE_SIZE);
+#elif defined NAUNET_ON_WINDOWS
(void)level;
- ret = al_printf("%*.*s\n", 0, AL_LOG_MESSAGE_SIZE, message);
+ ret = al_printf("%*.*s\n", 0, AL_LOG_MESSAGE_LENGTH, message);
#else
- ret = al_printf("%s%*.*s%s\n", get_color_for_level(level), 0, AL_LOG_MESSAGE_SIZE, message, RESET);
+ ret = al_printf("%s%*.*s%s\n", get_color_for_level(level), 0, AL_LOG_MESSAGE_LENGTH, message, RESET);
#endif
return ret;
}
@@ -90,6 +104,17 @@ bool nn_common_init(const char *thread_name)
al_random_init((u32)(nn_get_timestamp() / 1000000));
+#if defined NAUNET_ON_WINDOWS
+ DWORD length = GetTempPathA(sizeof(temp_directory), temp_directory);
+ nn_temp_directory = al_str_w(temp_directory, 0, length);
+#elif defined NAUNET_ON_ANDROID
+ // Default to empty.
+#else
+ const char unix_tmpdir[] = { "/tmp" };
+ al_memcpy(temp_directory, unix_tmpdir, sizeof(unix_tmpdir));
+ nn_temp_directory = al_str_w(temp_directory, 0, sizeof(unix_tmpdir) - 1);
+#endif
+
#ifdef NAUNET_ON_WINDOWS
if (!nn_windows_init()) return false;
#endif
@@ -97,6 +122,13 @@ bool nn_common_init(const char *thread_name)
return true;
}
+void nn_common_set_temp_directory(str *dir)
+{
+ al_assert(dir->length < sizeof(temp_directory));
+ al_memcpy(temp_directory, dir->data, dir->length);
+ nn_temp_directory = al_str_w(temp_directory, 0, dir->length);
+}
+
void nn_common_close(void)
{
#ifdef NAUNET_ON_WINDOWS