summaryrefslogtreecommitdiff
path: root/src/uuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uuid.c')
-rw-r--r--src/uuid.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/uuid.c b/src/uuid.c
index 29105fac71..6e1dbd7871 100644
--- a/src/uuid.c
+++ b/src/uuid.c
@@ -77,11 +77,22 @@ virUUIDGeneratePseudoRandomBytes(unsigned char *buf,
return 0;
}
+/**
+ * virUUIDGenerate:
+ * @uuid: array of VIR_UUID_RAW_LEN bytes to store the new UUID
+ *
+ * Generates a randomized unique identifier.
+ *
+ * Returns 0 in case of success and -1 in case of failure
+ */
int
virUUIDGenerate(unsigned char *uuid)
{
int err;
+ if (uuid == NULL)
+ return(-1);
+
if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_RAW_LEN)))
qemudLog(QEMUD_WARN,
"Falling back to pseudorandom UUID, "
@@ -90,11 +101,24 @@ virUUIDGenerate(unsigned char *uuid)
return virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_RAW_LEN);
}
+/**
+ * virUUIDParse:
+ * @uuid: zero terminated string representation of the UUID
+ * @rawuuid: array of VIR_UUID_RAW_LEN bytes to store the raw UUID
+ *
+ * Parses the external string representation, allowing spaces and '-'
+ * character in the sequence, and storing the result as a raw UUID
+ *
+ * Returns 0 in case of success and -1 in case of error.
+ */
int
virUUIDParse(const char *uuid, unsigned char *rawuuid) {
const char *cur;
int i;
+ if ((uuid == NULL) || (rawuuid == NULL))
+ return(-1);
+
/*
* do a liberal scan allowing '-' and ' ' anywhere between character
* pairs as long as there is 32 of them in the end.