summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-03-04 18:48:22 -0500
committerpommicket <pommicket@gmail.com>2023-03-04 18:48:22 -0500
commit8a13f9fa37b5401c836e0ce8674cee5255512d5e (patch)
treefce7438f610e0c1c44b35763b756e62c3b5f2dc9 /util.c
parenta8ecd337a1714653710d69a9fcaea8b354ffded8 (diff)
new light style
also highlighting of POSIX types
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/util.c b/util.c
index f7cbfbc..38d201a 100644
--- a/util.c
+++ b/util.c
@@ -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) {