]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-utils: Add ply_kernel_command_line_get_key_value helper
authorHans de Goede <hdegoede@redhat.com>
Sat, 28 Sep 2019 19:10:28 +0000 (21:10 +0200)
committerHans de Goede <hdegoede@redhat.com>
Mon, 30 Sep 2019 09:15:31 +0000 (11:15 +0200)
ply_kernel_command_line_get_string_after_prefix returns the rest of
the commandline after the passed in prefix. When parsing key=value parts
of the commandline, we really only want the value part and stop at the
whitespace separating it from other kernel commandline arguments.

This commit adds a new helper which returns a strdup-ed string containing
just the value; instead of the entire rest of the kernel commandline.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
src/libply/ply-utils.c
src/libply/ply-utils.h

index cf7570638e7ac05a73eb9e08979449b997d947ac..22b1db1518dccfe064f33bbde1a1ab4565be891b 100644 (file)
@@ -995,6 +995,18 @@ ply_kernel_command_line_has_argument (const char *argument)
         return true;
 }
 
+char *
+ply_kernel_command_line_get_key_value (const char *key)
+{
+        const char *value;
+
+        value = ply_kernel_command_line_get_string_after_prefix (key);
+        if (value == NULL || value[0] == '\0')
+                return NULL;
+
+        return strndup(value, strcspn (value, " \n"));
+}
+
 void
 ply_kernel_command_line_override (const char *command_line)
 {
index 7e8f5bf3a4fbcc0904a61137472dea0305924bfc..a936f7a20d45a1cfb912beba7bea03b34871ad54 100644 (file)
@@ -128,6 +128,7 @@ int ply_get_device_scale (uint32_t width,
 const char *ply_kernel_command_line_get_string_after_prefix (const char *prefix);
 bool ply_kernel_command_line_has_argument (const char *argument);
 void ply_kernel_command_line_override (const char *command_line);
+char *ply_kernel_command_line_get_key_value (const char *key);
 
 double ply_strtod(const char *str);