From e4a509b8174c8b2cfc0a084b78c9c7b7d08b624b Mon Sep 17 00:00:00 2001 From: mdw Date: Tue, 20 Sep 2005 13:30:18 +0000 Subject: [PATCH] Export better list of errors. --- key-error.c | 23 +++++------------------ key-error.h | 39 ++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/key-error.c b/key-error.c index b114798..b4f8ffe 100644 --- a/key-error.c +++ b/key-error.c @@ -46,29 +46,16 @@ const char *key_strerror(int err) { - char *tab[] = { - "No error", - "Bad tag string", - "Bad type string", - "Bad comment string", - "Keyid already exists", - "Key tag already exists", - "Key file is read-only", - "Key will eventually expire", - "Key has expired", - "Bad key flags string", - "Failed to unlock encrypted key", - "Unexpected key encoding type", - "Key not found", - "Bad attribute name", - "Malformed key data", - "I/O errror", + static const char *const tab[] = { +#define ENTRY(tag, num, str) str, + KEY_ERRORS(ENTRY) +#undef ENTRY "Unknown error code" }; unsigned e = -err; if (e >= N(tab)) - e = N(tab); + e = N(tab) - 1; return (tab[e]); } diff --git a/key-error.h b/key-error.h index 94b53c2..0323c2f 100644 --- a/key-error.h +++ b/key-error.h @@ -36,24 +36,29 @@ /*----- Error codes -------------------------------------------------------*/ +#define KEY_ERRORS(_) \ + _(OK, 0, "No error") \ + _(BADTAG, -1, "Bad tag string") \ + _(BADTYPE, -2, "Bad type string") \ + _(BADCOMMENT, -3, "Bad comment string") \ + _(DUPID, -4, "Key id already exists") \ + _(DUPTAG, -5, "Key tag already exists") \ + _(READONLY, -6, "Key file is read-only") \ + _(WILLEXPIRE, -7, "Key will eventually expire") \ + _(EXPIRED, -8, "Key has expired") \ + _(BADFLAGS, -9, "Bad key flags string") \ + _(BADPASS, -10, "Failed to unlock key") \ + _(WRONGTYPE, -11, "Unexpected key encoding type") \ + _(NOTFOUND, -12, "Key not found") \ + _(BADATTR, -13, "Bad attribute name") \ + _(MALFORMED, -14, "Malformed key data") \ + _(IO, -15, "I/O error") \ + enum { - KERR_OK = 0, /* No error */ - KERR_BADTAG = -1, /* Malformed tag string */ - KERR_BADTYPE = -2, /* Malformed type string */ - KERR_BADCOMMENT = -3, /* Malformed comment string */ - KERR_DUPID = -4, /* Duplicate keyid */ - KERR_DUPTAG = -5, /* Duplicate key tag string */ - KERR_READONLY = -6, /* Key file is read-only */ - KERR_WILLEXPIRE = -7, /* Key will eventually expire */ - KERR_EXPIRED = -8, /* Key has already expired */ - KERR_BADFLAGS = -9, /* Error in flags string */ - KERR_BADPASS = -10, /* Error decrypting locked key */ - KERR_WRONGTYPE = -11, /* Key has incorrect type */ - KERR_NOTFOUND = -12, /* Key couldn't be found */ - KERR_BADATTR = -13, /* Malformed attribute name */ - KERR_MALFORMED = -14, /* Key data is malformed */ - KERR_IO = -15, /* I/O error of some kind */ - KERR_MAX = -16 /* Not useful */ +#define ENTRY(tag, num, str) KERR_##tag = num, + KEY_ERRORS(ENTRY) +#undef ENTRY + KERR__dummy }; /*----- Functions provided ------------------------------------------------*/ -- 2.11.0