ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
util.c File Reference

Utility stubs for WASM/Emscripten (backtrace, localtime) More...

Go to the source code of this file.

Functions

int platform_backtrace (void **buffer, int size)
 
char ** platform_backtrace_symbols (void *const *buffer, int size)
 
void platform_backtrace_symbols_destroy (char **symbols)
 
void platform_print_backtrace_symbols (const char *label, char **symbols, int count, int skip_frames, int max_frames, backtrace_frame_filter_t filter)
 
void platform_print_backtrace (int skip_frames)
 
asciichat_error_t platform_localtime (const time_t *timer, struct tm *result)
 
int platform_isatty (int fd)
 
void platform_clear_error_state (void)
 
bool platform_get_temp_dir (char *temp_dir, size_t path_size)
 
bool platform_prompt_yes_no (const char *question, bool default_yes)
 
int platform_get_last_error (void)
 
const char * platform_get_home_dir (void)
 
void platform_normalize_path_separators (char *path)
 
char * platform_get_config_dir (void)
 
bool platform_get_cwd (char *cwd, size_t path_size)
 
int platform_path_strcasecmp (const char *a, const char *b, size_t n)
 
int platform_is_regular_file (const char *path)
 

Detailed Description

Utility stubs for WASM/Emscripten (backtrace, localtime)

Definition in file util.c.

Function Documentation

◆ platform_backtrace()

int platform_backtrace ( void **  buffer,
int  size 
)

Definition at line 14 of file util.c.

14 {
15 (void)buffer;
16 (void)size;
17 return 0; // No backtrace support in WASM
18}

Referenced by asciichat_fatal_with_context().

◆ platform_backtrace_symbols()

char ** platform_backtrace_symbols ( void *const *  buffer,
int  size 
)

Definition at line 20 of file util.c.

20 {
21 (void)buffer;
22 (void)size;
23 return NULL; // No backtrace symbols in WASM
24}

Referenced by asciichat_fatal_with_context().

◆ platform_backtrace_symbols_destroy()

void platform_backtrace_symbols_destroy ( char **  symbols)

Definition at line 26 of file util.c.

26 {
27 (void)symbols;
28 // No-op
29}

Referenced by asciichat_clear_errno(), asciichat_errno_destroy(), asciichat_fatal_with_context(), and asciichat_set_errno().

◆ platform_clear_error_state()

void platform_clear_error_state ( void  )

Definition at line 67 of file util.c.

67 {
68 // No-op - error state is thread-local, nothing to clear in WASM
69}

Referenced by asciichat_clear_errno().

◆ platform_get_config_dir()

char * platform_get_config_dir ( void  )

Definition at line 102 of file util.c.

102 {
103 static char config_dir[] = "/config";
104 return config_dir; // WASM virtual filesystem config directory
105}

Referenced by acds_identity_default_path(), and get_config_dir().

◆ platform_get_cwd()

bool platform_get_cwd ( char *  cwd,
size_t  path_size 
)

Definition at line 108 of file util.c.

108 {
109 if (!cwd || path_size == 0) {
110 return false;
111 }
112 platform_strlcpy(cwd, "/", path_size);
113 return true;
114}
size_t platform_strlcpy(char *dst, const char *src, size_t size)

References platform_strlcpy().

Referenced by get_log_dir(), and path_validate_user_path().

◆ platform_get_home_dir()

const char * platform_get_home_dir ( void  )

Definition at line 92 of file util.c.

92 {
93 return "/home"; // WASM virtual filesystem home
94}

Referenced by expand_path(), and path_validate_user_path().

◆ platform_get_last_error()

int platform_get_last_error ( void  )

Definition at line 87 of file util.c.

87 {
88 return 0; // No system error in WASM
89}

◆ platform_get_temp_dir()

bool platform_get_temp_dir ( char *  temp_dir,
size_t  path_size 
)

Definition at line 72 of file util.c.

72 {
73 if (!temp_dir || path_size == 0) {
74 return false;
75 }
76 platform_strlcpy(temp_dir, "/tmp", path_size);
77 return true;
78}

References platform_strlcpy().

Referenced by get_log_dir(), and path_validate_user_path().

◆ platform_is_regular_file()

int platform_is_regular_file ( const char *  path)

Definition at line 122 of file util.c.

122 {
123 (void)path;
124 return 0; // No file system access in WASM mirror mode
125}

Referenced by discovery_keys_clear_cache(), discovery_keys_load_cached(), and path_validate_user_path().

◆ platform_isatty()

int platform_isatty ( int  fd)

Definition at line 61 of file util.c.

61 {
62 (void)fd;
63 return 1; // Always true for WASM terminal (xterm.js)
64}

Referenced by session_display_create(), terminal_is_stderr_tty(), terminal_is_stdin_tty(), terminal_is_stdout_tty(), terminal_should_color_output(), and terminal_should_use_control_sequences().

◆ platform_localtime()

asciichat_error_t platform_localtime ( const time_t *  timer,
struct tm *  result 
)

Definition at line 48 of file util.c.

48 {
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}

Referenced by asciichat_error_stats_print(), asciichat_print_error_context(), get_current_time_formatted(), manpage_fmt_write_title(), and time_format_now().

◆ platform_normalize_path_separators()

void platform_normalize_path_separators ( char *  path)

Definition at line 96 of file util.c.

96 {
97 // No-op - WASM uses forward slashes (Unix-style)
98 (void)path;
99}

Referenced by expand_path().

◆ platform_path_strcasecmp()

int platform_path_strcasecmp ( const char *  a,
const char *  b,
size_t  n 
)

Definition at line 117 of file util.c.

117 {
118 return strncmp(a, b, n); // Case-sensitive on WASM
119}

Referenced by path_is_within_base().

◆ platform_print_backtrace()

void platform_print_backtrace ( int  skip_frames)

Definition at line 42 of file util.c.

42 {
43 (void)skip_frames;
44 // No-op - backtrace not supported in WASM
45}

Referenced by main().

◆ platform_print_backtrace_symbols()

void platform_print_backtrace_symbols ( const char *  label,
char **  symbols,
int  count,
int  skip_frames,
int  max_frames,
backtrace_frame_filter_t  filter 
)

Definition at line 31 of file util.c.

32 {
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}

◆ platform_prompt_yes_no()

bool platform_prompt_yes_no ( const char *  question,
bool  default_yes 
)

Definition at line 81 of file util.c.

81 {
82 (void)question;
83 return default_yes; // Always return default in WASM
84}

Referenced by action_completions(), client_crypto_handshake(), config_create_default(), discovery_keys_verify_change(), options_config_generate_manpage_merged(), prompt_unknown_host(), prompt_unknown_host_no_identity(), and server_main().