ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
util.c
Go to the documentation of this file.
1
7#include <ascii-chat/platform/abstraction.h>
8#include <ascii-chat/asciichat_errno.h>
9#include <time.h>
10#include <stddef.h>
11#include <stdbool.h>
12
13// Backtrace stubs (not supported in WASM)
14int platform_backtrace(void **buffer, int size) {
15 (void)buffer;
16 (void)size;
17 return 0; // No backtrace support in WASM
18}
19
20char **platform_backtrace_symbols(void *const *buffer, int size) {
21 (void)buffer;
22 (void)size;
23 return NULL; // No backtrace symbols in WASM
24}
25
27 (void)symbols;
28 // No-op
29}
30
31void platform_print_backtrace_symbols(const char *label, char **symbols, int count, int skip_frames, int max_frames,
32 backtrace_frame_filter_t filter) {
33 (void)label;
34 (void)symbols;
35 (void)count;
36 (void)skip_frames;
37 (void)max_frames;
38 (void)filter;
39 // No-op - backtrace not supported in WASM
40}
41
42void platform_print_backtrace(int skip_frames) {
43 (void)skip_frames;
44 // No-op - backtrace not supported in WASM
45}
46
47// Localtime stub
48asciichat_error_t platform_localtime(const time_t *timer, struct tm *result) {
49 if (!timer || !result) {
50 return ERROR_INVALID_PARAM;
51 }
52 // Use thread-safe localtime_r for both WASM and native builds
53 // IMPORTANT: localtime() is NOT thread-safe and causes deadlocks in threaded WASM builds
54 if (localtime_r(timer, result) != NULL) {
55 return ASCIICHAT_OK;
56 }
57 return ERROR_PLATFORM_INIT;
58}
59
60// Isatty stub
61int platform_isatty(int fd) {
62 (void)fd;
63 return 1; // Always true for WASM terminal (xterm.js)
64}
65
66// Error state management
68 // No-op - error state is thread-local, nothing to clear in WASM
69}
70
71// Temp directory stub
72bool platform_get_temp_dir(char *temp_dir, size_t path_size) {
73 if (!temp_dir || path_size == 0) {
74 return false;
75 }
76 platform_strlcpy(temp_dir, "/tmp", path_size);
77 return true;
78}
79
80// Prompt stub
81bool platform_prompt_yes_no(const char *question, bool default_yes) {
82 (void)question;
83 return default_yes; // Always return default in WASM
84}
85
86// Error handling stub
88 return 0; // No system error in WASM
89}
90
91// Path utility stubs
92const char *platform_get_home_dir(void) {
93 return "/home"; // WASM virtual filesystem home
94}
95
97 // No-op - WASM uses forward slashes (Unix-style)
98 (void)path;
99}
100
101// Config directory stub
103 static char config_dir[] = "/config";
104 return config_dir; // WASM virtual filesystem config directory
105}
106
107// Current working directory stub
108bool platform_get_cwd(char *cwd, size_t path_size) {
109 if (!cwd || path_size == 0) {
110 return false;
111 }
112 platform_strlcpy(cwd, "/", path_size);
113 return true;
114}
115
116// Path comparison stub (case-sensitive on WASM)
117int platform_path_strcasecmp(const char *a, const char *b, size_t n) {
118 return strncmp(a, b, n); // Case-sensitive on WASM
119}
120
121// File type check stub
122int platform_is_regular_file(const char *path) {
123 (void)path;
124 return 0; // No file system access in WASM mirror mode
125}
size_t platform_strlcpy(char *dst, const char *src, size_t size)
int platform_isatty(int fd)
Definition util.c:61
bool platform_get_cwd(char *cwd, size_t path_size)
Definition util.c:108
int platform_path_strcasecmp(const char *a, const char *b, size_t n)
Definition util.c:117
int platform_backtrace(void **buffer, int size)
Definition util.c:14
void platform_print_backtrace_symbols(const char *label, char **symbols, int count, int skip_frames, int max_frames, backtrace_frame_filter_t filter)
Definition util.c:31
int platform_get_last_error(void)
Definition util.c:87
void platform_normalize_path_separators(char *path)
Definition util.c:96
void platform_clear_error_state(void)
Definition util.c:67
void platform_backtrace_symbols_destroy(char **symbols)
Definition util.c:26
asciichat_error_t platform_localtime(const time_t *timer, struct tm *result)
Definition util.c:48
void platform_print_backtrace(int skip_frames)
Definition util.c:42
bool platform_get_temp_dir(char *temp_dir, size_t path_size)
Definition util.c:72
int platform_is_regular_file(const char *path)
Definition util.c:122
char ** platform_backtrace_symbols(void *const *buffer, int size)
Definition util.c:20
const char * platform_get_home_dir(void)
Definition util.c:92
bool platform_prompt_yes_no(const char *question, bool default_yes)
Definition util.c:81
char * platform_get_config_dir(void)
Definition util.c:102