]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[parseopt] Add parse_uuid() for parsing UUID command-line arguments
authorMichael Brown <mcb30@ipxe.org>
Thu, 29 Feb 2024 14:05:39 +0000 (14:05 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 29 Feb 2024 15:20:44 +0000 (15:20 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/parseopt.c
src/include/ipxe/parseopt.h

index cd3b3101ce5dec43399009c82faefc157429bed5..7aff14851c5cda14ad31260777dac0491181b3c8 100644 (file)
@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ctype.h>
 #include <errno.h>
 #include <getopt.h>
+#include <ipxe/uuid.h>
 #include <ipxe/netdevice.h>
 #include <ipxe/menu.h>
 #include <ipxe/settings.h>
@@ -124,6 +125,28 @@ int parse_timeout ( char *text, unsigned long *value ) {
        return 0;
 }
 
+/**
+ * Parse UUID
+ *
+ * @v text             Text
+ * @ret value          UUID value
+ * @ret rc             Return status code
+ */
+int parse_uuid ( char *text, union uuid *value ) {
+       int rc;
+
+       /* Sanity check */
+       assert ( text != NULL );
+
+       /* Parse UUID */
+       if ( ( rc = uuid_aton ( text, value ) ) != 0 ) {
+               printf ( "\"%s\": invalid UUID\n", text );
+               return rc;
+       }
+
+       return 0;
+}
+
 /**
  * Parse network device name
  *
index 829b3431caa850c74363444d2f61999b4efe74d9..ebd18804f6dc8320ec5c971e8556e279ce702b4c 100644 (file)
@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <stdint.h>
 #include <stddef.h>
+#include <ipxe/uuid.h>
 #include <ipxe/settings.h>
 
 struct net_device;
@@ -128,6 +129,7 @@ struct named_setting {
 extern int parse_string ( char *text, char **value );
 extern int parse_integer ( char *text, unsigned int *value );
 extern int parse_timeout ( char *text, unsigned long *value );
+extern int parse_uuid ( char *text, union uuid *value );
 extern int parse_netdev ( char *text, struct net_device **netdev );
 extern int
 parse_netdev_configurator ( char *text,