ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_freestanding_str.c File Reference

Project-owned freestanding string ABI primitives (strlen, strcmp, strchr, strstr, etc.). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_freestanding.h"
Include dependency graph for ra8_freestanding_str.c:

Go to the source code of this file.

Functions

size_t strlen (const char *s)
 Calculate string length.
size_t strnlen (const char *s, size_t maxlen)
 Calculate bounded string length.
int strcmp (const char *s1, const char *s2)
 Compare two null-terminated strings.
int strncmp (const char *s1, const char *s2, size_t n)
 Compare two strings up to a specified length.
char * strchr (const char *s, int c)
 Locate first occurrence of character in string.
char * strrchr (const char *s, int c)
 Locate last occurrence of character in string.
char * strstr (const char *haystack, const char *needle)
 Locate substring in string.
char * strcpy (char *dst, const char *src)
 Copy string to destination buffer.
char * strncpy (char *dst, const char *src, size_t n)
 Copy bounded string to destination buffer.

Detailed Description

Project-owned freestanding string ABI primitives (strlen, strcmp, strchr, strstr, etc.).

Tag
[Ring 0 / Foundation] {World: Dual}

Standard ISO C string primitives implemented directly for the bare-metal RA8 target firmware without libc or newlib dependencies. Deterministic, bounds-conscious, and heap-free.

Since
0.1.0

Definition in file ra8_freestanding_str.c.

Function Documentation

◆ strchr()

char * strchr ( const char * s,
int c )

Locate first occurrence of character in string.

Scans s for the first instance of character c (including null).

Parameters
[in]sNull-terminated string to search.
[in]cCharacter value to locate.
Returns
Pointer to first occurrence in s, or nullptr if not found.
Return values
non-nullPointer to first matching character in s.
nullptrCharacter not found in s.
Precondition
s points to a valid null-terminated string.
s is readable.
Postcondition
String content is unmodified.
Returned pointer (if non-null) is within s.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input string is not concurrently modified.
Since
0.1.0

Definition at line 157 of file ra8_freestanding_str.c.

References memcpy().

Referenced by internal_args_attach_blank_sd(), internal_authority_of(), internal_config_apply_line(), internal_cookie_name_valid(), internal_has_separator(), internal_json_str(), internal_mdl_state_split_tabs(), internal_next_line(), internal_panel_split_kv(), internal_parse_kv_line(), internal_parse_panel(), internal_parse_xml_tag(), internal_pubid_byte(), internal_split_field(), mdl_extract_selector(), mdl_meta_parse(), mdl_url_host(), and mdl_url_path().

◆ strcmp()

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

Compare two null-terminated strings.

Compares s1 and s2 lexicographically as unsigned char values.

Parameters
[in]s1First null-terminated string.
[in]s2Second null-terminated string.
Returns
Difference between first differing characters, or 0 if identical.
Return values
0Strings are identical up to null terminator.
<0First non-matching character in s1 is less than in s2.
>0First non-matching character in s1 is greater than in s2.
Precondition
Both s1 and s2 are valid null-terminated strings.
String buffers are readable.
Postcondition
Both input strings are unmodified.
Comparison semantics follow unsigned byte values.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input strings are not concurrently modified.
Since
0.1.0

Definition at line 93 of file ra8_freestanding_str.c.

