alaurie / rpms / plymouth

Forked from rpms/plymouth 4 days ago
Clone

Blame SOURCES/0001-ply-utils-Reintroduce-ply_string_has_prefix-helper.patch

b9a929
From 58161da08c108243d59d58c6c1f9d3c97bb9a3ad Mon Sep 17 00:00:00 2001
b9a929
From: Hans de Goede <hdegoede@redhat.com>
b9a929
Date: Mon, 7 Mar 2022 12:25:56 +0100
b9a929
Subject: [PATCH 1/6] ply-utils: Reintroduce ply_string_has_prefix helper
b9a929
b9a929
ply_string_has_prefix was dropped in commit c7965ea19abf ("ply-utils:
b9a929
Drop unused ply_string_has_prefix helper"). We have a need for this
b9a929
helper again, so reintroduce it.
b9a929
b9a929
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
b9a929
---
b9a929
 src/libply/ply-utils.c | 9 +++++++++
b9a929
 src/libply/ply-utils.h | 1 +
b9a929
 2 files changed, 10 insertions(+)
b9a929
b9a929
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
b9a929
index f90ac40..f457579 100644
b9a929
--- a/src/libply/ply-utils.c
b9a929
+++ b/src/libply/ply-utils.c
b9a929
@@ -432,60 +432,69 @@ ply_copy_string_array (const char *const *array)
b9a929
         int i;
b9a929
 
b9a929
         for (i = 0; array[i] != NULL; i++) {
b9a929
         }
b9a929
 
b9a929
         copy = calloc (i + 1, sizeof(char *));
b9a929
 
b9a929
         for (i = 0; array[i] != NULL; i++) {
b9a929
                 copy[i] = strdup (array[i]);
b9a929
         }
b9a929
 
b9a929
         return copy;
b9a929
 }
b9a929
 
b9a929
 void
b9a929
 ply_free_string_array (char **array)
b9a929
 {
b9a929
         int i;
b9a929
 
b9a929
         if (array == NULL)
b9a929
                 return;
b9a929
 
b9a929
         for (i = 0; array[i] != NULL; i++) {
b9a929
                 free (array[i]);
b9a929
                 array[i] = NULL;
b9a929
         }
b9a929
 
b9a929
         free (array);
b9a929
 }
b9a929
 
b9a929
+bool
b9a929
+ply_string_has_prefix (const char *str, const char *prefix)
b9a929
+{
b9a929
+        if (str == NULL || prefix == NULL)
b9a929
+                return false;
b9a929
+
b9a929
+        return strncmp (str, prefix, strlen (prefix)) == 0;
b9a929
+}
b9a929
+
b9a929
 double
b9a929
 ply_get_timestamp (void)
b9a929
 {
b9a929
         const double nanoseconds_per_second = 1000000000.0;
b9a929
         double timestamp;
b9a929
         struct timespec now = { 0L, /* zero-filled */ };
b9a929
 
b9a929
         clock_gettime (CLOCK_MONOTONIC, &now;;
b9a929
         timestamp = ((nanoseconds_per_second * now.tv_sec) + now.tv_nsec) /
b9a929
                     nanoseconds_per_second;
b9a929
 
b9a929
         return timestamp;
b9a929
 }
b9a929
 
b9a929
 void
b9a929
 ply_save_errno (void)
b9a929
 {
b9a929
         assert (errno_stack_position < PLY_ERRNO_STACK_SIZE);
b9a929
         errno_stack[errno_stack_position] = errno;
b9a929
         errno_stack_position++;
b9a929
 }
b9a929
 
b9a929
 void
b9a929
 ply_restore_errno (void)
b9a929
 {
b9a929
         assert (errno_stack_position > 0);
b9a929
         errno_stack_position--;
b9a929
         errno = errno_stack[errno_stack_position];
b9a929
 }
b9a929
 
b9a929
diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h
b9a929
index d7b7622..b4565c3 100644
b9a929
--- a/src/libply/ply-utils.h
b9a929
+++ b/src/libply/ply-utils.h
b9a929
@@ -56,60 +56,61 @@ typedef enum
b9a929
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
b9a929
 
b9a929
 #define ply_round_to_multiple(n, m) (((n) + (((m) - 1))) & ~((m) - 1))
b9a929
 
b9a929
 bool ply_open_unidirectional_pipe (int *sender_fd,
b9a929
                                    int *receiver_fd);
b9a929
 int ply_connect_to_unix_socket (const char            *path,
b9a929
                                 ply_unix_socket_type_t type);
b9a929
 int ply_listen_to_unix_socket (const char            *path,
b9a929
                                ply_unix_socket_type_t type);
b9a929
 bool ply_get_credentials_from_fd (int    fd,
b9a929
                                   pid_t *pid,
b9a929
                                   uid_t *uid,
b9a929
                                   gid_t *gid);
b9a929
 
b9a929
 bool ply_write (int         fd,
b9a929
                 const void *buffer,
b9a929
                 size_t      number_of_bytes);
b9a929
 bool ply_write_uint32 (int      fd,
b9a929
                        uint32_t value);
b9a929
 bool ply_read (int    fd,
b9a929
                void  *buffer,
b9a929
                size_t number_of_bytes);
b9a929
 bool ply_read_uint32 (int       fd,
b9a929
                       uint32_t *value);
b9a929
 
b9a929
 bool ply_fd_has_data (int fd);
b9a929
 bool ply_set_fd_as_blocking (int fd);
b9a929
 char **ply_copy_string_array (const char *const *array);
b9a929
 void ply_free_string_array (char **array);
b9a929
+bool ply_string_has_prefix (const char *str, const char *prefix);
b9a929
 double ply_get_timestamp (void);
b9a929
 
b9a929
 void ply_save_errno (void);
b9a929
 void ply_restore_errno (void);
b9a929
 
b9a929
 bool ply_directory_exists (const char *dir);
b9a929
 bool ply_file_exists (const char *file);
b9a929
 bool ply_character_device_exists (const char *device);
b9a929
 
b9a929
 ply_module_handle_t *ply_open_module (const char *module_path);
b9a929
 ply_module_handle_t *ply_open_built_in_module (void);
b9a929
 
b9a929
 ply_module_function_t ply_module_look_up_function (ply_module_handle_t *handle,
b9a929
                                                    const char          *function_name);
b9a929
 void ply_close_module (ply_module_handle_t *handle);
b9a929
 
b9a929
 bool ply_create_directory (const char *directory);
b9a929
 bool ply_create_file_link (const char *source,
b9a929
                            const char *destination);
b9a929
 void ply_show_new_kernel_messages (bool should_show);
b9a929
 
b9a929
 ply_daemon_handle_t *ply_create_daemon (void);
b9a929
 bool ply_detach_daemon (ply_daemon_handle_t *handle,
b9a929
                         int                  exit_code);
b9a929
 
b9a929
 int ply_utf8_character_get_size (const char *string,
b9a929
                                  size_t      n);
b9a929
 int ply_utf8_string_get_length (const char *string,
b9a929
                                 size_t      n);
b9a929
 
b9a929
-- 
b9a929
2.37.0.rc1
b9a929