]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-utils: Add ply_string_has_suffix () helper function
authorHans de Goede <hdegoede@redhat.com>
Tue, 4 Jun 2024 19:09:00 +0000 (21:09 +0200)
committerHans de Goede <hdegoede@redhat.com>
Fri, 7 Jun 2024 15:21:00 +0000 (17:21 +0200)
Add a ply_string_has_suffix () helper function to match the existing
ply_string_has_prefix () helper function.

src/libply/ply-utils.c
src/libply/ply-utils.h

index 0e317b6783d626058ad9722e732b6291f5df030a..d6d127f1be11fb7ea39340d72dfa8878f81b7d7f 100644 (file)
@@ -473,6 +473,24 @@ ply_string_has_prefix (const char *str,
         return strncmp (str, prefix, strlen (prefix)) == 0;
 }
 
+bool
+ply_string_has_suffix (const char *str,
+                       const char *suffix)
+{
+        size_t str_len, suffix_len;
+
+        if (str == NULL || suffix == NULL)
+                return false;
+
+        str_len = strlen (str);
+        suffix_len = strlen (suffix);
+
+        if (suffix_len > str_len)
+                return false;
+
+        return strcmp (str + (str_len - suffix_len), suffix) == 0;
+}
+
 double
 ply_get_timestamp (void)
 {
index 7cbbb2f4d34139dca3453d371a4607af4f3c9f07..86d66384bc01e4474343f1ee51fb08a89f7bd710 100644 (file)
@@ -109,6 +109,8 @@ char **ply_copy_string_array (const char *const *array);
 void ply_free_string_array (char **array);
 bool ply_string_has_prefix (const char *str,
                             const char *prefix);
+bool ply_string_has_suffix (const char *str,
+                            const char *suffix);
 double ply_get_timestamp (void);
 
 void ply_save_errno (void);