From 7cd73884e51f6d3649aa2ea0ed0cec0b39192f61 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 29 Feb 2024 14:05:39 +0000 Subject: [parseopt] Add parse_uuid() for parsing UUID command-line arguments Signed-off-by: Michael Brown --- src/core/parseopt.c | 23 +++++++++++++++++++++++ src/include/ipxe/parseopt.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/core/parseopt.c b/src/core/parseopt.c index cd3b3101..7aff1485 100644 --- a/src/core/parseopt.c +++ b/src/core/parseopt.c @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include #include #include #include @@ -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 * diff --git a/src/include/ipxe/parseopt.h b/src/include/ipxe/parseopt.h index 829b3431..ebd18804 100644 --- a/src/include/ipxe/parseopt.h +++ b/src/include/ipxe/parseopt.h @@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include +#include #include 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, -- cgit v1.2.3-55-g7522