ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
util.c
Go to the documentation of this file.
1
11#include <time.h>
12#include <stddef.h>
13#include <stdbool.h>
14
15// Backtrace stubs (not supported in WASM)
16int platform_backtrace(void **buffer, int size) {
17 (void)buffer;
18 (void)size;
19 return 0; // No backtrace support in WASM
20}
21
22char **platform_backtrace_symbols(void *const *buffer, int size) {
23 (void)buffer;
24 (void)size;
25 return NULL; // No backtrace symbols in WASM
26}
27
29 (void)symbols;
30 // No-op
31}
32
33void platform_print_backtrace_symbols(const char *label, char **symbols, int count, int skip_frames, int max_frames,
35 (void)label;
36 (void)symbols;
37 (void)count;
38 (void)skip_frames;
39 (void)max_frames;
40 (void)filter;
41 // No-op - backtrace not supported in WASM
42}
43
44void platform_print_backtrace(int skip_frames) {
45 (void)skip_frames;
46 // No-op - backtrace not supported in WASM
47}
48
49// Localtime stub
50asciichat_error_t platform_localtime(const time_t *timer, struct tm *result) {
51 if (!timer || !result) {
53 }
54 // Use thread-safe localtime_r for both WASM and native builds
55 // IMPORTANT: localtime() is NOT thread-safe and causes deadlocks in threaded WASM builds
56 if (localtime_r(timer, result) != NULL) {
57 return ASCIICHAT_OK;
58 }
60}
61
62// Isatty stub
63int platform_isatty(int fd) {
64 (void)fd;
65 return 1; // Always true for the browser terminal
66}
67
68// Error state management
70 // No-op - error state is thread-local, nothing to clear in WASM
71}
72
73// Temp directory stub
74bool platform_get_temp_dir(char *temp_dir, size_t path_size) {
75 if (!temp_dir || path_size == 0) {
76 return false;
77 }
78 platform_strlcpy(temp_dir, "/tmp", path_size);
79 return true;
80}
81
82// Prompt stub
83bool platform_prompt_yes_no(const char *question, bool default_yes) {
84 (void)question;
85 return default_yes; // Always return default in WASM
86}
87
88// Error handling stub
90 return 0; // No system error in WASM
91}
92
93// Path utility stubs
94const char *platform_get_home_dir(void) {
95 return "/home"; // WASM virtual filesystem home
96}
97
99 // No-op - WASM uses forward slashes (Unix-style)
100 (void)path;
101}
102
103// Config directory stub
105 static char config_dir[] = "/config";
106 return config_dir; // WASM virtual filesystem config directory
107}
108
109// Current working directory stub
110bool platform_get_cwd(char *cwd, size_t path_size) {
111 if (!cwd || path_size == 0) {
112 return false;
113 }
114 platform_strlcpy(cwd, "/", path_size);
115 return true;
116}
117
118// Path comparison stub (case-sensitive on WASM)
119int platform_path_strcasecmp(const char *a, const char *b, size_t n) {
120 return strncmp(a, b, n); // Case-sensitive on WASM
121}
122
123// File type check stub
124int platform_is_regular_file(const char *path) {
125 (void)path;
126 return 0; // No file system access in WASM mirror mode
127}
Platform abstraction layer umbrella header providing unified cross-platform API.
⚠️‼️ Comprehensive thread-local error context system for ascii-chat
📍 Backtrace capture, symbolization, and formatting
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
@ ERROR_PLATFORM_INIT
Definition error_codes.h:60
@ ASCIICHAT_OK
Definition error_codes.h:51
@ ERROR_INVALID_PARAM
bool platform_get_cwd(char *cwd, size_t path_size)
Get the current working directory of the process.
Definition util.c:110
int platform_path_strcasecmp(const char *a, const char *b, size_t n)
Platform-aware path string comparison.
Definition util.c:119
int platform_backtrace(void **buffer, int size)
Get a backtrace of the current call stack.
Definition util.c:16
void platform_backtrace_symbols_destroy(char **symbols)
Free symbol array from platform_backtrace_symbols()
Definition util.c:28
bool platform_prompt_yes_no(const char *question, bool default_yes)
Prompt the user for a yes/no answer.
Definition util.c:83
int platform_get_last_error(void)
Get the last system error code.
Definition util.c:89
void platform_normalize_path_separators(char *path)
Normalize path separators for the current platform.
Definition util.c:98
void platform_clear_error_state(void)
Definition util.c:69
asciichat_error_t platform_localtime(const time_t *timer, struct tm *result)
Platform-safe localtime wrapper.
Definition util.c:50
bool platform_get_temp_dir(char *temp_dir, size_t path_size)
Get the system temporary directory path.
Definition util.c:74
int platform_is_regular_file(const char *path)
Check if a path is a regular file.
Definition util.c:124
size_t platform_strlcpy(char *dst, const char *src, size_t size)
Safe string copy with size tracking (strlcpy)
char ** platform_backtrace_symbols(void *const *buffer, int size)
Convert backtrace addresses to symbol names.
Definition util.c:22
const char * platform_get_home_dir(void)
Get the user's home directory.
Definition util.c:94
char * platform_get_config_dir(void)
Get the application configuration directory.
Definition util.c:104
bool(* backtrace_frame_filter_t)(const char *frame)
ClangTool/LibTooling compatibility shim for stdbool.h.
🖥️ Cross-platform terminal interface for ascii-chat
⏱️ High-precision timing utilities using sokol_time.h and uthash
int platform_isatty(int fd)
Check if a file descriptor is a terminal.
Definition util.c:63
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:33
void platform_print_backtrace(int skip_frames)
Definition util.c:44