libhmap-c

C hashmap library
git clone https://git.sinitax.com/sinitax/libhmap-c
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

commit bd2e5f7bdd17d757a17301587206eb1cb3af3ad5
parent a21f5271c522c5938d96af8218d3f24ff85401d9
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 20 Mar 2023 15:05:24 +0100

Add strerror lut definition macro

Diffstat:
Minclude/hashmap.h | 5+++++
Msrc/test.c | 7++++++-
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/hashmap.h b/include/hashmap.h @@ -10,6 +10,11 @@ #define HASHMAP_ITER(map, iter) \ hashmap_iter_init(iter); hashmap_iter_next(map, iter); +#define HASHMAP_STRERR_INIT \ + [HMAP_OK] = "Success", \ + [HMAP_KEY_EXISTS] = "Key exists", \ + [HMAP_KEY_MISSING] = "Key missing" + typedef uint32_t (*hashmap_hash_func)(const void *data, size_t size); typedef bool (*hashmap_keycmp_func)(const void *key1, size_t size1, const void *key2, size_t size2); diff --git a/src/test.c b/src/test.c @@ -5,7 +5,12 @@ #include <string.h> #include <stdlib.h> -#define LIBHASHMAP_ERR(rc) errx(1, "libhashmap: %s", rc < 0 ? strerror(-rc) : "???") +#define LIBHASHMAP_ERR(rc) errx(1, "libhashmap: %s", \ + rc < 0 ? strerror(-rc) : hmap_err[rc]) + +static const char *hmap_err[] = { + HASHMAP_STRERR_INIT +}; int main(int argc, const char **argv)