add got_error_uuid()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
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);
+ }
+}