Referenced by internal_add_manifest_image(), internal_agent_spec(), internal_already_have(), internal_apply_semantic_key(), internal_cache_find(), internal_cache_find(), internal_compile_images(), internal_compile_stylesheets(), internal_config_apply_pair(), internal_config_apply_string(), internal_config_apply_u32(), internal_config_parse_order(), internal_config_valid(), internal_demo_probe_fat(), internal_demo_probe_foreign(), internal_duplicate_name(), internal_epub_media_type_from_sniff(), internal_epub_media_type_from_suffix(), internal_epub_page_is_cover(), internal_extract_meta(), internal_extract_series_metadata(), internal_find_row(), internal_format(), internal_gov_find(), internal_hit_index_of(), internal_is_dot_segment(), internal_is_option_value(), internal_is_reserved_base(), internal_is_void(), internal_key_is(), internal_library_leaf(), internal_mdl_fetch_discard_stale_page(), internal_mdl_fetch_try_reuse(), internal_modem_answer_line(), internal_parse(), internal_parse(), internal_parse(), internal_parse_arguments(), internal_parse_verify_opt(), internal_parse_xml_semantics(), internal_redirect_host_ok(), internal_remove_stale_page_variants(), internal_resolve_one_leaf(), internal_resolve_removal_target(), internal_root_walk_step(), internal_snapshot_prior_metadata(), internal_sort_pages(), internal_split_output(), internal_split_output(), internal_split_output(), internal_split_path(), internal_stub_listdir(), internal_stub_open(), internal_stub_stat(), internal_take_flag(), internal_take_opt(), internal_tar_member(), internal_urlname_is_known_ext(), internal_validate_network_args(), internal_zip_member(), main(), mdl_extract_images(), mdl_format_from_str(), mdl_governor_peek(), mdl_robots_cache_consult(), mdl_search_filter_series_hits(), mdl_state_chapter_complete(), mdl_state_chapter_pages(), mdl_state_find_chapter(), mdl_storage_copy_atomic(), priv_book_is_block(), priv_fmt_try_portable_convert(), priv_fmt_try_portable_inspect(), priv_fmt_try_portable_verify(), priv_fs_posix_dir_next(), priv_fs_posix_root_alias_classify(), priv_mdl_export_path_join(), priv_mdl_export_prepare_cover(), priv_reflow_tok_classify(), and prof_load().

◆ strcpy()

char * strcpy ( char * dst,
const char * src )

Copy string to destination buffer.

Copies string src (including terminating null) to dst.

Parameters
[out]dstDestination buffer pointer.
[in]srcSource null-terminated string pointer.
Returns
Original destination pointer dst.
Return values
dstThe destination pointer passed in dst is always returned.
Precondition
dst has sufficient capacity to hold src and terminating null.
dst and src do not overlap.
Postcondition
The copied string at dst matches src.
Source string is unmodified.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when strings are not concurrently modified.
Since
0.1.0

Definition at line 261 of file ra8_freestanding_str.c.

◆ strlen()

size_t strlen ( const char * s)

Calculate string length.

Computes number of characters before terminating null byte.

Parameters
[in]sNull-terminated character string.
Returns
String length in characters.
Return values
lengthNumber of characters before null terminator.
Precondition
s points to a valid null-terminated string.
s is readable.
Postcondition
String content is unmodified.
Never negative.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input string is not concurrently modified.
Since
0.1.0

Definition at line 42 of file ra8_freestanding_str.c.

