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

String utility functions for WASM/Emscripten. More...

Go to the source code of this file.

Functions

size_t platform_strlcpy (char *dst, const char *src, size_t size)
 
size_t platform_strlcat (char *dst, const char *src, size_t size)
 
int platform_strcasecmp (const char *s1, const char *s2)
 
int platform_asprintf (char **strp, const char *fmt,...)
 
char * platform_strdup (const char *s)
 
asciichat_error_t platform_memcpy (void *dest, size_t dest_size, const void *src, size_t count)
 
asciichat_error_t platform_memset (void *dest, size_t dest_size, int ch, size_t count)
 
int platform_vsnprintf (char *str, size_t size, const char *format, va_list ap)
 
int platform_strncasecmp (const char *s1, const char *s2, size_t n)
 

Detailed Description

String utility functions for WASM/Emscripten.

Definition in file platform/wasm/string.c.

Function Documentation

◆ platform_asprintf()

int platform_asprintf ( char **  strp,
const char *  fmt,
  ... 
)

Definition at line 48 of file platform/wasm/string.c.

48 {
49 // Use standard asprintf (available in WASM/Emscripten)
50 va_list args;
51 va_start(args, fmt);
52 int ret = vasprintf(strp, fmt, args);
53 va_end(args);
54 return ret;
55}
action_args_t args

References args.

◆ platform_memcpy()

asciichat_error_t platform_memcpy ( void *  dest,
size_t  dest_size,
const void *  src,
size_t  count 
)

Definition at line 62 of file platform/wasm/string.c.

62 {
63 if (!dest || !src) {
64 return ERROR_INVALID_PARAM;
65 }
66 if (count > dest_size) {
67 return ERROR_INVALID_PARAM; // Buffer overflow protection
68 }
69 memcpy(dest, src, count);
70 return ASCIICHAT_OK;
71}

◆ platform_memset()

asciichat_error_t platform_memset ( void *  dest,
size_t  dest_size,
int  ch,
size_t  count 
)

Definition at line 73 of file platform/wasm/string.c.

73 {
74 if (!dest) {
75 return ERROR_INVALID_PARAM;
76 }
77 if (count > dest_size) {
78 return ERROR_INVALID_PARAM; // Buffer overflow protection
79 }
80 memset(dest, ch, count);
81 return ASCIICHAT_OK;
82}

◆ platform_strcasecmp()

int platform_strcasecmp ( const char *  s1,
const char *  s2 
)

Definition at line 43 of file platform/wasm/string.c.

43 {
44 // Use standard strcasecmp (available in WASM)
45 return strcasecmp(s1, s2);
46}

Referenced by color_filter_from_cli_name(), detect_terminal_background(), options_init(), validate_opt_log_level(), and validate_opt_reconnect().

◆ platform_strdup()

◆ platform_strlcat()

size_t platform_strlcat ( char *  dst,
const char *  src,
size_t  size 
)

Definition at line 27 of file platform/wasm/string.c.

27 {
28 size_t dst_len = strlen(dst);
29 size_t src_len = strlen(src);
30
31 if (dst_len >= size) {
32 return dst_len + src_len;
33 }
34
35 size_t remaining = size - dst_len;
36 size_t copy_len = (src_len >= remaining) ? remaining - 1 : src_len;
37 memcpy(dst + dst_len, src, copy_len);
38 dst[dst_len + copy_len] = '\0';
39
40 return dst_len + src_len;
41}

◆ platform_strlcpy()

size_t platform_strlcpy ( char *  dst,
const char *  src,
size_t  size 
)

Definition at line 13 of file platform/wasm/string.c.

13 {
14 size_t src_len = strlen(src);
15
16 if (size == 0) {
17 return src_len;
18 }
19
20 size_t copy_len = (src_len >= size) ? size - 1 : src_len;
21 memcpy(dst, src, copy_len);
22 dst[copy_len] = '\0';
23
24 return src_len;
25}

Referenced by detect_terminal_capabilities(), platform_get_cwd(), and platform_get_temp_dir().

◆ platform_strncasecmp()

int platform_strncasecmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Definition at line 88 of file platform/wasm/string.c.

88 {
89 return strncasecmp(s1, s2, n);
90}

◆ platform_vsnprintf()

int platform_vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  ap 
)

Definition at line 84 of file platform/wasm/string.c.

84 {
85 return vsnprintf(str, size, format, ap);
86}

Referenced by safe_snprintf(), and safe_vsnprintf().