ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
string.c File Reference

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)
int platform_memcpy (void *dest, size_t dest_size, const void *src, size_t count)
int 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)
int platform_strcpy (char *dest, size_t dest_size, const char *src)
int platform_strncpy (char *dest, size_t dest_size, const char *src, size_t count)

Function Documentation

◆ platform_asprintf()

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

Definition at line 47 of file src/web/platform/string.c.

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

References args.

◆ platform_memcpy()

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

Definition at line 61 of file src/web/platform/string.c.

61 {
62 if (!dest || !src) {
64 }
65 if (count > dest_size) {
66 return ERROR_INVALID_PARAM; // Buffer overflow protection
67 }
68 memcpy(dest, src, count);
69 return ASCIICHAT_OK;
70}
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM

References ASCIICHAT_OK, and ERROR_INVALID_PARAM.

◆ platform_memset()

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

Definition at line 72 of file src/web/platform/string.c.

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

References ASCIICHAT_OK, and ERROR_INVALID_PARAM.

◆ platform_strcasecmp()

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

Definition at line 42 of file src/web/platform/string.c.

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

Referenced by color_filter_from_cli_name(), detect_terminal_background(), http_response_set_header(), http_server_authorize(), validate_opt_log_level(), and validate_opt_reconnect().

◆ platform_strcpy()

int platform_strcpy ( char * dest,
size_t dest_size,
const char * src )

Definition at line 91 of file src/web/platform/string.c.

91 {
92 if (!dest || !src) {
94 }
95 if (dest_size == 0) {
97 }
98
99 size_t src_len = strlen(src);
100 if (src_len >= dest_size) {
101 return ERROR_INVALID_PARAM;
102 }
103
104 strncpy(dest, src, dest_size - 1);
105 dest[dest_size - 1] = '\0';
106 return ASCIICHAT_OK;
107}

References ASCIICHAT_OK, and ERROR_INVALID_PARAM.

◆ platform_strdup()

◆ platform_strlcat()

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

Definition at line 26 of file src/web/platform/string.c.

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

◆ platform_strlcpy()

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

Definition at line 12 of file src/web/platform/string.c.

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

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 87 of file src/web/platform/string.c.

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

Referenced by ffmpeg_decoder_create_with_request_options(), http_basic_auth_parse(), and yt_dlp_extract_with_options().

◆ platform_strncpy()

int platform_strncpy ( char * dest,
size_t dest_size,
const char * src,
size_t count )

Definition at line 109 of file src/web/platform/string.c.

109 {
110 if (!dest || !src || dest_size == 0 || count >= dest_size)
111 return ERROR_INVALID_PARAM;
112 memcpy(dest, src, count);
113 dest[count] = '\0';
114 return ASCIICHAT_OK;
115}

References ASCIICHAT_OK, and ERROR_INVALID_PARAM.

Referenced by http_server_dispatch_http3(), parse_private_key(), and parse_public_key().

◆ platform_vsnprintf()

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

Definition at line 83 of file src/web/platform/string.c.

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