Referenced by cb_host_output_open(), demo_file_ops(), demo_print(), demo_puts(), demo_read_verify(), demo_write_test_file(), elf_sym_addr(), epub_toc_entry_to_chapter(), er_draw_key_label(), internal_add_manifest_image(), internal_add_rule(), internal_agent_spec(), internal_attr_at(), internal_authority_of(), internal_build_export_metadata(), internal_build_tar(), internal_cache_copy(), internal_cache_encode_record(), internal_cbz_add_metadata(), internal_ci_contains(), internal_class_has_token(), internal_cli_ends_ci(), internal_config_set_str(), internal_config_trim(), internal_config_valid(), internal_cookie_field_is(), internal_copy_fits(), internal_cover_copy(), internal_decode_entity(), internal_demo_http_get(), internal_demo_log(), internal_demo_print(), internal_elem_at(), internal_emit_cstr(), internal_ends_ci(), internal_ends_with(), internal_ends_with_ci(), internal_entity(), internal_epub_render_meta(), internal_exfat_list_emit(), internal_extract_label(), internal_extract_meta(), internal_fat_dir_scan_sector(), internal_filter_prefix(), internal_find_attr_value(), internal_find_ci(), internal_handle_cdata(), internal_handle_raw_text(), internal_hex_decode(), internal_intern_span(), internal_is_reserved_base(), internal_json_str(), internal_keyword(), internal_library_act_on_node(), internal_log(), internal_make_name(), internal_mdl_stage_headers(), internal_mdl_state_append_gaps(), internal_mdl_state_parse_binary64(), internal_mdl_state_paths(), internal_panel_rstrip(), internal_panel_set_name(), internal_parent(), internal_parse_panel(), internal_parse_xml_tag(), internal_prepare_filter_chapters(), internal_rcs_print(), internal_resolve_config_path(), internal_resolve_descriptor_path(), internal_resolve_one_leaf(), internal_resolve_pack_path(), internal_resolve_path_rel(), internal_resolve_scheme_rel(), internal_scan_tags(), internal_split_output(), internal_split_output(), internal_split_output(), internal_split_path(), internal_split_path(), internal_stage_name(), internal_stderr_write(), internal_str_copy_trimmed(), internal_tag_is(), internal_tar_header(), internal_terminator(), internal_text(), internal_text(), internal_text(), internal_text(), internal_text(), internal_text(), internal_trim_ws(), internal_url_slug(), internal_urlname_last_path_marker(), internal_urlname_path_end(), internal_urlname_path_start(), internal_validate_mode_fields(), internal_xml_unescape(), mdl_hash_str(), mdl_meta_parse(), mdl_path_contained(), mdl_path_join(), mdl_search_build_url(), mdl_urlname_chapter_parse(), mdl_xml_escape(), mkbookimg_dest_name(), priv_alphabet_soup_split_path(), priv_emu_io_err_text(), priv_emu_io_file_text(), priv_emu_io_out_text(), priv_match_grad(), priv_mdl_epub_add_str(), priv_mdl_epub_str_cat(), priv_mdl_state_relative_path_valid(), priv_mkbookimg_diag(), priv_mkfontimg_diag(), priv_ota_json_u32(), priv_ra8_svgp_attr(), priv_ra8_svgp_find_ci(), priv_ra8_svgp_starts_ci(), priv_reflow_tok_decode_entity(), priv_reflow_tok_find_lit(), priv_reflow_tok_skip_past(), priv_reflow_tok_starts_with(), priv_rv_diag(), ra8_rabook_intern(), rabook_import_open(), sh_center_x(), sh_comic_center_x(), sh_decode_entity(), sh_ext_match(), sh_fit(), sh_sd_listdir_cb(), sh_titlebar(), sh_xhtml_is_block(), sh_xhtml_is_suppress(), and xml_span_equal().

◆ strncmp()

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

Compare two strings up to a specified length.

Compares at most n characters of s1 and s2.

Parameters
[in]s1First string.
[in]s2Second string.
[in]nMaximum characters to compare.
Returns
Difference between first differing characters, or 0 if identical.
Return values
0Strings match for first n characters or up to null terminator.
<0First non-matching character in s1 is less than in s2.
>0First non-matching character in s1 is greater than in s2.
Precondition
s1 and s2 are readable up to n bytes or null-terminated.
Both pointers are addressable.
Postcondition
Both input strings are unmodified.
Bounded by n characters.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input strings are not concurrently modified.
Since
0.1.0

Definition at line 124 of file ra8_freestanding_str.c.

Referenced by epub_toc_entry_to_chapter(), internal_add_manifest_image(), internal_args_try_control(), internal_args_try_display(), internal_args_try_input(), internal_args_try_mode(), internal_args_try_sd(), internal_args_try_sym(), internal_config_valid(), internal_filter_prefix(), internal_init_site_identity(), internal_is_reserved_base(), internal_load_argv_traces(), internal_mdl_http_begin(), internal_mdl_start_request_valid(), internal_mdl_start_valid(), internal_output_path(), internal_panel_apply_kv(), internal_validate_mode_fields(), internal_xml_unescape(), mdl_extract_resolve_url(), mdl_extract_selector(), mdl_path_contained(), mdl_search_build_url(), priv_mdl_app_storage_publish_site(), priv_reflow_tok_decode_entity(), sh_decode_entity(), sh_xhtml_is_block(), and sh_xhtml_is_suppress().

◆ strncpy()

char * strncpy ( char * dst,
const char * src,
size_t n )

Copy bounded string to destination buffer.

Copies at most n characters from src to dst, padding with null bytes if src is shorter than n.

