diff options
author | pommicket <pommicket@gmail.com> | 2023-03-04 18:48:22 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-03-04 18:48:22 -0500 |
commit | 8a13f9fa37b5401c836e0ce8674cee5255512d5e (patch) | |
tree | fce7438f610e0c1c44b35763b756e62c3b5f2dc9 /util.c | |
parent | a8ecd337a1714653710d69a9fcaea8b354ffded8 (diff) |
new light style
also highlighting of POSIX types
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -123,7 +123,19 @@ const char32_t *util_mem32chr_const(const char32_t *s, char32_t c, size_t n) { } bool str_has_prefix(const char *str, const char *prefix) { - return strncmp(str, prefix, strlen(prefix)) == 0; + size_t prefix_len = strlen(prefix); + size_t str_len = strlen(str); + if (str_len < prefix_len) + return false; + return memcmp(str, prefix, prefix_len) == 0; +} + +bool str_has_suffix(const char *str, const char *suffix) { + size_t suffix_len = strlen(suffix); + size_t str_len = strlen(str); + if (str_len < suffix_len) + return false; + return memcmp(str + str_len - suffix_len, suffix, suffix_len) == 0; } bool str_has_path_prefix(const char *path, const char *prefix) { |