mirror of
https://github.com/ipxe/ipxe
synced 2026-05-08 15:02:55 +03:00
[uuid] Add uuid_aton() to parse a UUID from a string
Add uuid_aton() to parse a UUID value from a string (analogous to inet_aton(), inet6_aton(), sock_aton(), etc), treating it as a 32-digit hex string with optional hyphen separators. The placement of the separators is not checked: each byte within the hex string may be separated by a hyphen, or not separated at all. Add dedicated self-tests for UUID parsing and formatting (already partially covered by the ":uuid" and ":guid" settings self-tests). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
+13
-2
@@ -78,12 +78,23 @@ int hex_decode ( char separator, const char *encoded, void *data, size_t len ) {
|
||||
unsigned int count = 0;
|
||||
unsigned int sixteens;
|
||||
unsigned int units;
|
||||
int optional;
|
||||
|
||||
/* Strip out optionality flag from separator character */
|
||||
optional = ( separator & HEX_DECODE_OPTIONAL );
|
||||
separator &= ~HEX_DECODE_OPTIONAL;
|
||||
|
||||
/* Decode string */
|
||||
while ( *encoded ) {
|
||||
|
||||
/* Check separator, if applicable */
|
||||
if ( count && separator && ( ( *(encoded++) != separator ) ) )
|
||||
return -EINVAL;
|
||||
if ( count && separator ) {
|
||||
if ( *encoded == separator ) {
|
||||
encoded++;
|
||||
} else if ( ! optional ) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract digits. Note that either digit may be NUL,
|
||||
* which would be interpreted as an invalid value by
|
||||
|
||||
Reference in New Issue
Block a user