Commit 095892882c4ccc2f584998552200561f340e060f

Stefan Sperling 2019-03-10T15:45:07

add got_error_uuid()

diff --git a/include/got_error.h b/include/got_error.h
index ca9b003..106fa01 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -74,6 +74,9 @@
 #define GOT_ERR_TREE_DUP_ENTRY	58
 #define GOT_ERR_DIR_DUP_ENTRY	59
 #define GOT_ERR_NOT_WORKTREE	60
+#define GOT_ERR_UUID_VERSION	61
+#define GOT_ERR_UUID_INVALID	62
+#define GOT_ERR_UUID		63
 
 static const struct got_error {
 	int code;
@@ -138,6 +141,9 @@ static const struct got_error {
 	{ GOT_ERR_TREE_DUP_ENTRY,"duplicate entry in tree object" },
 	{ GOT_ERR_DIR_DUP_ENTRY,"duplicate entry in directory" },
 	{ GOT_ERR_NOT_WORKTREE, "no got work tree found" },
+	{ GOT_ERR_UUID_VERSION, "bad uuid version" },
+	{ GOT_ERR_UUID_INVALID, "uuid invalid" },
+	{ GOT_ERR_UUID,		"uuid error" },
 };
 
 /*
@@ -190,3 +196,6 @@ const struct got_error *got_error_no_obj(struct got_object_id *);
  * message set during earlier invocations.
  */
 const struct got_error *got_error_not_ref(const char *);
+
+/* Return an error based on a uuid(3) status code. */
+const struct got_error *got_error_uuid(uint32_t);
diff --git a/lib/error.c b/lib/error.c
index 72cf6ae..737359c 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <sha1.h>
 #include <zlib.h>
+#include <uuid.h>
 
 #include "got_error.h"
 #include "got_object.h"
@@ -120,3 +121,20 @@ got_error_not_ref(const char *refname)
 
 	return got_error_msg(GOT_ERR_NOT_REF, msg);
 }
+
+const struct got_error *
+got_error_uuid(uint32_t uuid_status)
+{
+	switch (uuid_status) {
+	case uuid_s_ok:
+		return NULL;
+	case uuid_s_bad_version:
+		return got_error(GOT_ERR_UUID_VERSION);
+	case uuid_s_invalid_string_uuid:
+		return got_error(GOT_ERR_UUID_INVALID);
+	case uuid_s_no_memory:
+		return got_error_set_errno(ENOMEM);
+	default:
+		return got_error(GOT_ERR_UUID);
+	}
+}