Parameters
[out]dstDestination buffer pointer.
[in]srcSource string pointer.
[in]nMaximum number of bytes to write.
Returns
Original destination pointer dst.
Return values
dstThe destination pointer passed in dst is always returned.
Precondition
dst points to at least n writable bytes.
dst and src do not overlap.
Postcondition
Exactly n bytes are written to dst.
Source string is unmodified.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when strings are not concurrently modified.
Since
0.1.0

Definition at line 288 of file ra8_freestanding_str.c.

Referenced by sh_copy_str(), sh_sd_listdir_cb(), and sh_seed_baked().

◆ strnlen()

size_t strnlen ( const char * s,
size_t maxlen )

Calculate bounded string length.

Computes length of string s up to a maximum of maxlen.

Parameters
[in]sCharacter string to measure.
[in]maxlenMaximum characters to examine.
Returns
Length of string up to maxlen.
Return values
lengthMin of characters before null terminator and maxlen.
Precondition
s points to readable memory of at least maxlen bytes or null-terminated.
s is addressable.
Postcondition
String content is unmodified.
Return value is at most maxlen.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input string is not concurrently modified.
Since
0.1.0

Definition at line 65 of file ra8_freestanding_str.c.

Referenced by internal_add_rule(), internal_cursor_entry(), internal_demo_roundtrip(), internal_library_leaf(), internal_library_remove_root(), internal_mdl_copy_field(), internal_mdl_http_field_copy(), internal_mdl_http_field_valid(), internal_mdl_request_field_valid(), internal_mdl_start_request_valid(), internal_mdl_start_valid(), internal_meta_candidate_path(), internal_urlname_copy(), mdl_robots_cache_consult(), mdl_urlname_chapter_parse(), mdl_urlname_chapter_text_parse(), priv_mdl_export_prepare_cover(), priv_mdl_export_validate_source_url(), and priv_mdl_state_field_valid().

◆ strrchr()

char * strrchr ( const char * s,
int c )

Locate last occurrence of character in string.

Scans s for the last instance of character c (including null).

Parameters
[in]sNull-terminated string to search.
[in]cCharacter value to locate.
Returns
Pointer to last occurrence in s, or nullptr if not found.
Return values
non-nullPointer to last matching character in s.
nullptrCharacter not found in s.
Precondition
s points to a valid null-terminated string.
s is readable.
Postcondition
String content is unmodified.
Returned pointer (if non-null) is within s.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input string is not concurrently modified.
Since
0.1.0

Definition at line 190 of file ra8_freestanding_str.c.

References memcpy().

Referenced by internal_body_paths(), internal_epub_media_type_from_suffix(), internal_mdl_fetch_try_reuse(), internal_parent(), internal_publish_page_image(), internal_resolve_one_leaf(), internal_split_path(), internal_split_path(), priv_alphabet_soup_split_path(), and priv_mdl_export_jof().

◆ strstr()

char * strstr ( const char * haystack,
const char * needle )

Locate substring in string.

Finds the first occurrence of needle in haystack.

Parameters
[in]haystackNull-terminated string to search.
[in]needleNull-terminated substring to locate.
Returns
Pointer to beginning of substring in haystack, or nullptr if not found.
Return values
non-nullPointer to substring occurrence in haystack.
nullptrSubstring not found in haystack.
Precondition
Both haystack and needle are valid null-terminated strings.
Both buffers are readable.
Postcondition
Both input strings are unmodified.
Returns haystack if needle is empty.
Note
Freestanding runtime primitive; never allocates; reentrant and thread-safe when input strings are not concurrently modified.
Since
0.1.0

Definition at line 222 of file ra8_freestanding_str.c.

References memcpy().

Referenced by internal_args_attach_blank_sd(), internal_authority_of(), internal_class_has_token(), internal_contains_ok(), internal_decode_fail(), internal_json_str(), internal_mve_exec_one(), internal_parse_xml_tag(), internal_resolve_scheme_rel(), internal_robots_target(), internal_run_stop_banner(), internal_sniff_content_type(), internal_urlname_path_start(), mdl_meta_parse(), mdl_search_filter_series_hits(), mdl_url_host(), mdl_url_path(), priv_epub_xml_attr_contains(), and priv_ota_json_u32().